1*cb626376SJames Ogletree /* SPDX-License-Identifier: GPL-2.0 2*cb626376SJames Ogletree * 3*cb626376SJames Ogletree * CS40L50 Advanced Haptic Driver with waveform memory, 4*cb626376SJames Ogletree * integrated DSP, and closed-loop algorithms 5*cb626376SJames Ogletree * 6*cb626376SJames Ogletree * Copyright 2024 Cirrus Logic, Inc. 7*cb626376SJames Ogletree * 8*cb626376SJames Ogletree * Author: James Ogletree <james.ogletree@cirrus.com> 9*cb626376SJames Ogletree */ 10*cb626376SJames Ogletree 11*cb626376SJames Ogletree #ifndef __MFD_CS40L50_H__ 12*cb626376SJames Ogletree #define __MFD_CS40L50_H__ 13*cb626376SJames Ogletree 14*cb626376SJames Ogletree #include <linux/firmware/cirrus/cs_dsp.h> 15*cb626376SJames Ogletree #include <linux/gpio/consumer.h> 16*cb626376SJames Ogletree #include <linux/pm.h> 17*cb626376SJames Ogletree #include <linux/regmap.h> 18*cb626376SJames Ogletree 19*cb626376SJames Ogletree /* Power Supply Configuration */ 20*cb626376SJames Ogletree #define CS40L50_BLOCK_ENABLES2 0x201C 21*cb626376SJames Ogletree #define CS40L50_ERR_RLS 0x2034 22*cb626376SJames Ogletree #define CS40L50_BST_LPMODE_SEL 0x3810 23*cb626376SJames Ogletree #define CS40L50_DCM_LOW_POWER 0x1 24*cb626376SJames Ogletree #define CS40L50_OVERTEMP_WARN 0x4000010 25*cb626376SJames Ogletree 26*cb626376SJames Ogletree /* Interrupts */ 27*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_1 0xE010 28*cb626376SJames Ogletree #define CS40L50_IRQ1_BASE CS40L50_IRQ1_INT_1 29*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_2 0xE014 30*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_8 0xE02C 31*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_9 0xE030 32*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_10 0xE034 33*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_18 0xE054 34*cb626376SJames Ogletree #define CS40L50_IRQ1_MASK_1 0xE090 35*cb626376SJames Ogletree #define CS40L50_IRQ1_MASK_2 0xE094 36*cb626376SJames Ogletree #define CS40L50_IRQ1_MASK_20 0xE0DC 37*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_1_OFFSET (CS40L50_IRQ1_INT_1 - CS40L50_IRQ1_BASE) 38*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_2_OFFSET (CS40L50_IRQ1_INT_2 - CS40L50_IRQ1_BASE) 39*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_8_OFFSET (CS40L50_IRQ1_INT_8 - CS40L50_IRQ1_BASE) 40*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_9_OFFSET (CS40L50_IRQ1_INT_9 - CS40L50_IRQ1_BASE) 41*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_10_OFFSET (CS40L50_IRQ1_INT_10 - CS40L50_IRQ1_BASE) 42*cb626376SJames Ogletree #define CS40L50_IRQ1_INT_18_OFFSET (CS40L50_IRQ1_INT_18 - CS40L50_IRQ1_BASE) 43*cb626376SJames Ogletree #define CS40L50_IRQ_MASK_2_OVERRIDE 0xFFDF7FFF 44*cb626376SJames Ogletree #define CS40L50_IRQ_MASK_20_OVERRIDE 0x15C01000 45*cb626376SJames Ogletree #define CS40L50_AMP_SHORT_MASK BIT(31) 46*cb626376SJames Ogletree #define CS40L50_DSP_QUEUE_MASK BIT(21) 47*cb626376SJames Ogletree #define CS40L50_TEMP_ERR_MASK BIT(31) 48*cb626376SJames Ogletree #define CS40L50_BST_UVP_MASK BIT(6) 49*cb626376SJames Ogletree #define CS40L50_BST_SHORT_MASK BIT(7) 50*cb626376SJames Ogletree #define CS40L50_BST_ILIMIT_MASK BIT(18) 51*cb626376SJames Ogletree #define CS40L50_UVLO_VDDBATT_MASK BIT(16) 52*cb626376SJames Ogletree #define CS40L50_GLOBAL_ERROR_MASK BIT(15) 53*cb626376SJames Ogletree 54*cb626376SJames Ogletree enum cs40l50_irq_list { 55*cb626376SJames Ogletree CS40L50_DSP_QUEUE_IRQ, 56*cb626376SJames Ogletree CS40L50_GLOBAL_ERROR_IRQ, 57*cb626376SJames Ogletree CS40L50_UVLO_VDDBATT_IRQ, 58*cb626376SJames Ogletree CS40L50_BST_ILIMIT_IRQ, 59*cb626376SJames Ogletree CS40L50_BST_SHORT_IRQ, 60*cb626376SJames Ogletree CS40L50_BST_UVP_IRQ, 61*cb626376SJames Ogletree CS40L50_TEMP_ERR_IRQ, 62*cb626376SJames Ogletree CS40L50_AMP_SHORT_IRQ, 63*cb626376SJames Ogletree }; 64*cb626376SJames Ogletree 65*cb626376SJames Ogletree /* DSP */ 66*cb626376SJames Ogletree #define CS40L50_XMEM_PACKED_0 0x2000000 67*cb626376SJames Ogletree #define CS40L50_XMEM_UNPACKED24_0 0x2800000 68*cb626376SJames Ogletree #define CS40L50_SYS_INFO_ID 0x25E0000 69*cb626376SJames Ogletree #define CS40L50_DSP_QUEUE_WT 0x28042C8 70*cb626376SJames Ogletree #define CS40L50_DSP_QUEUE_RD 0x28042CC 71*cb626376SJames Ogletree #define CS40L50_NUM_WAVES 0x2805C18 72*cb626376SJames Ogletree #define CS40L50_CORE_BASE 0x2B80000 73*cb626376SJames Ogletree #define CS40L50_YMEM_PACKED_0 0x2C00000 74*cb626376SJames Ogletree #define CS40L50_YMEM_UNPACKED24_0 0x3400000 75*cb626376SJames Ogletree #define CS40L50_PMEM_0 0x3800000 76*cb626376SJames Ogletree #define CS40L50_DSP_POLL_US 1000 77*cb626376SJames Ogletree #define CS40L50_DSP_TIMEOUT_COUNT 100 78*cb626376SJames Ogletree #define CS40L50_RESET_PULSE_US 2200 79*cb626376SJames Ogletree #define CS40L50_CP_READY_US 3100 80*cb626376SJames Ogletree #define CS40L50_AUTOSUSPEND_MS 2000 81*cb626376SJames Ogletree #define CS40L50_PM_ALGO 0x9F206 82*cb626376SJames Ogletree #define CS40L50_GLOBAL_ERR_RLS_SET BIT(11) 83*cb626376SJames Ogletree #define CS40L50_GLOBAL_ERR_RLS_CLEAR 0 84*cb626376SJames Ogletree 85*cb626376SJames Ogletree enum cs40l50_wseqs { 86*cb626376SJames Ogletree CS40L50_PWR_ON, 87*cb626376SJames Ogletree CS40L50_STANDBY, 88*cb626376SJames Ogletree CS40L50_ACTIVE, 89*cb626376SJames Ogletree CS40L50_NUM_WSEQS, 90*cb626376SJames Ogletree }; 91*cb626376SJames Ogletree 92*cb626376SJames Ogletree /* DSP Queue */ 93*cb626376SJames Ogletree #define CS40L50_DSP_QUEUE_BASE 0x11004 94*cb626376SJames Ogletree #define CS40L50_DSP_QUEUE_END 0x1101C 95*cb626376SJames Ogletree #define CS40L50_DSP_QUEUE 0x11020 96*cb626376SJames Ogletree #define CS40L50_PREVENT_HIBER 0x2000003 97*cb626376SJames Ogletree #define CS40L50_ALLOW_HIBER 0x2000004 98*cb626376SJames Ogletree #define CS40L50_SHUTDOWN 0x2000005 99*cb626376SJames Ogletree #define CS40L50_SYSTEM_RESET 0x2000007 100*cb626376SJames Ogletree #define CS40L50_START_I2S 0x3000002 101*cb626376SJames Ogletree #define CS40L50_OWT_PUSH 0x3000008 102*cb626376SJames Ogletree #define CS40L50_STOP_PLAYBACK 0x5000000 103*cb626376SJames Ogletree #define CS40L50_OWT_DELETE 0xD000000 104*cb626376SJames Ogletree 105*cb626376SJames Ogletree /* Firmware files */ 106*cb626376SJames Ogletree #define CS40L50_FW "cs40l50.wmfw" 107*cb626376SJames Ogletree #define CS40L50_WT "cs40l50.bin" 108*cb626376SJames Ogletree 109*cb626376SJames Ogletree /* Device */ 110*cb626376SJames Ogletree #define CS40L50_DEVID 0x0 111*cb626376SJames Ogletree #define CS40L50_REVID 0x4 112*cb626376SJames Ogletree #define CS40L50_DEVID_A 0x40A50 113*cb626376SJames Ogletree #define CS40L50_REVID_B0 0xB0 114*cb626376SJames Ogletree 115*cb626376SJames Ogletree struct cs40l50 { 116*cb626376SJames Ogletree struct device *dev; 117*cb626376SJames Ogletree struct regmap *regmap; 118*cb626376SJames Ogletree struct mutex lock; 119*cb626376SJames Ogletree struct cs_dsp dsp; 120*cb626376SJames Ogletree struct gpio_desc *reset_gpio; 121*cb626376SJames Ogletree struct regmap_irq_chip_data *irq_data; 122*cb626376SJames Ogletree const struct firmware *fw; 123*cb626376SJames Ogletree const struct firmware *bin; 124*cb626376SJames Ogletree struct cs_dsp_wseq wseqs[CS40L50_NUM_WSEQS]; 125*cb626376SJames Ogletree int irq; 126*cb626376SJames Ogletree u32 devid; 127*cb626376SJames Ogletree u32 revid; 128*cb626376SJames Ogletree }; 129*cb626376SJames Ogletree 130*cb626376SJames Ogletree int cs40l50_dsp_write(struct device *dev, struct regmap *regmap, u32 val); 131*cb626376SJames Ogletree int cs40l50_probe(struct cs40l50 *cs40l50); 132*cb626376SJames Ogletree int cs40l50_remove(struct cs40l50 *cs40l50); 133*cb626376SJames Ogletree 134*cb626376SJames Ogletree extern const struct regmap_config cs40l50_regmap; 135*cb626376SJames Ogletree extern const struct dev_pm_ops cs40l50_pm_ops; 136*cb626376SJames Ogletree 137*cb626376SJames Ogletree #endif /* __MFD_CS40L50_H__ */ 138