blob: 6df6ea5f7da4b61a05db684f17ccd16d677f3c4d [file] [log] [blame]
Christian Grommba3d7dd2015-07-24 16:11:53 +02001/*
2 * dim2_hal.h - DIM2 HAL interface
3 * (MediaLB, Device Interface Macro IP, OS62420)
4 *
5 * Copyright (C) 2015, Microchip Technology Germany II GmbH & Co. KG
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * This file is licensed under GPLv2.
13 */
14
15#ifndef _DIM2_HAL_H
16#define _DIM2_HAL_H
17
18#include <linux/types.h>
Hugo Camboulive092c78f2016-01-02 22:33:26 +000019#include "dim2_reg.h"
Christian Grommba3d7dd2015-07-24 16:11:53 +020020
Christian Grommba3d7dd2015-07-24 16:11:53 +020021/*
22 * The values below are specified in the hardware specification.
23 * So, they should not be changed until the hardware specification changes.
24 */
25enum mlb_clk_speed {
26 CLK_256FS = 0,
27 CLK_512FS = 1,
28 CLK_1024FS = 2,
29 CLK_2048FS = 3,
30 CLK_3072FS = 4,
31 CLK_4096FS = 5,
32 CLK_6144FS = 6,
33 CLK_8192FS = 7,
34};
35
36struct dim_ch_state_t {
37 bool ready; /* Shows readiness to enqueue next buffer */
38 u16 done_buffers; /* Number of completed buffers */
39};
40
Christian Grommba3d7dd2015-07-24 16:11:53 +020041struct int_ch_state {
42 /* changed only in interrupt context */
PrasannaKumar Muralidharanafb10552016-03-12 14:03:09 +053043 volatile int request_counter;
Christian Grommba3d7dd2015-07-24 16:11:53 +020044
45 /* changed only in task context */
PrasannaKumar Muralidharanafb10552016-03-12 14:03:09 +053046 volatile int service_counter;
Christian Grommba3d7dd2015-07-24 16:11:53 +020047
48 u8 idx1;
49 u8 idx2;
50 u8 level; /* [0..2], buffering level */
51};
52
53struct dim_channel {
54 struct int_ch_state state;
55 u8 addr;
56 u16 dbr_addr;
57 u16 dbr_size;
58 u16 packet_length; /*< Isochronous packet length in bytes. */
59 u16 bytes_per_frame; /*< Synchronous bytes per frame. */
60 u16 done_sw_buffers_number; /*< Done software buffers number. */
61};
62
Christian Gromm63c87662016-06-13 16:24:24 +020063u8 dim_startup(struct dim2_regs __iomem *dim_base_address, u32 mlb_clock,
64 u32 fcnt);
Christian Grommba3d7dd2015-07-24 16:11:53 +020065
Chaehyun Lim50a45b12015-10-29 16:44:12 +090066void dim_shutdown(void);
Christian Grommba3d7dd2015-07-24 16:11:53 +020067
Chaehyun Limb7242072015-11-02 22:59:01 +090068bool dim_get_lock_state(void);
Christian Grommba3d7dd2015-07-24 16:11:53 +020069
Chaehyun Limc64c60732015-11-02 22:59:05 +090070u16 dim_norm_ctrl_async_buffer_size(u16 buf_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +020071
Chaehyun Lime302ca42015-11-02 22:59:06 +090072u16 dim_norm_isoc_buffer_size(u16 buf_size, u16 packet_length);
Christian Grommba3d7dd2015-07-24 16:11:53 +020073
Chaehyun Limaff19242015-11-02 22:59:07 +090074u16 dim_norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame);
Christian Grommba3d7dd2015-07-24 16:11:53 +020075
Chaehyun Lima3f3e922015-11-02 22:59:08 +090076u8 dim_init_control(struct dim_channel *ch, u8 is_tx, u16 ch_address,
77 u16 max_buffer_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +020078
Chaehyun Lim26303152015-11-02 22:59:09 +090079u8 dim_init_async(struct dim_channel *ch, u8 is_tx, u16 ch_address,
80 u16 max_buffer_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +020081
Chaehyun Limf1383172015-11-02 22:59:10 +090082u8 dim_init_isoc(struct dim_channel *ch, u8 is_tx, u16 ch_address,
83 u16 packet_length);
Christian Grommba3d7dd2015-07-24 16:11:53 +020084
Chaehyun Lim10e5efb2015-11-02 22:59:11 +090085u8 dim_init_sync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
86 u16 bytes_per_frame);
Christian Grommba3d7dd2015-07-24 16:11:53 +020087
Chaehyun Lima5e4d892015-11-02 22:59:12 +090088u8 dim_destroy_channel(struct dim_channel *ch);
Christian Grommba3d7dd2015-07-24 16:11:53 +020089
Andrey Shvetsov8f533462016-09-15 16:19:13 +020090void dim_service_mlb_int_irq(void);
91
Andrey Shvetsov055f1d12016-09-15 16:19:09 +020092void dim_service_ahb_int_irq(struct dim_channel *const *channels);
Christian Grommba3d7dd2015-07-24 16:11:53 +020093
Chaehyun Lim0d08d542015-11-02 22:59:14 +090094u8 dim_service_channel(struct dim_channel *ch);
Christian Grommba3d7dd2015-07-24 16:11:53 +020095
Chaehyun Lim60d5f662015-11-02 22:59:16 +090096struct dim_ch_state_t *dim_get_channel_state(struct dim_channel *ch,
97 struct dim_ch_state_t *state_ptr);
Christian Grommba3d7dd2015-07-24 16:11:53 +020098
Andrey Shvetsov8f533462016-09-15 16:19:13 +020099u16 dim_dbr_space(struct dim_channel *ch);
100
Chaehyun Limc904ffd2015-11-02 22:59:17 +0900101bool dim_enqueue_buffer(struct dim_channel *ch, u32 buffer_addr,
102 u16 buffer_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200103
Chaehyun Lim38c38542015-10-29 16:44:13 +0900104bool dim_detach_buffers(struct dim_channel *ch, u16 buffers_number);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200105
Hugo Camboulive092c78f2016-01-02 22:33:26 +0000106u32 dimcb_io_read(u32 __iomem *ptr32);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200107
Hugo Camboulive092c78f2016-01-02 22:33:26 +0000108void dimcb_io_write(u32 __iomem *ptr32, u32 value);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200109
Chaehyun Limde668732015-11-02 22:59:02 +0900110void dimcb_on_error(u8 error_id, const char *error_message);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200111
Christian Grommba3d7dd2015-07-24 16:11:53 +0200112#endif /* _DIM2_HAL_H */