3
This file is provided under a dual BSD/GPLv2 license. When using or
4
redistributing this file, you may do so under either license.
8
Copyright(c) 2010-2011 Texas Instruments Incorporated,
11
This program is free software; you can redistribute it and/or modify
12
it under the terms of version 2 of the GNU General Public License as
13
published by the Free Software Foundation.
15
This program is distributed in the hope that it will be useful, but
16
WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program; if not, write to the Free Software
22
Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
23
The full GNU General Public License is included in this distribution
24
in the file called LICENSE.GPL.
28
Copyright(c) 2010-2011 Texas Instruments Incorporated,
31
Redistribution and use in source and binary forms, with or without
32
modification, are permitted provided that the following conditions
35
* Redistributions of source code must retain the above copyright
36
notice, this list of conditions and the following disclaimer.
37
* Redistributions in binary form must reproduce the above copyright
38
notice, this list of conditions and the following disclaimer in
39
the documentation and/or other materials provided with the
41
* Neither the name of Texas Instruments Incorporated nor the names of
42
its contributors may be used to endorse or promote products derived
43
from this software without specific prior written permission.
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
46
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
47
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
48
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
49
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
50
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
51
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
55
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
59
#include <linux/kernel.h>
60
#include <linux/module.h>
62
#include <linux/module.h>
63
#include <linux/slab.h>
65
#include "abe_legacy.h"
76
/* parameters are the direct and recursive coefficients in */
77
/* Q6.26 integer fixed-point format. */
80
/* center frequency of the band [Hz] */
82
/* gain of each band. [dB] */
84
/* Q factor of this band [dB] */
96
int omap_abe_connect_debug_trace(struct omap_abe *abe,
97
struct omap_abe_dma *dma2);
99
int omap_abe_reset_hal(struct omap_abe *abe);
100
int omap_abe_load_fw(struct omap_abe *abe);
101
int omap_abe_wakeup(struct omap_abe *abe);
102
int omap_abe_irq_processing(struct omap_abe *abe);
103
int omap_abe_clear_irq(struct omap_abe *abe);
104
int omap_abe_disable_irq(struct omap_abe *abe);
105
int omap_abe_set_debug_trace(struct omap_abe_dbg *dbg, int debug);
106
int omap_abe_set_ping_pong_buffer(struct omap_abe *abe,
107
u32 port, u32 n_bytes);
108
int omap_abe_read_next_ping_pong_buffer(struct omap_abe *abe,
109
u32 port, u32 *p, u32 *n);
110
int omap_abe_init_ping_pong_buffer(struct omap_abe *abe,
111
u32 id, u32 size_bytes, u32 n_buffers,
113
int omap_abe_read_offset_from_ping_buffer(struct omap_abe *abe,
115
int omap_abe_set_router_configuration(struct omap_abe *abe,
116
u32 id, u32 k, u32 *param);
117
int omap_abe_set_opp_processing(struct omap_abe *abe, u32 opp);
118
int omap_abe_disable_data_transfer(struct omap_abe *abe, u32 id);
119
int omap_abe_enable_data_transfer(struct omap_abe *abe, u32 id);
120
int omap_abe_connect_cbpr_dmareq_port(struct omap_abe *abe,
121
u32 id, abe_data_format_t *f,
123
abe_dma_t *returned_dma_t);
124
int omap_abe_connect_irq_ping_pong_port(struct omap_abe *abe,
125
u32 id, abe_data_format_t *f,
126
u32 subroutine_id, u32 size,
127
u32 *sink, u32 dsp_mcu_flag);
128
int omap_abe_connect_serial_port(struct omap_abe *abe,
129
u32 id, abe_data_format_t *f,
131
int omap_abe_read_port_address(struct omap_abe *abe,
132
u32 port, abe_dma_t *dma2);
133
int omap_abe_check_activity(struct omap_abe *abe);
135
int omap_abe_use_compensated_gain(struct omap_abe *abe, int on_off);
136
int omap_abe_write_equalizer(struct omap_abe *abe,
137
u32 id, struct omap_abe_equ *param);
139
int omap_abe_disable_gain(struct omap_abe *abe, u32 id, u32 p);
140
int omap_abe_enable_gain(struct omap_abe *abe, u32 id, u32 p);
141
int omap_abe_mute_gain(struct omap_abe *abe, u32 id, u32 p);
142
int omap_abe_unmute_gain(struct omap_abe *abe, u32 id, u32 p);
144
int omap_abe_write_gain(struct omap_abe *abe,
145
u32 id, s32 f_g, u32 ramp, u32 p);
146
int omap_abe_write_mixer(struct omap_abe *abe,
147
u32 id, s32 f_g, u32 f_ramp, u32 p);
148
int omap_abe_read_gain(struct omap_abe *abe,
149
u32 id, u32 *f_g, u32 p);
150
int omap_abe_read_mixer(struct omap_abe *abe,
151
u32 id, u32 *f_g, u32 p);
153
extern struct omap_abe *abe;
157
* abe_init_mem - Allocate Kernel space memory map for ABE
159
* Memory map of ABE memory space for PMEM/DMEM/SMEM/DMEM
161
void abe_init_mem(void __iomem *_io_base)
163
omap_abe_init_mem(abe, _io_base);
165
EXPORT_SYMBOL(abe_init_mem);
167
struct omap_abe* abe_probe_aess(void)
169
return omap_abe_probe_aess(abe);
171
EXPORT_SYMBOL(abe_probe_aess);
173
void abe_remove_aess(void)
175
omap_abe_remove_aess(abe);
177
EXPORT_SYMBOL(abe_remove_aess);
179
void abe_add_subroutine(u32 *id, abe_subroutine2 f,
180
u32 nparam, u32 *params)
182
omap_abe_add_subroutine(abe, id, f, nparam, params);
184
EXPORT_SYMBOL(abe_add_subroutine);
189
* abe_reset_hal - reset the ABE/HAL
190
* @rdev: regulator source
191
* @constraints: constraints to apply
193
* Operations : reset the HAL by reloading the static variables and
194
* default AESS registers.
195
* Called after a PRCM cold-start reset of ABE
197
u32 abe_reset_hal(void)
199
omap_abe_reset_hal(abe);
202
EXPORT_SYMBOL(abe_reset_hal);
205
* abe_load_fw - Load ABE Firmware and initialize memories
208
u32 abe_load_fw(void)
210
omap_abe_load_fw(abe);
213
EXPORT_SYMBOL(abe_load_fw);
216
* abe_wakeup - Wakeup ABE
218
* Wakeup ABE in case of retention
222
omap_abe_wakeup(abe);
225
EXPORT_SYMBOL(abe_wakeup);
228
* abe_irq_processing - Process ABE interrupt
230
* This subroutine is call upon reception of "MA_IRQ_99 ABE_MPU_IRQ" Audio
231
* back-end interrupt. This subroutine will check the ATC Hrdware, the
232
* IRQ_FIFO from the AE and act accordingly. Some IRQ source are originated
233
* for the delivery of "end of time sequenced tasks" notifications, some are
234
* originated from the Ping-Pong protocols, some are generated from
235
* the embedded debugger when the firmware stops on programmable break-points,
238
u32 abe_irq_processing(void)
240
omap_abe_irq_processing(abe);
243
EXPORT_SYMBOL(abe_irq_processing);
246
* abe_clear_irq - clear ABE interrupt
248
* This subroutine is call to clear MCU Irq
250
u32 abe_clear_irq(void)
252
omap_abe_clear_irq(abe);
255
EXPORT_SYMBOL(abe_clear_irq);
258
* abe_disable_irq - disable MCU/DSP ABE interrupt
260
* This subroutine is disabling ABE MCU/DSP Irq
262
u32 abe_disable_irq(void)
264
omap_abe_disable_irq(abe);
268
EXPORT_SYMBOL(abe_disable_irq);
271
* abe_write_event_generator - Selects event generator source
272
* @e: Event Generation Counter, McPDM, DMIC or default.
274
* Loads the AESS event generator hardware source.
275
* Loads the firmware parameters accordingly.
276
* Indicates to the FW which data stream is the most important to preserve
277
* in case all the streams are asynchronous.
278
* If the parameter is "default", then HAL decides which Event source
279
* is the best appropriate based on the opened ports.
281
* When neither the DMIC and the McPDM are activated, the AE will have
282
* its EVENT generator programmed with the EVENT_COUNTER.
283
* The event counter will be tuned in order to deliver a pulse frequency higher
285
* The DPLL output at 100% OPP is MCLK = (32768kHz x6000) = 196.608kHz
286
* The ratio is (MCLK/96000)+(1<<1) = 2050
287
* (1<<1) in order to have the same speed at 50% and 100% OPP
288
* (only 15 MSB bits are used at OPP50%)
290
u32 abe_write_event_generator(u32 e) // should integarte abe as parameter
292
omap_abe_write_event_generator(abe, e);
295
EXPORT_SYMBOL(abe_write_event_generator);
298
* abe_start_event_generator - Starts event generator source
300
* Start the event genrator of AESS. No more event will be send to AESS engine.
301
* Upper layer must wait 1/96kHz to be sure that engine reaches
302
* the IDLE instruction.
304
u32 abe_stop_event_generator(void)
306
omap_abe_stop_event_generator(abe);
309
EXPORT_SYMBOL(abe_stop_event_generator);
312
* abe_connect_debug_trace
313
* @dma2:pointer to the DMEM trace buffer
315
* returns the address and size of the real-time debug trace buffer,
316
* the content of which will vary from one firmware release to another
318
u32 abe_connect_debug_trace(abe_dma_t *dma2)
320
omap_abe_connect_debug_trace(abe, (struct omap_abe_dma *)dma2);
323
EXPORT_SYMBOL(abe_connect_debug_trace);
326
* abe_set_debug_trace
327
* @debug: debug ID from a list to be defined
329
* loads a mask which filters the debug trace to dedicated types of data
331
u32 abe_set_debug_trace(abe_dbg_t debug)
333
omap_abe_set_debug_trace(&abe->dbg, (int)(debug));
336
EXPORT_SYMBOL(abe_set_debug_trace);
339
* abe_set_ping_pong_buffer
341
* @n_bytes: Size of Ping/Pong buffer
343
* Updates the next ping-pong buffer with "size" bytes copied from the
344
* host processor. This API notifies the FW that the data transfer is done.
346
u32 abe_set_ping_pong_buffer(u32 port, u32 n_bytes)
348
omap_abe_set_ping_pong_buffer(abe, port, n_bytes);
351
EXPORT_SYMBOL(abe_set_ping_pong_buffer);
354
* abe_read_next_ping_pong_buffer
356
* @p: Next buffer address (pointer)
357
* @n: Next buffer size (pointer)
359
* Tell the next base address of the next ping_pong Buffer and its size
361
u32 abe_read_next_ping_pong_buffer(u32 port, u32 *p, u32 *n)
363
omap_abe_read_next_ping_pong_buffer(abe, port, p, n);
366
EXPORT_SYMBOL(abe_read_next_ping_pong_buffer);
369
* abe_init_ping_pong_buffer
371
* @size_bytes:size of the ping pong
372
* @n_buffers:number of buffers (2 = ping/pong)
373
* @p:returned address of the ping-pong list of base addresses
374
* (byte offset from DMEM start)
376
* Computes the base address of the ping_pong buffers
378
u32 abe_init_ping_pong_buffer(u32 id, u32 size_bytes, u32 n_buffers,
381
omap_abe_init_ping_pong_buffer(abe, id, size_bytes, n_buffers, p);
384
EXPORT_SYMBOL(abe_init_ping_pong_buffer);
387
* abe_read_offset_from_ping_buffer
389
* @n: returned address of the offset
390
* from the ping buffer start address (in samples)
392
* Computes the current firmware ping pong read pointer location,
393
* expressed in samples, as the offset from the start address of ping buffer.
395
u32 abe_read_offset_from_ping_buffer(u32 id, u32 *n)
397
omap_abe_read_offset_from_ping_buffer(abe, id, n);
400
EXPORT_SYMBOL(abe_read_offset_from_ping_buffer);
403
* abe_write_equalizer
404
* @id: name of the equalizer
405
* @param : equalizer coefficients
407
* Load the coefficients in CMEM.
409
u32 abe_write_equalizer(u32 id, abe_equ_t *param)
411
omap_abe_write_equalizer(abe, id, (struct omap_abe_equ *)param);
414
EXPORT_SYMBOL(abe_write_equalizer);
422
u32 abe_disable_gain(u32 id, u32 p)
424
omap_abe_disable_gain(abe, id, p);
427
EXPORT_SYMBOL(abe_disable_gain);
435
u32 abe_enable_gain(u32 id, u32 p)
437
omap_abe_enable_gain(abe, id, p);
440
EXPORT_SYMBOL(abe_enable_gain);
449
u32 abe_mute_gain(u32 id, u32 p)
451
omap_abe_mute_gain(abe, id, p);
454
EXPORT_SYMBOL(abe_mute_gain);
463
u32 abe_unmute_gain(u32 id, u32 p)
465
omap_abe_unmute_gain(abe, id, p);
468
EXPORT_SYMBOL(abe_unmute_gain);
472
* @id: gain name or mixer name
473
* @f_g: list of input gains of the mixer
474
* @ramp: gain ramp speed factor
475
* @p: list of ports corresponding to the above gains
477
* Loads the gain coefficients to FW memory. This API can be called when
478
* the corresponding MIXER is not activated. After reloading the firmware
479
* the default coefficients corresponds to "all input and output mixer's gain
480
* in mute state". A mixer is disabled with a network reconfiguration
481
* corresponding to an OPP value.
483
u32 abe_write_gain(u32 id, s32 f_g, u32 ramp, u32 p)
485
omap_abe_write_gain(abe, id, f_g, ramp, p);
488
EXPORT_SYMBOL(abe_write_gain);
492
* @id: name of the mixer
493
* @param: input gains and delay ramp of the mixer
494
* @p: port corresponding to the above gains
496
* Load the gain coefficients in FW memory. This API can be called when
497
* the corresponding MIXER is not activated. After reloading the firmware
498
* the default coefficients corresponds to "all input and output mixer's
499
* gain in mute state". A mixer is disabled with a network reconfiguration
500
* corresponding to an OPP value.
502
u32 abe_write_mixer(u32 id, s32 f_g, u32 f_ramp, u32 p)
504
omap_abe_write_gain(abe, id, f_g, f_ramp, p);
507
EXPORT_SYMBOL(abe_write_mixer);
511
* @id: name of the mixer
512
* @param: list of input gains of the mixer
513
* @p: list of port corresponding to the above gains
516
u32 abe_read_gain(u32 id, u32 *f_g, u32 p)
518
omap_abe_read_gain(abe, id, f_g, p);
521
EXPORT_SYMBOL(abe_read_gain);
525
* @id: name of the mixer
526
* @param: gains of the mixer
527
* @p: port corresponding to the above gains
529
* Load the gain coefficients in FW memory. This API can be called when
530
* the corresponding MIXER is not activated. After reloading the firmware
531
* the default coefficients corresponds to "all input and output mixer's
532
* gain in mute state". A mixer is disabled with a network reconfiguration
533
* corresponding to an OPP value.
535
u32 abe_read_mixer(u32 id, u32 *f_g, u32 p)
537
omap_abe_read_gain(abe, id, f_g, p);
540
EXPORT_SYMBOL(abe_read_mixer);
543
* abe_set_router_configuration
544
* @Id: name of the router
545
* @Conf: id of the configuration
546
* @param: list of output index of the route
548
* The uplink router takes its input from DMIC (6 samples), AMIC (2 samples)
549
* and PORT1/2 (2 stereo ports). Each sample will be individually stored in
550
* an intermediate table of 10 elements.
552
* Example of router table parameter for voice uplink with phoenix microphones
554
* indexes 0 .. 9 = MM_UL description (digital MICs and MMEXTIN)
555
* DMIC1_L_labelID, DMIC1_R_labelID, DMIC2_L_labelID, DMIC2_R_labelID,
556
* MM_EXT_IN_L_labelID, MM_EXT_IN_R_labelID, ZERO_labelID, ZERO_labelID,
557
* ZERO_labelID, ZERO_labelID,
558
* indexes 10 .. 11 = MM_UL2 description (recording on DMIC3)
559
* DMIC3_L_labelID, DMIC3_R_labelID,
560
* indexes 12 .. 13 = VX_UL description (VXUL based on PDMUL data)
561
* AMIC_L_labelID, AMIC_R_labelID,
562
* indexes 14 .. 15 = RESERVED (NULL)
563
* ZERO_labelID, ZERO_labelID,
565
u32 abe_set_router_configuration(u32 id, u32 k, u32 *param)
567
omap_abe_set_router_configuration(abe, id, k, param);
570
EXPORT_SYMBOL(abe_set_router_configuration);
573
* abe_set_opp_processing - Set OPP mode for ABE Firmware
576
* New processing network and OPP:
577
* 0: Ultra Lowest power consumption audio player (no post-processing, no mixer)
578
* 1: OPP 25% (simple multimedia features, including low-power player)
579
* 2: OPP 50% (multimedia and voice calls)
580
* 3: OPP100% ( multimedia complex use-cases)
582
* Rearranges the FW task network to the corresponding OPP list of features.
583
* The corresponding AE ports are supposed to be set/reset accordingly before
587
u32 abe_set_opp_processing(u32 opp)
589
omap_abe_set_opp_processing(abe, opp);
592
EXPORT_SYMBOL(abe_set_opp_processing);
595
* abe_disable_data_transfer
598
* disables the ATC descriptor and stop IO/port activities
599
* disable the IO task (@f = 0)
600
* clear ATC DMEM buffer, ATC enabled
602
u32 abe_disable_data_transfer(u32 id)
604
omap_abe_disable_data_transfer(abe, id);
607
EXPORT_SYMBOL(abe_disable_data_transfer);
610
* abe_enable_data_transfer
613
* enables the ATC descriptor
615
* enable the IO task (@f <> 0)
617
u32 abe_enable_data_transfer(u32 id)
619
omap_abe_enable_data_transfer(abe, id);
622
EXPORT_SYMBOL(abe_enable_data_transfer);
625
* abe_connect_cbpr_dmareq_port
627
* @f: desired data format
628
* @d: desired dma_request line (0..7)
629
* @a: returned pointer to the base address of the CBPr register and number of
630
* samples to exchange during a DMA_request.
632
* enables the data echange between a DMA and the ABE through the
633
* CBPr registers of AESS.
635
u32 abe_connect_cbpr_dmareq_port(u32 id, abe_data_format_t *f, u32 d,
636
abe_dma_t *returned_dma_t)
638
omap_abe_connect_cbpr_dmareq_port(abe, id, f, d, returned_dma_t);
641
EXPORT_SYMBOL(abe_connect_cbpr_dmareq_port);
644
* abe_connect_irq_ping_pong_port
646
* @f: desired data format
647
* @I: index of the call-back subroutine to call
648
* @s: half-buffer (ping) size
649
* @p: returned base address of the first (ping) buffer)
651
* enables the data echanges between a direct access to the DMEM
652
* memory of ABE using cache flush. On each IRQ activation a subroutine
653
* registered with "abe_plug_subroutine" will be called. This subroutine
654
* will generate an amount of samples, send them to DMEM memory and call
655
* "abe_set_ping_pong_buffer" to notify the new amount of samples in the
658
u32 abe_connect_irq_ping_pong_port(u32 id, abe_data_format_t *f,
659
u32 subroutine_id, u32 size,
660
u32 *sink, u32 dsp_mcu_flag)
662
omap_abe_connect_irq_ping_pong_port(abe, id, f, subroutine_id, size,
666
EXPORT_SYMBOL(abe_connect_irq_ping_pong_port);
669
* abe_connect_serial_port()
672
* @i: peripheral ID (McBSP #1, #2, #3)
674
* Operations : enables the data echanges between a McBSP and an ATC buffer in
675
* DMEM. This API is used connect 48kHz McBSP streams to MM_DL and 8/16kHz
676
* voice streams to VX_UL, VX_DL, BT_VX_UL, BT_VX_DL. It abstracts the
677
* abe_write_port API.
679
u32 abe_connect_serial_port(u32 id, abe_data_format_t *f,
682
omap_abe_connect_serial_port(abe, id, f, mcbsp_id);
685
EXPORT_SYMBOL(abe_connect_serial_port);
688
* abe_read_port_address
689
* @dma: output pointer to the DMA iteration and data destination pointer
691
* This API returns the address of the DMA register used on this audio port.
692
* Depending on the protocol being used, adds the base address offset L3
695
u32 abe_read_port_address(u32 port, abe_dma_t *dma2)
697
omap_abe_read_port_address(abe, port, dma2);
700
EXPORT_SYMBOL(abe_read_port_address);
703
* abe_check_activity - Check if some ABE activity.
705
* Check if any ABE ports are running.
706
* return 1: still activity on ABE
707
* return 0: no more activity on ABE. Event generator can be stopped
710
u32 abe_check_activity(void)
712
return (u32)omap_abe_check_activity(abe);
714
EXPORT_SYMBOL(abe_check_activity);
716
* abe_use_compensated_gain
719
* Selects the automatic Mixer's gain management
720
* on_off = 1 allows the "abe_write_gain" to adjust the overall
721
* gains of the mixer to be tuned not to create saturation
723
abehal_status abe_use_compensated_gain(u32 on_off)
725
omap_abe_use_compensated_gain(abe, (int)(on_off));
728
EXPORT_SYMBOL(abe_use_compensated_gain);