blob: 1c924e869de7bfe99935b04d61c0e5191093bc5a [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
Hugo Camboulive092c78f2016-01-02 22:33:26 +000063u8 dim_startup(struct dim2_regs __iomem *dim_base_address, u32 mlb_clock);
Christian Grommba3d7dd2015-07-24 16:11:53 +020064
Chaehyun Lim50a45b12015-10-29 16:44:12 +090065void dim_shutdown(void);
Christian Grommba3d7dd2015-07-24 16:11:53 +020066
Chaehyun Limb7242072015-11-02 22:59:01 +090067bool dim_get_lock_state(void);
Christian Grommba3d7dd2015-07-24 16:11:53 +020068
Chaehyun Limc64c60732015-11-02 22:59:05 +090069u16 dim_norm_ctrl_async_buffer_size(u16 buf_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +020070
Chaehyun Lime302ca42015-11-02 22:59:06 +090071u16 dim_norm_isoc_buffer_size(u16 buf_size, u16 packet_length);
Christian Grommba3d7dd2015-07-24 16:11:53 +020072
Chaehyun Limaff19242015-11-02 22:59:07 +090073u16 dim_norm_sync_buffer_size(u16 buf_size, u16 bytes_per_frame);
Christian Grommba3d7dd2015-07-24 16:11:53 +020074
Chaehyun Lima3f3e922015-11-02 22:59:08 +090075u8 dim_init_control(struct dim_channel *ch, u8 is_tx, u16 ch_address,
76 u16 max_buffer_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +020077
Chaehyun Lim26303152015-11-02 22:59:09 +090078u8 dim_init_async(struct dim_channel *ch, u8 is_tx, u16 ch_address,
79 u16 max_buffer_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +020080
Chaehyun Limf1383172015-11-02 22:59:10 +090081u8 dim_init_isoc(struct dim_channel *ch, u8 is_tx, u16 ch_address,
82 u16 packet_length);
Christian Grommba3d7dd2015-07-24 16:11:53 +020083
Chaehyun Lim10e5efb2015-11-02 22:59:11 +090084u8 dim_init_sync(struct dim_channel *ch, u8 is_tx, u16 ch_address,
85 u16 bytes_per_frame);
Christian Grommba3d7dd2015-07-24 16:11:53 +020086
Chaehyun Lima5e4d892015-11-02 22:59:12 +090087u8 dim_destroy_channel(struct dim_channel *ch);
Christian Grommba3d7dd2015-07-24 16:11:53 +020088
Chaehyun Lime5baa9e2015-11-02 22:59:13 +090089void dim_service_irq(struct dim_channel *const *channels);
Christian Grommba3d7dd2015-07-24 16:11:53 +020090
Chaehyun Lim0d08d542015-11-02 22:59:14 +090091u8 dim_service_channel(struct dim_channel *ch);
Christian Grommba3d7dd2015-07-24 16:11:53 +020092
Chaehyun Lim60d5f662015-11-02 22:59:16 +090093struct dim_ch_state_t *dim_get_channel_state(struct dim_channel *ch,
94 struct dim_ch_state_t *state_ptr);
Christian Grommba3d7dd2015-07-24 16:11:53 +020095
Chaehyun Limc904ffd2015-11-02 22:59:17 +090096bool dim_enqueue_buffer(struct dim_channel *ch, u32 buffer_addr,
97 u16 buffer_size);
Christian Grommba3d7dd2015-07-24 16:11:53 +020098
Chaehyun Lim38c38542015-10-29 16:44:13 +090099bool dim_detach_buffers(struct dim_channel *ch, u16 buffers_number);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200100
Hugo Camboulive092c78f2016-01-02 22:33:26 +0000101u32 dimcb_io_read(u32 __iomem *ptr32);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200102
Hugo Camboulive092c78f2016-01-02 22:33:26 +0000103void dimcb_io_write(u32 __iomem *ptr32, u32 value);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200104
Chaehyun Limde668732015-11-02 22:59:02 +0900105void dimcb_on_error(u8 error_id, const char *error_message);
Christian Grommba3d7dd2015-07-24 16:11:53 +0200106
Christian Grommba3d7dd2015-07-24 16:11:53 +0200107#endif /* _DIM2_HAL_H */