34df0a4c54
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEZH8oZUiU471FcZm+ONu9yGCSaT4FAmTCEMUACgkQONu9yGCS aT52vhAAr5fuA8n3nANC/iWrnV+tR7PS9+ncqxloumGgIPnFijlCpB7DBoK7KAPw cs83aMisxfvWkSPuQebqY2xO2dUX03DiySCNta0W81Iw2ndASLnA/OXYn+ZOXMbW xKYA37d5EmQ+JWIhh3+Gnxjb3Tui6vVEJAgqkC+4FD/sB60VwuGNIKirkYT58402 NlYExg0Wcgye8Qc50JXH96Dy6opvX84qGnnmz3slfKk7Jykifqh3jm1bSIQrngWs mUb8cXOkQgMrAWz8IJ4FgHisA0X3B3SklaiEO0ClPWw4nwC9PtpnAxZRxIVf2LDC eXj0fsJcP6So2b2vDnmfn2V+1bM8jQFuyv6eqhxW6sz4uiQQuZ3GAqdw0UhhfUmL ExzlCWTzdy2ZP4oN440JvxnYDItCsK263G+6l+LH3owWEbwHYmUh2uZoiC31rIEk pzXpZYzpFpGweTGtKx0+mW90i8l0lyQojN4pJMUrHgjp7u+bQIY0BkFUTClMH59E TsArErG8YOUh3cb+JkiTuJfgpv/D1kW//p3t2uJEsZPUHjN9BDsn0rsMftLYZI1C IKXpi69yYjbSmYAz6gRzi7AmlxRxqM4BEdOOyqHMylyyK5K0EneXqpA1UMT+Fuel 5KXXVWjPu+C0I5x4MLnbBckJQHVsKY/sUE94ba4OFsTMbCJeNZ8= =Vm2g -----END PGP SIGNATURE----- Merge 5.4.251 into android11-5.4-lts Changes in 5.4.251 gfs2: Don't deref jdesc in evict x86/smp: Use dedicated cache-line for mwait_play_dead() video: imsttfb: check for ioremap() failures fbdev: imsttfb: Fix use after free bug in imsttfb_probe HID: wacom: Use ktime_t rather than int when dealing with timestamps drm/i915: Initialise outparam for error return from wait_for_register scripts/tags.sh: Resolve gtags empty index generation drm/amdgpu: Validate VM ioctl flags. bgmac: fix *initial* chip reset to support BCM5358 x86/resctrl: Use is_closid_match() in more places x86/resctrl: Only show tasks' pid in current pid namespace md/raid10: check slab-out-of-bounds in md_bitmap_get_counter md/raid10: fix overflow of md/safe_mode_delay md/raid10: fix wrong setting of max_corr_read_errors md/raid10: fix null-ptr-deref of mreplace in raid10_sync_request md/raid10: fix io loss while replacement replace rdev irqchip/jcore-aic: Kill use of irq_create_strict_mappings() irqchip/jcore-aic: Fix missing allocation of IRQ descriptors tracing/timer: Add missing hrtimer modes to decode_hrtimer_mode(). clocksource/drivers/cadence-ttc: Use ttc driver as platform driver clocksource/drivers/cadence-ttc: Fix memory leak in ttc_timer_probe PM: domains: fix integer overflow issues in genpd_parse_state() powercap: RAPL: Fix CONFIG_IOSF_MBI dependency ARM: 9303/1: kprobes: avoid missing-declaration warnings evm: Complete description of evm_inode_setattr() pstore/ram: Add check for kstrdup ima: Fix build warnings wifi: ath9k: fix AR9003 mac hardware hang check register offset calculation wifi: ath9k: avoid referencing uninit memory in ath9k_wmi_ctrl_rx samples/bpf: Fix buffer overflow in tcp_basertt spi: spi-geni-qcom: Correct CS_TOGGLE bit in SPI_TRANS_CFG wifi: mwifiex: Fix the size of a memory allocation in mwifiex_ret_802_11_scan() nfc: constify several pointers to u8, char and sk_buff nfc: llcp: fix possible use of uninitialized variable in nfc_llcp_send_connect() regulator: core: Fix more error checking for debugfs_create_dir() regulator: core: Streamline debugfs operations wifi: orinoco: Fix an error handling path in spectrum_cs_probe() wifi: orinoco: Fix an error handling path in orinoco_cs_probe() wifi: atmel: Fix an error handling path in atmel_probe() wl3501_cs: Fix a bunch of formatting issues related to function docs wl3501_cs: Remove unnecessary NULL check wl3501_cs: Fix misspelling and provide missing documentation net: create netdev->dev_addr assignment helpers wl3501_cs: use eth_hw_addr_set() wifi: wl3501_cs: Fix an error handling path in wl3501_probe() wifi: ray_cs: Utilize strnlen() in parse_addr() wifi: ray_cs: Drop useless status variable in parse_addr() wifi: ray_cs: Fix an error handling path in ray_probe() wifi: ath9k: don't allow to overwrite ENDPOINT0 attributes wifi: rsi: Do not set MMC_PM_KEEP_POWER in shutdown watchdog/perf: define dummy watchdog_update_hrtimer_threshold() on correct config watchdog/perf: more properly prevent false positives with turbo modes kexec: fix a memory leak in crash_shrink_memory() memstick r592: make memstick_debug_get_tpc_name() static wifi: ath9k: Fix possible stall on ath9k_txq_list_has_key() rtnetlink: extend RTEXT_FILTER_SKIP_STATS to IFLA_VF_INFO wifi: iwlwifi: pull from TXQs with softirqs disabled wifi: cfg80211: rewrite merging of inherited elements wifi: ath9k: convert msecs to jiffies where needed netlink: fix potential deadlock in netlink_set_err() netlink: do not hard code device address lenth in fdb dumps selftests: rtnetlink: remove netdevsim device after ipsec offload test gtp: Fix use-after-free in __gtp_encap_destroy(). nfc: llcp: simplify llcp_sock_connect() error paths net: nfc: Fix use-after-free caused by nfc_llcp_find_local lib/ts_bm: reset initial match offset for every block of text netfilter: conntrack: dccp: copy entire header to stack buffer, not just basic one netfilter: nf_conntrack_sip: fix the ct_sip_parse_numerical_param() return value. ipvlan: Fix return value of ipvlan_queue_xmit() netlink: Add __sock_i_ino() for __netlink_diag_dump(). radeon: avoid double free in ci_dpm_init() Input: drv260x - sleep between polling GO bit ARM: dts: BCM5301X: Drop "clock-names" from the SPI node Input: adxl34x - do not hardcode interrupt trigger type drm: sun4i_tcon: use devm_clk_get_enabled in `sun4i_tcon_init_clocks` RDMA/bnxt_re: Fix to remove an unnecessary log ARM: dts: gta04: Move model property out of pinctrl node arm64: dts: qcom: msm8916: correct camss unit address drm/panel: simple: fix active size for Ampire AM-480272H3TMQW-T01H ARM: ep93xx: fix missing-prototype warnings memory: brcmstb_dpfe: fix testing array offset after use ASoC: es8316: Increment max value for ALC Capture Target Volume control ASoC: es8316: Do not set rate constraints for unsupported MCLKs soc/fsl/qe: fix usb.c build errors IB/hfi1: Fix sdma.h tx->num_descs off-by-one errors arm64: dts: renesas: ulcb-kf: Remove flow control for SCIF1 fbdev: omapfb: lcd_mipid: Fix an error handling path in mipid_spi_probe() drm/amdkfd: Fix potential deallocation of previously deallocated memory. drm/radeon: fix possible division-by-zero errors clk: tegra: tegra124-emc: Fix potential memory leak ALSA: ac97: Fix possible NULL dereference in snd_ac97_mixer clk: cdce925: check return value of kasprintf() clk: keystone: sci-clk: check return value of kasprintf() ASoC: imx-audmix: check return value of devm_kasprintf() scsi: qedf: Fix NULL dereference in error handling PCI/ASPM: Disable ASPM on MFD function removal to avoid use-after-free scsi: 3w-xxxx: Add error handling for initialization failure in tw_probe() PCI: pciehp: Cancel bringup sequence if card is not present PCI: ftpci100: Release the clock resources PCI: Add pci_clear_master() stub for non-CONFIG_PCI pinctrl: cherryview: Return correct value if pin in push-pull mode perf dwarf-aux: Fix off-by-one in die_get_varname() pinctrl: at91-pio4: check return value of devm_kasprintf() powerpc/mm/dax: Fix the condition when checking if altmap vmemap can cross-boundary hwrng: virtio - add an internal buffer hwrng: virtio - don't wait on cleanup hwrng: virtio - don't waste entropy hwrng: virtio - always add a pending request hwrng: virtio - Fix race on data_avail and actual data crypto: nx - fix build warnings when DEBUG_FS is not enabled modpost: fix section mismatch message for R_ARM_ABS32 modpost: fix section mismatch message for R_ARM_{PC24,CALL,JUMP24} crypto: marvell/cesa - Fix type mismatch warning modpost: fix off by one in is_executable_section() ARC: define ASM_NL and __ALIGN(_STR) outside #ifdef __ASSEMBLY__ guard NFSv4.1: freeze the session table upon receiving NFS4ERR_BADSESSION hwrng: st - Fix W=1 unused variable warning hwrng: st - keep clock enabled while hwrng is registered USB: serial: option: add LARA-R6 01B PIDs usb: dwc3: gadget: Propagate core init errors to UDC during pullup block: fix signed int overflow in Amiga partition support block: change all __u32 annotations to __be32 in affs_hardblocks.h w1: fix loop in w1_fini() sh: j2: Use ioremap() to translate device tree address into kernel memory media: usb: Check az6007_read() return value media: videodev2.h: Fix struct v4l2_input tuner index comment media: usb: siano: Fix warning due to null work_func_t function pointer usb: dwc3: qcom: Fix potential memory leak extcon: Fix kernel doc of property fields to avoid warnings extcon: Fix kernel doc of property capability fields to avoid warnings usb: phy: phy-tahvo: fix memory leak in tahvo_usb_probe() usb: hide unused usbfs_notify_suspend/resume functions mfd: rt5033: Drop rt5033-battery sub-device KVM: s390: fix KVM_S390_GET_CMMA_BITS for GFNs in memslot holes usb: dwc3: qcom: Release the correct resources in dwc3_qcom_remove() mfd: intel-lpss: Add missing check for platform_get_resource serial: 8250_omap: Use force_suspend and resume for system suspend mfd: stmfx: Fix error path in stmfx_chip_init KVM: s390: vsie: fix the length of APCB bitmap mfd: stmpe: Only disable the regulators if they are enabled pwm: imx-tpm: force 'real_period' to be zero in suspend pwm: sysfs: Do not apply state to already disabled PWMs rtc: st-lpc: Release some resources in st_rtc_probe() in case of error sctp: fix potential deadlock on &net->sctp.addr_wq_lock Add MODULE_FIRMWARE() for FIRMWARE_TG357766. spi: bcm-qspi: return error if neither hif_mspi nor mspi is available mailbox: ti-msgmgr: Fill non-message tx data fields with 0x0 f2fs: fix error path handling in truncate_dnode() powerpc: allow PPC_EARLY_DEBUG_CPM only when SERIAL_CPM=y net: bridge: keep ports without IFF_UNICAST_FLT in BR_PROMISC mode tcp: annotate data races in __tcp_oow_rate_limited() xsk: Improve documentation for AF_XDP xsk: Honor SO_BINDTODEVICE on bind net/sched: act_pedit: Add size check for TCA_PEDIT_PARMS_EX net: dsa: tag_sja1105: fix MAC DA patching from meta frames sh: dma: Fix DMA channel offset calculation i2c: xiic: Defer xiic_wakeup() and __xiic_start_xfer() in xiic_process() i2c: xiic: Don't try to handle more interrupt events after error ALSA: jack: Fix mutex call in snd_jack_report() NFSD: add encoding of op_recall flag for write delegation mmc: core: disable TRIM on Kingston EMMC04G-M627 mmc: core: disable TRIM on Micron MTFC4GACAJCN-1M mmc: sdhci: fix DMA configure compatibility issue when 64bit DMA mode is used. bcache: Remove unnecessary NULL point check in node allocations integrity: Fix possible multiple allocation in integrity_inode_get() jffs2: reduce stack usage in jffs2_build_xattr_subsystem() fs: avoid empty option when generating legacy mount string ext4: Remove ext4 locking of moved directory Revert "f2fs: fix potential corruption when moving a directory" fs: Establish locking order for unrelated directories fs: Lock moved directories btrfs: fix race when deleting quota root from the dirty cow roots list ARM: orion5x: fix d2net gpio initialization fs: no need to check source fanotify: disallow mount/sb marks on kernel internal pseudo fs block: add overflow checks for Amiga partition support netfilter: nf_tables: fix nat hook table deletion netfilter: nftables: add helper function to set the base sequence number netfilter: add helper function to set up the nfnetlink header and use it netfilter: nf_tables: use net_generic infra for transaction data netfilter: nf_tables: add rescheduling points during loop detection walks netfilter: nf_tables: incorrect error path handling with NFT_MSG_NEWRULE netfilter: nf_tables: add NFT_TRANS_PREPARE_ERROR to deal with bound set/chain netfilter: nf_tables: reject unbound anonymous set before commit phase netfilter: nf_tables: unbind non-anonymous set if rule construction fails netfilter: nf_tables: fix scheduling-while-atomic splat netfilter: conntrack: Avoid nf_ct_helper_hash uses after free netfilter: nf_tables: prevent OOB access in nft_byteorder_eval tty: serial: fsl_lpuart: add earlycon for imx8ulp platform block/partition: fix signedness issue for Amiga partitions net: lan743x: Don't sleep in atomic context workqueue: clean up WORK_* constant types, clarify masking drm/panel: Initialise panel dev and funcs through drm_panel_init() drm/panel: Add and fill drm_panel type field drm/panel: simple: Add connector_type for innolux_at043tn24 igc: Remove delay during TX ring configuration igc: set TP bit in 'supported' and 'advertising' fields of ethtool_link_ksettings scsi: qla2xxx: Fix error code in qla2x00_start_sp() net: mvneta: fix txq_map in case of txq_number==1 net/sched: cls_fw: Fix improper refcount update leads to use-after-free ionic: improve irq numa locality ionic: clean irq affinity on queue deinit ionic: move irq request to qcq alloc ionic: ionic_intr_free parameter change ionic: remove WARN_ON to prevent panic_on_warn icmp6: Fix null-ptr-deref of ip6_null_entry->rt6i_idev in icmp6_dev(). udp6: fix udp6_ehashfn() typo ntb: idt: Fix error handling in idt_pci_driver_init() NTB: amd: Fix error handling in amd_ntb_pci_driver_init() ntb: intel: Fix error handling in intel_ntb_pci_driver_init() NTB: ntb_transport: fix possible memory leak while device_register() fails NTB: ntb_tool: Add check for devm_kcalloc ipv6/addrconf: fix a potential refcount underflow for idev platform/x86: wmi: Replace UUID redefinitions by their originals platform/x86: wmi: Fix indentation in some cases platform/x86: wmi: remove unnecessary argument platform/x86: wmi: use guid_t and guid_equal() platform/x86: wmi: move variables platform/x86: wmi: Break possible infinite loop when parsing GUID erofs: avoid infinite loop in z_erofs_do_read_page() when reading beyond EOF wifi: airo: avoid uninitialized warning in airo_get_rate() cls_flower: Add extack support for src and dst port range options net/sched: flower: Ensure both minimum and maximum ports are specified net/sched: make psched_mtu() RTNL-less safe pinctrl: amd: Fix mistake in handling clearing pins at startup pinctrl: amd: Detect internal GPIO0 debounce handling pinctrl: amd: Only use special debounce behavior for GPIO 0 tpm: tpm_vtpm_proxy: fix a race condition in /dev/vtpmx creation mtd: rawnand: meson: fix unaligned DMA buffers handling net: bcmgenet: Ensure MDIO unregistration has clocks enabled powerpc: Fail build if using recordmcount with binutils v2.37 misc: fastrpc: Create fastrpc scalar with correct buffer count SUNRPC: Fix UAF in svc_tcp_listen_data_ready() erofs: fix compact 4B support for 16k block size ext4: fix wrong unit use in ext4_mb_clear_bb ext4: only update i_reserved_data_blocks on successful block allocation jfs: jfs_dmap: Validate db_l2nbperpage while mounting PCI/PM: Avoid putting EloPOS E2/S2/H2 PCIe Ports in D3cold PCI: Add function 1 DMA alias quirk for Marvell 88SE9235 PCI: qcom: Disable write access to read only registers for IP v2.3.3 PCI: rockchip: Assert PCI Configuration Enable bit after probe PCI: rockchip: Write PCI Device ID to correct register PCI: rockchip: Add poll and timeout to wait for PHY PLLs to be locked PCI: rockchip: Fix legacy IRQ generation for RK3399 PCIe endpoint core PCI: rockchip: Use u32 variable to access 32-bit registers PCI: rockchip: Set address alignment for endpoint mode misc: pci_endpoint_test: Free IRQs before removing the device misc: pci_endpoint_test: Re-init completion for every test md/raid0: add discard support for the 'original' layout fs: dlm: return positive pid value for F_GETLK drm/atomic: Allow vblank-enabled + self-refresh "disable" drm/rockchip: vop: Leave vblank enabled in self-refresh serial: atmel: don't enable IRQs prematurely firmware: stratix10-svc: Fix a potential resource leak in svc_create_memory_pool() hwrng: imx-rngc - fix the timeout for init and self check ceph: don't let check_caps skip sending responses for revoke msgs meson saradc: fix clock divider mask length Revert "8250: add support for ASIX devices with a FIFO bug" tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() in case of error tty: serial: samsung_tty: Fix a memory leak in s3c24xx_serial_getclk() when iterating clk tracing/histograms: Add histograms to hist_vars if they have referenced variables ring-buffer: Fix deadloop issue on reading trace_pipe xtensa: ISS: fix call to split_if_spec tracing: Fix null pointer dereference in tracing_err_log_open() tracing/probes: Fix not to count error code to total length scsi: qla2xxx: Wait for io return on terminate rport scsi: qla2xxx: Fix potential NULL pointer dereference scsi: qla2xxx: Check valid rport returned by fc_bsg_to_rport() scsi: qla2xxx: Correct the index of array scsi: qla2xxx: Pointer may be dereferenced scsi: qla2xxx: Remove unused nvme_ls_waitq wait queue drm/atomic: Fix potential use-after-free in nonblocking commits perf probe: Add test for regression introduced by switch to die_get_decl_file() btrfs: fix warning when putting transaction with qgroups enabled after abort fuse: revalidate: don't invalidate if interrupted selftests: tc: set timeout to 15 minutes can: bcm: Fix UAF in bcm_proc_show() drm/client: Fix memory leak in drm_client_target_cloned drm/client: Fix memory leak in drm_client_modeset_probe ext4: correct inline offset when handling xattrs in inode body debugobjects: Recheck debug_objects_enabled before reporting nbd: Add the maximum limit of allocated index in nbd_dev_add md: fix data corruption for raid456 when reshape restart while grow up md/raid10: prevent soft lockup while flush writes posix-timers: Ensure timer ID search-loop limit is valid arm64: mm: fix VA-range sanity check sched/fair: Don't balance task to its current running CPU bpf: Address KCSAN report on bpf_lru_list devlink: report devlink_port_type_warn source device wifi: wext-core: Fix -Wstringop-overflow warning in ioctl_standard_iw_point() wifi: iwlwifi: mvm: avoid baid size integer overflow igb: Fix igb_down hung on surprise removal spi: bcm63xx: fix max prepend length fbdev: imxfb: warn about invalid left/right margin pinctrl: amd: Use amd_pinconf_set() for all config options net: ethernet: ti: cpsw_ale: Fix cpsw_ale_get_field()/cpsw_ale_set_field() iavf: Fix use-after-free in free_netdev net:ipv6: check return value of pskb_trim() Revert "tcp: avoid the lookup process failing to get sk in ehash table" fbdev: au1200fb: Fix missing IRQ check in au1200fb_drv_probe llc: Don't drop packet from non-root netns. netfilter: nf_tables: fix spurious set element insertion failure netfilter: nf_tables: can't schedule in nft_chain_validate tcp: annotate data-races around tp->tcp_tx_delay net: Replace the limit of TCP_LINGER2 with TCP_FIN_TIMEOUT_MAX tcp: annotate data-races around tp->linger2 tcp: annotate data-races around rskq_defer_accept tcp: annotate data-races around tp->notsent_lowat tcp: annotate data-races around fastopenq.max_qlen tracing/histograms: Return an error if we fail to add histogram to hist_vars list Linux 5.4.251 Change-Id: I0b8e1ac44b19c6c2c4f5f055395b3cbf6aecbbee Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
457 lines
12 KiB
C
457 lines
12 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright 2018-2019 NXP.
|
|
*
|
|
* Limitations:
|
|
* - The TPM counter and period counter are shared between
|
|
* multiple channels, so all channels should use same period
|
|
* settings.
|
|
* - Changes to polarity cannot be latched at the time of the
|
|
* next period start.
|
|
* - Changing period and duty cycle together isn't atomic,
|
|
* with the wrong timing it might happen that a period is
|
|
* produced with old duty cycle but new period settings.
|
|
*/
|
|
|
|
#include <linux/bitfield.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/clk.h>
|
|
#include <linux/err.h>
|
|
#include <linux/io.h>
|
|
#include <linux/log2.h>
|
|
#include <linux/module.h>
|
|
#include <linux/of.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/pwm.h>
|
|
#include <linux/slab.h>
|
|
|
|
#define PWM_IMX_TPM_PARAM 0x4
|
|
#define PWM_IMX_TPM_GLOBAL 0x8
|
|
#define PWM_IMX_TPM_SC 0x10
|
|
#define PWM_IMX_TPM_CNT 0x14
|
|
#define PWM_IMX_TPM_MOD 0x18
|
|
#define PWM_IMX_TPM_CnSC(n) (0x20 + (n) * 0x8)
|
|
#define PWM_IMX_TPM_CnV(n) (0x24 + (n) * 0x8)
|
|
|
|
#define PWM_IMX_TPM_PARAM_CHAN GENMASK(7, 0)
|
|
|
|
#define PWM_IMX_TPM_SC_PS GENMASK(2, 0)
|
|
#define PWM_IMX_TPM_SC_CMOD GENMASK(4, 3)
|
|
#define PWM_IMX_TPM_SC_CMOD_INC_EVERY_CLK FIELD_PREP(PWM_IMX_TPM_SC_CMOD, 1)
|
|
#define PWM_IMX_TPM_SC_CPWMS BIT(5)
|
|
|
|
#define PWM_IMX_TPM_CnSC_CHF BIT(7)
|
|
#define PWM_IMX_TPM_CnSC_MSB BIT(5)
|
|
#define PWM_IMX_TPM_CnSC_MSA BIT(4)
|
|
|
|
/*
|
|
* The reference manual describes this field as two separate bits. The
|
|
* semantic of the two bits isn't orthogonal though, so they are treated
|
|
* together as a 2-bit field here.
|
|
*/
|
|
#define PWM_IMX_TPM_CnSC_ELS GENMASK(3, 2)
|
|
#define PWM_IMX_TPM_CnSC_ELS_INVERSED FIELD_PREP(PWM_IMX_TPM_CnSC_ELS, 1)
|
|
#define PWM_IMX_TPM_CnSC_ELS_NORMAL FIELD_PREP(PWM_IMX_TPM_CnSC_ELS, 2)
|
|
|
|
|
|
#define PWM_IMX_TPM_MOD_WIDTH 16
|
|
#define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0)
|
|
|
|
struct imx_tpm_pwm_chip {
|
|
struct pwm_chip chip;
|
|
struct clk *clk;
|
|
void __iomem *base;
|
|
struct mutex lock;
|
|
u32 user_count;
|
|
u32 enable_count;
|
|
u32 real_period;
|
|
};
|
|
|
|
struct imx_tpm_pwm_param {
|
|
u8 prescale;
|
|
u32 mod;
|
|
u32 val;
|
|
};
|
|
|
|
static inline struct imx_tpm_pwm_chip *
|
|
to_imx_tpm_pwm_chip(struct pwm_chip *chip)
|
|
{
|
|
return container_of(chip, struct imx_tpm_pwm_chip, chip);
|
|
}
|
|
|
|
/*
|
|
* This function determines for a given pwm_state *state that a consumer
|
|
* might request the pwm_state *real_state that eventually is implemented
|
|
* by the hardware and the necessary register values (in *p) to achieve
|
|
* this.
|
|
*/
|
|
static int pwm_imx_tpm_round_state(struct pwm_chip *chip,
|
|
struct imx_tpm_pwm_param *p,
|
|
struct pwm_state *real_state,
|
|
const struct pwm_state *state)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
|
|
u32 rate, prescale, period_count, clock_unit;
|
|
u64 tmp;
|
|
|
|
rate = clk_get_rate(tpm->clk);
|
|
tmp = (u64)state->period * rate;
|
|
clock_unit = DIV_ROUND_CLOSEST_ULL(tmp, NSEC_PER_SEC);
|
|
if (clock_unit <= PWM_IMX_TPM_MOD_MOD)
|
|
prescale = 0;
|
|
else
|
|
prescale = ilog2(clock_unit) + 1 - PWM_IMX_TPM_MOD_WIDTH;
|
|
|
|
if ((!FIELD_FIT(PWM_IMX_TPM_SC_PS, prescale)))
|
|
return -ERANGE;
|
|
p->prescale = prescale;
|
|
|
|
period_count = (clock_unit + ((1 << prescale) >> 1)) >> prescale;
|
|
p->mod = period_count;
|
|
|
|
/* calculate real period HW can support */
|
|
tmp = (u64)period_count << prescale;
|
|
tmp *= NSEC_PER_SEC;
|
|
real_state->period = DIV_ROUND_CLOSEST_ULL(tmp, rate);
|
|
|
|
/*
|
|
* if eventually the PWM output is inactive, either
|
|
* duty cycle is 0 or status is disabled, need to
|
|
* make sure the output pin is inactive.
|
|
*/
|
|
if (!state->enabled)
|
|
real_state->duty_cycle = 0;
|
|
else
|
|
real_state->duty_cycle = state->duty_cycle;
|
|
|
|
tmp = (u64)p->mod * real_state->duty_cycle;
|
|
p->val = DIV64_U64_ROUND_CLOSEST(tmp, real_state->period);
|
|
|
|
real_state->polarity = state->polarity;
|
|
real_state->enabled = state->enabled;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pwm_imx_tpm_get_state(struct pwm_chip *chip,
|
|
struct pwm_device *pwm,
|
|
struct pwm_state *state)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
|
|
u32 rate, val, prescale;
|
|
u64 tmp;
|
|
|
|
/* get period */
|
|
state->period = tpm->real_period;
|
|
|
|
/* get duty cycle */
|
|
rate = clk_get_rate(tpm->clk);
|
|
val = readl(tpm->base + PWM_IMX_TPM_SC);
|
|
prescale = FIELD_GET(PWM_IMX_TPM_SC_PS, val);
|
|
tmp = readl(tpm->base + PWM_IMX_TPM_CnV(pwm->hwpwm));
|
|
tmp = (tmp << prescale) * NSEC_PER_SEC;
|
|
state->duty_cycle = DIV_ROUND_CLOSEST_ULL(tmp, rate);
|
|
|
|
/* get polarity */
|
|
val = readl(tpm->base + PWM_IMX_TPM_CnSC(pwm->hwpwm));
|
|
if ((val & PWM_IMX_TPM_CnSC_ELS) == PWM_IMX_TPM_CnSC_ELS_INVERSED)
|
|
state->polarity = PWM_POLARITY_INVERSED;
|
|
else
|
|
/*
|
|
* Assume reserved values (2b00 and 2b11) to yield
|
|
* normal polarity.
|
|
*/
|
|
state->polarity = PWM_POLARITY_NORMAL;
|
|
|
|
/* get channel status */
|
|
state->enabled = FIELD_GET(PWM_IMX_TPM_CnSC_ELS, val) ? true : false;
|
|
}
|
|
|
|
/* this function is supposed to be called with mutex hold */
|
|
static int pwm_imx_tpm_apply_hw(struct pwm_chip *chip,
|
|
struct imx_tpm_pwm_param *p,
|
|
struct pwm_state *state,
|
|
struct pwm_device *pwm)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
|
|
bool period_update = false;
|
|
bool duty_update = false;
|
|
u32 val, cmod, cur_prescale;
|
|
unsigned long timeout;
|
|
struct pwm_state c;
|
|
|
|
if (state->period != tpm->real_period) {
|
|
/*
|
|
* TPM counter is shared by multiple channels, so
|
|
* prescale and period can NOT be modified when
|
|
* there are multiple channels in use with different
|
|
* period settings.
|
|
*/
|
|
if (tpm->user_count > 1)
|
|
return -EBUSY;
|
|
|
|
val = readl(tpm->base + PWM_IMX_TPM_SC);
|
|
cmod = FIELD_GET(PWM_IMX_TPM_SC_CMOD, val);
|
|
cur_prescale = FIELD_GET(PWM_IMX_TPM_SC_PS, val);
|
|
if (cmod && cur_prescale != p->prescale)
|
|
return -EBUSY;
|
|
|
|
/* set TPM counter prescale */
|
|
val &= ~PWM_IMX_TPM_SC_PS;
|
|
val |= FIELD_PREP(PWM_IMX_TPM_SC_PS, p->prescale);
|
|
writel(val, tpm->base + PWM_IMX_TPM_SC);
|
|
|
|
/*
|
|
* set period count:
|
|
* if the PWM is disabled (CMOD[1:0] = 2b00), then MOD register
|
|
* is updated when MOD register is written.
|
|
*
|
|
* if the PWM is enabled (CMOD[1:0] ≠ 2b00), the period length
|
|
* is latched into hardware when the next period starts.
|
|
*/
|
|
writel(p->mod, tpm->base + PWM_IMX_TPM_MOD);
|
|
tpm->real_period = state->period;
|
|
period_update = true;
|
|
}
|
|
|
|
pwm_imx_tpm_get_state(chip, pwm, &c);
|
|
|
|
/* polarity is NOT allowed to be changed if PWM is active */
|
|
if (c.enabled && c.polarity != state->polarity)
|
|
return -EBUSY;
|
|
|
|
if (state->duty_cycle != c.duty_cycle) {
|
|
/*
|
|
* set channel value:
|
|
* if the PWM is disabled (CMOD[1:0] = 2b00), then CnV register
|
|
* is updated when CnV register is written.
|
|
*
|
|
* if the PWM is enabled (CMOD[1:0] ≠ 2b00), the duty length
|
|
* is latched into hardware when the next period starts.
|
|
*/
|
|
writel(p->val, tpm->base + PWM_IMX_TPM_CnV(pwm->hwpwm));
|
|
duty_update = true;
|
|
}
|
|
|
|
/* make sure MOD & CnV registers are updated */
|
|
if (period_update || duty_update) {
|
|
timeout = jiffies + msecs_to_jiffies(tpm->real_period /
|
|
NSEC_PER_MSEC + 1);
|
|
while (readl(tpm->base + PWM_IMX_TPM_MOD) != p->mod
|
|
|| readl(tpm->base + PWM_IMX_TPM_CnV(pwm->hwpwm))
|
|
!= p->val) {
|
|
if (time_after(jiffies, timeout))
|
|
return -ETIME;
|
|
cpu_relax();
|
|
}
|
|
}
|
|
|
|
/*
|
|
* polarity settings will enabled/disable output status
|
|
* immediately, so if the channel is disabled, need to
|
|
* make sure MSA/MSB/ELS are set to 0 which means channel
|
|
* disabled.
|
|
*/
|
|
val = readl(tpm->base + PWM_IMX_TPM_CnSC(pwm->hwpwm));
|
|
val &= ~(PWM_IMX_TPM_CnSC_ELS | PWM_IMX_TPM_CnSC_MSA |
|
|
PWM_IMX_TPM_CnSC_MSB);
|
|
if (state->enabled) {
|
|
/*
|
|
* set polarity (for edge-aligned PWM modes)
|
|
*
|
|
* ELS[1:0] = 2b10 yields normal polarity behaviour,
|
|
* ELS[1:0] = 2b01 yields inversed polarity.
|
|
* The other values are reserved.
|
|
*/
|
|
val |= PWM_IMX_TPM_CnSC_MSB;
|
|
val |= (state->polarity == PWM_POLARITY_NORMAL) ?
|
|
PWM_IMX_TPM_CnSC_ELS_NORMAL :
|
|
PWM_IMX_TPM_CnSC_ELS_INVERSED;
|
|
}
|
|
writel(val, tpm->base + PWM_IMX_TPM_CnSC(pwm->hwpwm));
|
|
|
|
/* control the counter status */
|
|
if (state->enabled != c.enabled) {
|
|
val = readl(tpm->base + PWM_IMX_TPM_SC);
|
|
if (state->enabled) {
|
|
if (++tpm->enable_count == 1)
|
|
val |= PWM_IMX_TPM_SC_CMOD_INC_EVERY_CLK;
|
|
} else {
|
|
if (--tpm->enable_count == 0)
|
|
val &= ~PWM_IMX_TPM_SC_CMOD;
|
|
}
|
|
writel(val, tpm->base + PWM_IMX_TPM_SC);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int pwm_imx_tpm_apply(struct pwm_chip *chip,
|
|
struct pwm_device *pwm,
|
|
const struct pwm_state *state)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
|
|
struct imx_tpm_pwm_param param;
|
|
struct pwm_state real_state;
|
|
int ret;
|
|
|
|
ret = pwm_imx_tpm_round_state(chip, ¶m, &real_state, state);
|
|
if (ret)
|
|
return ret;
|
|
|
|
mutex_lock(&tpm->lock);
|
|
ret = pwm_imx_tpm_apply_hw(chip, ¶m, &real_state, pwm);
|
|
mutex_unlock(&tpm->lock);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int pwm_imx_tpm_request(struct pwm_chip *chip, struct pwm_device *pwm)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
|
|
|
|
mutex_lock(&tpm->lock);
|
|
tpm->user_count++;
|
|
mutex_unlock(&tpm->lock);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pwm_imx_tpm_free(struct pwm_chip *chip, struct pwm_device *pwm)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = to_imx_tpm_pwm_chip(chip);
|
|
|
|
mutex_lock(&tpm->lock);
|
|
tpm->user_count--;
|
|
mutex_unlock(&tpm->lock);
|
|
}
|
|
|
|
static const struct pwm_ops imx_tpm_pwm_ops = {
|
|
.request = pwm_imx_tpm_request,
|
|
.free = pwm_imx_tpm_free,
|
|
.get_state = pwm_imx_tpm_get_state,
|
|
.apply = pwm_imx_tpm_apply,
|
|
.owner = THIS_MODULE,
|
|
};
|
|
|
|
static int pwm_imx_tpm_probe(struct platform_device *pdev)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm;
|
|
int ret;
|
|
u32 val;
|
|
|
|
tpm = devm_kzalloc(&pdev->dev, sizeof(*tpm), GFP_KERNEL);
|
|
if (!tpm)
|
|
return -ENOMEM;
|
|
|
|
platform_set_drvdata(pdev, tpm);
|
|
|
|
tpm->base = devm_platform_ioremap_resource(pdev, 0);
|
|
if (IS_ERR(tpm->base))
|
|
return PTR_ERR(tpm->base);
|
|
|
|
tpm->clk = devm_clk_get(&pdev->dev, NULL);
|
|
if (IS_ERR(tpm->clk)) {
|
|
ret = PTR_ERR(tpm->clk);
|
|
if (ret != -EPROBE_DEFER)
|
|
dev_err(&pdev->dev,
|
|
"failed to get PWM clock: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
ret = clk_prepare_enable(tpm->clk);
|
|
if (ret) {
|
|
dev_err(&pdev->dev,
|
|
"failed to prepare or enable clock: %d\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
tpm->chip.dev = &pdev->dev;
|
|
tpm->chip.ops = &imx_tpm_pwm_ops;
|
|
tpm->chip.base = -1;
|
|
tpm->chip.of_xlate = of_pwm_xlate_with_flags;
|
|
tpm->chip.of_pwm_n_cells = 3;
|
|
|
|
/* get number of channels */
|
|
val = readl(tpm->base + PWM_IMX_TPM_PARAM);
|
|
tpm->chip.npwm = FIELD_GET(PWM_IMX_TPM_PARAM_CHAN, val);
|
|
|
|
mutex_init(&tpm->lock);
|
|
|
|
ret = pwmchip_add(&tpm->chip);
|
|
if (ret) {
|
|
dev_err(&pdev->dev, "failed to add PWM chip: %d\n", ret);
|
|
clk_disable_unprepare(tpm->clk);
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int pwm_imx_tpm_remove(struct platform_device *pdev)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = platform_get_drvdata(pdev);
|
|
int ret = pwmchip_remove(&tpm->chip);
|
|
|
|
clk_disable_unprepare(tpm->clk);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int __maybe_unused pwm_imx_tpm_suspend(struct device *dev)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = dev_get_drvdata(dev);
|
|
|
|
if (tpm->enable_count > 0)
|
|
return -EBUSY;
|
|
|
|
/*
|
|
* Force 'real_period' to be zero to force period update code
|
|
* can be executed after system resume back, since suspend causes
|
|
* the period related registers to become their reset values.
|
|
*/
|
|
tpm->real_period = 0;
|
|
|
|
clk_disable_unprepare(tpm->clk);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int __maybe_unused pwm_imx_tpm_resume(struct device *dev)
|
|
{
|
|
struct imx_tpm_pwm_chip *tpm = dev_get_drvdata(dev);
|
|
int ret = 0;
|
|
|
|
ret = clk_prepare_enable(tpm->clk);
|
|
if (ret)
|
|
dev_err(dev,
|
|
"failed to prepare or enable clock: %d\n",
|
|
ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static SIMPLE_DEV_PM_OPS(imx_tpm_pwm_pm,
|
|
pwm_imx_tpm_suspend, pwm_imx_tpm_resume);
|
|
|
|
static const struct of_device_id imx_tpm_pwm_dt_ids[] = {
|
|
{ .compatible = "fsl,imx7ulp-pwm", },
|
|
{ /* sentinel */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, imx_tpm_pwm_dt_ids);
|
|
|
|
static struct platform_driver imx_tpm_pwm_driver = {
|
|
.driver = {
|
|
.name = "imx7ulp-tpm-pwm",
|
|
.of_match_table = imx_tpm_pwm_dt_ids,
|
|
.pm = &imx_tpm_pwm_pm,
|
|
},
|
|
.probe = pwm_imx_tpm_probe,
|
|
.remove = pwm_imx_tpm_remove,
|
|
};
|
|
module_platform_driver(imx_tpm_pwm_driver);
|
|
|
|
MODULE_AUTHOR("Anson Huang <Anson.Huang@nxp.com>");
|
|
MODULE_DESCRIPTION("i.MX TPM PWM Driver");
|
|
MODULE_LICENSE("GPL v2");
|