blob: cc9d14d3de43f682ac82018f563c7633181ba875 [file] [log] [blame]
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -08001/* Copyright (c) 2016-2017, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
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#ifndef BTFM_SLIM_H
13#define BTFM_SLIM_H
14#include <linux/slimbus/slimbus.h>
15
Satish Kodishala75fa6662017-05-01 19:17:06 +053016#define BTFMSLIM_DBG(fmt, arg...) pr_debug("%s: " fmt "\n", __func__, ## arg)
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080017#define BTFMSLIM_INFO(fmt, arg...) pr_info("%s: " fmt "\n", __func__, ## arg)
18#define BTFMSLIM_ERR(fmt, arg...) pr_err("%s: " fmt "\n", __func__, ## arg)
19
20/* Vendor specific defines
21 * This should redefines in slimbus slave specific header
22 */
23#define SLIM_SLAVE_COMPATIBLE_STR "btfmslim_slave"
24#define SLIM_SLAVE_REG_OFFSET 0x0000
25#define SLIM_SLAVE_RXPORT NULL
26#define SLIM_SLAVE_TXPORT NULL
27#define SLIM_SLAVE_INIT NULL
28#define SLIM_SLAVE_PORT_EN NULL
29
30/* Misc defines */
31#define SLIM_SLAVE_RW_MAX_TRIES 3
32#define SLIM_SLAVE_PRESENT_TIMEOUT 100
33
34#define PGD 1
35#define IFD 0
36
37
38/* Codec driver defines */
39enum {
40 BTFM_FM_SLIM_TX = 0,
41 BTFM_BT_SCO_SLIM_TX,
42 BTFM_BT_SCO_A2DP_SLIM_RX,
43 BTFM_BT_SPLIT_A2DP_SLIM_RX,
44 BTFM_SLIM_NUM_CODEC_DAIS
45};
46
47/* Slimbus Port defines - This should be redefined in specific device file */
48#define BTFM_SLIM_PGD_PORT_LAST 0xFF
49
50struct btfmslim_ch {
51 int id;
52 char *name;
53 uint32_t port_hdl; /* slimbus port handler */
54 uint16_t port; /* slimbus port number */
55
56 uint8_t ch; /* slimbus channel number */
57 uint16_t ch_hdl; /* slimbus channel handler */
58 uint16_t grph; /* slimbus group channel handler */
59};
60
61struct btfmslim {
62 struct device *dev;
63 struct slim_device *slim_pgd;
64 struct slim_device slim_ifd;
65 struct mutex io_lock;
66 struct mutex xfer_lock;
67 uint8_t enabled;
68
69 uint32_t num_rx_port;
70 uint32_t num_tx_port;
Satish Kodishala93194f82017-05-18 20:11:20 +053071 uint32_t sample_rate;
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080072
73 struct btfmslim_ch *rx_chs;
74 struct btfmslim_ch *tx_chs;
75
76 int (*vendor_init)(struct btfmslim *btfmslim);
77 int (*vendor_port_en)(struct btfmslim *btfmslim, uint8_t port_num,
78 uint8_t rxport, uint8_t enable);
79};
80
81/**
82 * btfm_slim_hw_init: Initialize slimbus slave device
83 * Returns:
84 * 0: Success
85 * else: Fail
86 */
87int btfm_slim_hw_init(struct btfmslim *btfmslim);
88
89/**
90 * btfm_slim_hw_deinit: Deinitialize slimbus slave device
91 * Returns:
92 * 0: Success
93 * else: Fail
94 */
95int btfm_slim_hw_deinit(struct btfmslim *btfmslim);
96
97/**
98 * btfm_slim_write: write value to pgd or ifd device
99 * @btfmslim: slimbus slave device data pointer.
100 * @reg: slimbus slave register address
101 * @bytes: length of data
102 * @src: data pointer to write
103 * @pgd: selection for device: either PGD or IFD
104 * Returns:
105 * -EINVAL
106 * -ETIMEDOUT
107 * -ENOMEM
108 */
109int btfm_slim_write(struct btfmslim *btfmslim,
110 uint16_t reg, int bytes, void *src, uint8_t pgd);
111
112
113
114/**
115 * btfm_slim_read: read value from pgd or ifd device
116 * @btfmslim: slimbus slave device data pointer.
117 * @reg: slimbus slave register address
118 * @bytes: length of data
119 * @dest: data pointer to read
120 * @pgd: selection for device: either PGD or IFD
121 * Returns:
122 * -EINVAL
123 * -ETIMEDOUT
124 * -ENOMEM
125 */
126int btfm_slim_read(struct btfmslim *btfmslim,
127 uint16_t reg, int bytes, void *dest, uint8_t pgd);
128
129
130/**
131 * btfm_slim_enable_ch: enable channel for slimbus slave port
132 * @btfmslim: slimbus slave device data pointer.
133 * @ch: slimbus slave channel pointer
134 * @rxport: rxport or txport
135 * Returns:
136 * -EINVAL
137 * -ETIMEDOUT
138 * -ENOMEM
139 */
140int btfm_slim_enable_ch(struct btfmslim *btfmslim,
141 struct btfmslim_ch *ch, uint8_t rxport, uint32_t rates,
142 uint8_t grp, uint8_t nchan);
143
144/**
145 * btfm_slim_disable_ch: disable channel for slimbus slave port
146 * @btfmslim: slimbus slave device data pointer.
147 * @ch: slimbus slave channel pointer
148 * @rxport: rxport or txport
149 * Returns:
150 * -EINVAL
151 * -ETIMEDOUT
152 * -ENOMEM
153 */
154int btfm_slim_disable_ch(struct btfmslim *btfmslim,
155 struct btfmslim_ch *ch, uint8_t rxport, uint8_t grp, uint8_t nchan);
156
157/**
158 * btfm_slim_register_codec: Register codec driver in slimbus device node
159 * @dev: device node
160 * Returns:
161 * -ENOMEM
162 * 0
163 */
164int btfm_slim_register_codec(struct device *dev);
Satish kumar sugasibcf528a2017-07-27 13:37:22 -0700165
166/**
167 * btfm_slim_unregister_codec: Unregister codec driver in slimbus device node
168 * @dev: device node
169 * Returns:
170 * VOID
171 */
172void btfm_slim_unregister_codec(struct device *dev);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800173#endif /* BTFM_SLIM_H */