blob: 00d46a5671d9be8b18ee169e49b70872e98de9ec [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
16#define BTFMSLIM_DBG(fmt, arg...) pr_debug("%s: " fmt "\n", __func__, ## arg)
17#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;
71
72 struct btfmslim_ch *rx_chs;
73 struct btfmslim_ch *tx_chs;
74
75 int (*vendor_init)(struct btfmslim *btfmslim);
76 int (*vendor_port_en)(struct btfmslim *btfmslim, uint8_t port_num,
77 uint8_t rxport, uint8_t enable);
78};
79
80/**
81 * btfm_slim_hw_init: Initialize slimbus slave device
82 * Returns:
83 * 0: Success
84 * else: Fail
85 */
86int btfm_slim_hw_init(struct btfmslim *btfmslim);
87
88/**
89 * btfm_slim_hw_deinit: Deinitialize slimbus slave device
90 * Returns:
91 * 0: Success
92 * else: Fail
93 */
94int btfm_slim_hw_deinit(struct btfmslim *btfmslim);
95
96/**
97 * btfm_slim_write: write value to pgd or ifd device
98 * @btfmslim: slimbus slave device data pointer.
99 * @reg: slimbus slave register address
100 * @bytes: length of data
101 * @src: data pointer to write
102 * @pgd: selection for device: either PGD or IFD
103 * Returns:
104 * -EINVAL
105 * -ETIMEDOUT
106 * -ENOMEM
107 */
108int btfm_slim_write(struct btfmslim *btfmslim,
109 uint16_t reg, int bytes, void *src, uint8_t pgd);
110
111
112
113/**
114 * btfm_slim_read: read value from pgd or ifd device
115 * @btfmslim: slimbus slave device data pointer.
116 * @reg: slimbus slave register address
117 * @bytes: length of data
118 * @dest: data pointer to read
119 * @pgd: selection for device: either PGD or IFD
120 * Returns:
121 * -EINVAL
122 * -ETIMEDOUT
123 * -ENOMEM
124 */
125int btfm_slim_read(struct btfmslim *btfmslim,
126 uint16_t reg, int bytes, void *dest, uint8_t pgd);
127
128
129/**
130 * btfm_slim_enable_ch: enable channel for slimbus slave port
131 * @btfmslim: slimbus slave device data pointer.
132 * @ch: slimbus slave channel pointer
133 * @rxport: rxport or txport
134 * Returns:
135 * -EINVAL
136 * -ETIMEDOUT
137 * -ENOMEM
138 */
139int btfm_slim_enable_ch(struct btfmslim *btfmslim,
140 struct btfmslim_ch *ch, uint8_t rxport, uint32_t rates,
141 uint8_t grp, uint8_t nchan);
142
143/**
144 * btfm_slim_disable_ch: disable channel for slimbus slave port
145 * @btfmslim: slimbus slave device data pointer.
146 * @ch: slimbus slave channel pointer
147 * @rxport: rxport or txport
148 * Returns:
149 * -EINVAL
150 * -ETIMEDOUT
151 * -ENOMEM
152 */
153int btfm_slim_disable_ch(struct btfmslim *btfmslim,
154 struct btfmslim_ch *ch, uint8_t rxport, uint8_t grp, uint8_t nchan);
155
156/**
157 * btfm_slim_register_codec: Register codec driver in slimbus device node
158 * @dev: device node
159 * Returns:
160 * -ENOMEM
161 * 0
162 */
163int btfm_slim_register_codec(struct device *dev);
164#endif /* BTFM_SLIM_H */