blob: fc653fde261210d2075ffd062e0b42ecafb77461 [file] [log] [blame]
Satish Kodishalaf542e4b2018-03-05 17:53:10 +05301/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved.
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -08002 *
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
Satish Kodishalaf542e4b2018-03-05 17:53:10 +053081extern int btfm_feedback_ch_setting;
82
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -080083/**
84 * btfm_slim_hw_init: Initialize slimbus slave device
85 * Returns:
86 * 0: Success
87 * else: Fail
88 */
89int btfm_slim_hw_init(struct btfmslim *btfmslim);
90
91/**
92 * btfm_slim_hw_deinit: Deinitialize slimbus slave device
93 * Returns:
94 * 0: Success
95 * else: Fail
96 */
97int btfm_slim_hw_deinit(struct btfmslim *btfmslim);
98
99/**
100 * btfm_slim_write: write value to pgd or ifd device
101 * @btfmslim: slimbus slave device data pointer.
102 * @reg: slimbus slave register address
103 * @bytes: length of data
104 * @src: data pointer to write
105 * @pgd: selection for device: either PGD or IFD
106 * Returns:
107 * -EINVAL
108 * -ETIMEDOUT
109 * -ENOMEM
110 */
111int btfm_slim_write(struct btfmslim *btfmslim,
112 uint16_t reg, int bytes, void *src, uint8_t pgd);
113
114
115
116/**
117 * btfm_slim_read: read value from pgd or ifd device
118 * @btfmslim: slimbus slave device data pointer.
119 * @reg: slimbus slave register address
120 * @bytes: length of data
121 * @dest: data pointer to read
122 * @pgd: selection for device: either PGD or IFD
123 * Returns:
124 * -EINVAL
125 * -ETIMEDOUT
126 * -ENOMEM
127 */
128int btfm_slim_read(struct btfmslim *btfmslim,
129 uint16_t reg, int bytes, void *dest, uint8_t pgd);
130
131
132/**
133 * btfm_slim_enable_ch: enable channel for slimbus slave port
134 * @btfmslim: slimbus slave device data pointer.
135 * @ch: slimbus slave channel pointer
136 * @rxport: rxport or txport
137 * Returns:
138 * -EINVAL
139 * -ETIMEDOUT
140 * -ENOMEM
141 */
142int btfm_slim_enable_ch(struct btfmslim *btfmslim,
143 struct btfmslim_ch *ch, uint8_t rxport, uint32_t rates,
144 uint8_t grp, uint8_t nchan);
145
146/**
147 * btfm_slim_disable_ch: disable channel for slimbus slave port
148 * @btfmslim: slimbus slave device data pointer.
149 * @ch: slimbus slave channel pointer
150 * @rxport: rxport or txport
151 * Returns:
152 * -EINVAL
153 * -ETIMEDOUT
154 * -ENOMEM
155 */
156int btfm_slim_disable_ch(struct btfmslim *btfmslim,
157 struct btfmslim_ch *ch, uint8_t rxport, uint8_t grp, uint8_t nchan);
158
159/**
160 * btfm_slim_register_codec: Register codec driver in slimbus device node
161 * @dev: device node
162 * Returns:
163 * -ENOMEM
164 * 0
165 */
166int btfm_slim_register_codec(struct device *dev);
Satish kumar sugasibcf528a2017-07-27 13:37:22 -0700167
168/**
169 * btfm_slim_unregister_codec: Unregister codec driver in slimbus device node
170 * @dev: device node
171 * Returns:
172 * VOID
173 */
174void btfm_slim_unregister_codec(struct device *dev);
Mahesh Kumar Sharma41a4d382017-01-17 17:00:51 -0800175#endif /* BTFM_SLIM_H */