GNU Linux-libre 4.9.309-gnu1
[releases.git] / drivers / staging / most / hdm-dim2 / dim2_hal.h
1 /*
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>
19 #include "dim2_reg.h"
20
21 /*
22  * The values below are specified in the hardware specification.
23  * So, they should not be changed until the hardware specification changes.
24  */
25 enum 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
36 struct dim_ch_state_t {
37         bool ready; /* Shows readiness to enqueue next buffer */
38         u16 done_buffers; /* Number of completed buffers */
39 };
40
41 struct int_ch_state {
42         /* changed only in interrupt context */
43         volatile int request_counter;
44
45         /* changed only in task context */
46         volatile int service_counter;
47
48         u8 idx1;
49         u8 idx2;
50         u8 level; /* [0..2], buffering level */
51 };
52
53 struct 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
63 u8 dim_startup(struct dim2_regs __iomem *dim_base_address, u32 mlb_clock,
64                u32 fcnt);
65
66 void dim_shutdown(void);
67
68 bool dim_get_lock_state(void);
69
70 u16 dim_norm_ctrl_async_buffer_size(u16 buf_size);
71
72 u16 dim_norm_isoc_buffer_size(u16 buf_size, u16 packet_length);
73
74 u16 dim_norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame);
75
76 u8 dim_init_control(struct dim_channel *ch, u8 is_tx, u16 ch_address,
77                     u16 max_buffer_size);
78
79 u8 dim_init_async(struct dim_channel *ch, u8 is_tx, u16 ch_address,
80                   u16 max_buffer_size);
81
82 u8 dim_init_isoc(struct dim_channel *ch, u8 is_tx, u16 ch_address,
83                  u16 packet_length);
84
85 u8 dim_init_sync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
86                  u16 bytes_per_frame);
87
88 u8 dim_destroy_channel(struct dim_channel *ch);
89
90 void dim_service_mlb_int_irq(void);
91
92 void dim_service_ahb_int_irq(struct dim_channel *const *channels);
93
94 u8 dim_service_channel(struct dim_channel *ch);
95
96 struct dim_ch_state_t *dim_get_channel_state(struct dim_channel *ch,
97                                              struct dim_ch_state_t *state_ptr);
98
99 u16 dim_dbr_space(struct dim_channel *ch);
100
101 bool dim_enqueue_buffer(struct dim_channel *ch, u32 buffer_addr,
102                         u16 buffer_size);
103
104 bool dim_detach_buffers(struct dim_channel *ch, u16 buffers_number);
105
106 u32 dimcb_io_read(u32 __iomem *ptr32);
107
108 void dimcb_io_write(u32 __iomem *ptr32, u32 value);
109
110 void dimcb_on_error(u8 error_id, const char *error_message);
111
112 #endif /* _DIM2_HAL_H */