0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef __CS_DSP_H
0012 #define __CS_DSP_H
0013
0014 #include <linux/bits.h>
0015 #include <linux/device.h>
0016 #include <linux/firmware.h>
0017 #include <linux/list.h>
0018 #include <linux/regmap.h>
0019
0020 #define CS_ADSP2_REGION_0 BIT(0)
0021 #define CS_ADSP2_REGION_1 BIT(1)
0022 #define CS_ADSP2_REGION_2 BIT(2)
0023 #define CS_ADSP2_REGION_3 BIT(3)
0024 #define CS_ADSP2_REGION_4 BIT(4)
0025 #define CS_ADSP2_REGION_5 BIT(5)
0026 #define CS_ADSP2_REGION_6 BIT(6)
0027 #define CS_ADSP2_REGION_7 BIT(7)
0028 #define CS_ADSP2_REGION_8 BIT(8)
0029 #define CS_ADSP2_REGION_9 BIT(9)
0030 #define CS_ADSP2_REGION_1_9 (CS_ADSP2_REGION_1 | \
0031 CS_ADSP2_REGION_2 | CS_ADSP2_REGION_3 | \
0032 CS_ADSP2_REGION_4 | CS_ADSP2_REGION_5 | \
0033 CS_ADSP2_REGION_6 | CS_ADSP2_REGION_7 | \
0034 CS_ADSP2_REGION_8 | CS_ADSP2_REGION_9)
0035 #define CS_ADSP2_REGION_ALL (CS_ADSP2_REGION_0 | CS_ADSP2_REGION_1_9)
0036
0037 #define CS_DSP_DATA_WORD_SIZE 3
0038 #define CS_DSP_DATA_WORD_BITS (3 * BITS_PER_BYTE)
0039
0040 #define CS_DSP_ACKED_CTL_TIMEOUT_MS 100
0041 #define CS_DSP_ACKED_CTL_N_QUICKPOLLS 10
0042 #define CS_DSP_ACKED_CTL_MIN_VALUE 0
0043 #define CS_DSP_ACKED_CTL_MAX_VALUE 0xFFFFFF
0044
0045
0046
0047
0048
0049
0050 struct cs_dsp_region {
0051 int type;
0052 unsigned int base;
0053 };
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063 struct cs_dsp_alg_region {
0064 struct list_head list;
0065 unsigned int alg;
0066 unsigned int ver;
0067 int type;
0068 unsigned int base;
0069 };
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088 struct cs_dsp_coeff_ctl {
0089 struct list_head list;
0090 struct cs_dsp *dsp;
0091 void *cache;
0092 const char *fw_name;
0093
0094 const char *subname;
0095 unsigned int subname_len;
0096 unsigned int offset;
0097 size_t len;
0098 unsigned int type;
0099 unsigned int flags;
0100 unsigned int set:1;
0101 unsigned int enabled:1;
0102 struct cs_dsp_alg_region alg_region;
0103
0104 void *priv;
0105 };
0106
0107 struct cs_dsp_ops;
0108 struct cs_dsp_client_ops;
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139
0140
0141
0142
0143 struct cs_dsp {
0144 const char *name;
0145 int rev;
0146 int num;
0147 int type;
0148 struct device *dev;
0149 struct regmap *regmap;
0150
0151 const struct cs_dsp_ops *ops;
0152 const struct cs_dsp_client_ops *client_ops;
0153
0154 unsigned int base;
0155 unsigned int base_sysinfo;
0156 unsigned int sysclk_reg;
0157 unsigned int sysclk_mask;
0158 unsigned int sysclk_shift;
0159
0160 struct list_head alg_regions;
0161
0162 const char *fw_name;
0163 unsigned int fw_id;
0164 unsigned int fw_id_version;
0165 unsigned int fw_vendor_id;
0166
0167 const struct cs_dsp_region *mem;
0168 int num_mems;
0169
0170 int fw_ver;
0171
0172 bool booted;
0173 bool running;
0174
0175 struct list_head ctl_list;
0176
0177 struct mutex pwr_lock;
0178
0179 unsigned int lock_regions;
0180
0181 #ifdef CONFIG_DEBUG_FS
0182 struct dentry *debugfs_root;
0183 char *wmfw_file_name;
0184 char *bin_file_name;
0185 #endif
0186 };
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201 struct cs_dsp_client_ops {
0202 int (*control_add)(struct cs_dsp_coeff_ctl *ctl);
0203 void (*control_remove)(struct cs_dsp_coeff_ctl *ctl);
0204 int (*pre_run)(struct cs_dsp *dsp);
0205 int (*post_run)(struct cs_dsp *dsp);
0206 void (*pre_stop)(struct cs_dsp *dsp);
0207 void (*post_stop)(struct cs_dsp *dsp);
0208 void (*watchdog_expired)(struct cs_dsp *dsp);
0209 };
0210
0211 int cs_dsp_adsp1_init(struct cs_dsp *dsp);
0212 int cs_dsp_adsp2_init(struct cs_dsp *dsp);
0213 int cs_dsp_halo_init(struct cs_dsp *dsp);
0214
0215 int cs_dsp_adsp1_power_up(struct cs_dsp *dsp,
0216 const struct firmware *wmfw_firmware, char *wmfw_filename,
0217 const struct firmware *coeff_firmware, char *coeff_filename,
0218 const char *fw_name);
0219 void cs_dsp_adsp1_power_down(struct cs_dsp *dsp);
0220 int cs_dsp_power_up(struct cs_dsp *dsp,
0221 const struct firmware *wmfw_firmware, char *wmfw_filename,
0222 const struct firmware *coeff_firmware, char *coeff_filename,
0223 const char *fw_name);
0224 void cs_dsp_power_down(struct cs_dsp *dsp);
0225 int cs_dsp_run(struct cs_dsp *dsp);
0226 void cs_dsp_stop(struct cs_dsp *dsp);
0227
0228 void cs_dsp_remove(struct cs_dsp *dsp);
0229
0230 int cs_dsp_set_dspclk(struct cs_dsp *dsp, unsigned int freq);
0231 void cs_dsp_adsp2_bus_error(struct cs_dsp *dsp);
0232 void cs_dsp_halo_bus_error(struct cs_dsp *dsp);
0233 void cs_dsp_halo_wdt_expire(struct cs_dsp *dsp);
0234
0235 void cs_dsp_init_debugfs(struct cs_dsp *dsp, struct dentry *debugfs_root);
0236 void cs_dsp_cleanup_debugfs(struct cs_dsp *dsp);
0237
0238 int cs_dsp_coeff_write_acked_control(struct cs_dsp_coeff_ctl *ctl, unsigned int event_id);
0239 int cs_dsp_coeff_write_ctrl(struct cs_dsp_coeff_ctl *ctl, unsigned int off,
0240 const void *buf, size_t len);
0241 int cs_dsp_coeff_read_ctrl(struct cs_dsp_coeff_ctl *ctl, unsigned int off,
0242 void *buf, size_t len);
0243 struct cs_dsp_coeff_ctl *cs_dsp_get_ctl(struct cs_dsp *dsp, const char *name, int type,
0244 unsigned int alg);
0245
0246 int cs_dsp_read_raw_data_block(struct cs_dsp *dsp, int mem_type, unsigned int mem_addr,
0247 unsigned int num_words, __be32 *data);
0248 int cs_dsp_read_data_word(struct cs_dsp *dsp, int mem_type, unsigned int mem_addr, u32 *data);
0249 int cs_dsp_write_data_word(struct cs_dsp *dsp, int mem_type, unsigned int mem_addr, u32 data);
0250 void cs_dsp_remove_padding(u32 *buf, int nwords);
0251
0252 struct cs_dsp_alg_region *cs_dsp_find_alg_region(struct cs_dsp *dsp,
0253 int type, unsigned int id);
0254
0255 const char *cs_dsp_mem_region_name(unsigned int type);
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265 struct cs_dsp_chunk {
0266 u8 *data;
0267 u8 *max;
0268 int bytes;
0269
0270 u32 cache;
0271 int cachebits;
0272 };
0273
0274
0275
0276
0277
0278
0279
0280
0281 static inline struct cs_dsp_chunk cs_dsp_chunk(void *data, int size)
0282 {
0283 struct cs_dsp_chunk ch = {
0284 .data = data,
0285 .max = data + size,
0286 };
0287
0288 return ch;
0289 }
0290
0291
0292
0293
0294
0295
0296
0297 static inline bool cs_dsp_chunk_end(struct cs_dsp_chunk *ch)
0298 {
0299 return ch->data == ch->max;
0300 }
0301
0302
0303
0304
0305
0306
0307
0308 static inline int cs_dsp_chunk_bytes(struct cs_dsp_chunk *ch)
0309 {
0310 return ch->bytes;
0311 }
0312
0313
0314
0315
0316
0317
0318
0319 static inline bool cs_dsp_chunk_valid_addr(struct cs_dsp_chunk *ch, void *addr)
0320 {
0321 return (u8 *)addr >= ch->data && (u8 *)addr < ch->max;
0322 }
0323
0324 int cs_dsp_chunk_write(struct cs_dsp_chunk *ch, int nbits, u32 val);
0325 int cs_dsp_chunk_flush(struct cs_dsp_chunk *ch);
0326 int cs_dsp_chunk_read(struct cs_dsp_chunk *ch, int nbits);
0327
0328 #endif