1 /*******************************************************************************
3 Intel SmartPHY DSL PCIe Endpoint/ACA Linux driver
4 Copyright(c) 2016 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
22 *******************************************************************************/
27 #include <linux/types.h>
28 #include <linux/pci.h>
29 #include <linux/device.h>
32 /*! \def DC_EP_MAX_PEER
33 * \brief how many EP partners existed. In most cases, this number should be
34 * one for bonding application. For the future extension, it could be bigger
35 * value. For example, multiple bonding
37 #define DC_EP_MAX_PEER 1
39 /* Reset related module bit definition */
40 #define RST_GPIO BIT(2)
41 #define RST_DSL_IF BIT(3)
42 #define RST_DFE BIT(7)
43 #define RST_PPE BIT(8)
44 #define RST_CDMA BIT(9)
45 #define RST_SPI BIT(10)
46 #define RST_IMCU BIT(11)
47 #define RST_ACA_DMA BIT(14)
48 #define RST_AFE BIT(16)
49 #define RST_ACA_HOSTIF BIT(17)
50 #define RST_PCIE BIT(22)
51 #define RST_PPE_ATM_TC BIT(23)
52 #define RST_FPI_SLAVE BIT(25)
53 #define RST_GLOBAL BIT(30)
55 /* PMU related module definition */
56 #define PMU_ADMA BIT(0)
57 #define PMU_CDMA BIT(2)
58 #define PMU_SPI BIT(8)
59 #define PMU_DSL BIT(9)
60 #define PMU_PPE_QSB BIT(18)
61 #define PMU_PPE_SLL01 BIT(19)
62 #define PMU_PPE_TC BIT(21)
63 #define PMU_EMA BIT(22)
64 #define PMU_PPM2 BIT(23)
65 #define PMU_PPE_TOP BIT(29)
67 /* IMER bit definition */
68 #define PPE2HOST_INT0 BIT(0)
69 #define PPE2HOST_INT1 BIT(1)
70 #define DYING_GASP_INT BIT(3)
71 #define MEI_IRQ BIT(8)
72 #define ACA_XBAR_INT BIT(9)
73 #define MODEM_XBAR_INT BIT(12)
74 #define LED0_INT BIT(13)
75 #define LED1_INT BIT(14)
76 #define NMI_PLL BIT(15)
77 #define DMA_TX BIT(16)
78 #define DMA_RX BIT(17)
79 #define ACA_HOSTIF_TX BIT(20)
80 #define ACA_HOSTIF_RX BIT(21)
81 #define ACA_RXOUT_PD_RING_FULL BIT(22)
82 #define ACA_TXOUT_PD_RING_FULL BIT(23)
85 * Structure used to specify available pin mux functions for gpio pinx
86 * It will be used in pinmux_set() function
96 * Structure used to specify interrupt source so that EP can assign unique
100 DC_EP_INT_PPE
, /*!< PPE2HOST_INT 0/1 */
101 DC_EP_INT_MEI
, /*!< DSL MEI_IRQ */
105 /* Clock setting for system clock */
112 /* Clock setting for PPE clock */
122 /* GPIO direction IN/OUT */
129 /* GPIO Pullup/Pulldown setting */
131 GPIO_PUPD_DISABLE
= 0,
137 /* GPIO slew rate setting */
139 GPIO_SLEW_RATE_SLOW
= 0,
143 /* GPIO driver current setting */
145 GPIO_DRV_CUR_2MA
= 0,
153 ACA_LITTLE_ENDIAN
= 0,
166 /* ACA four major direction functions for start/stop */
167 #define ACA_TXIN_EN BIT(0)
168 #define ACA_TXOUT_EN BIT(1)
169 #define ACA_RXIN_EN BIT(2)
170 #define ACA_RXOUT_EN BIT(3)
171 #define ACA_ALL_EN 0xF
176 * ACA SoC specific parameters. The caller needs to fill up all necessary info
177 * according to specific SoC and specific project
178 * For each function, different parameters are needed.
180 struct aca_cfg_param
{
181 u32 soc_desc_base
; /*!< SoC CBM or DDR descriptor base address */
182 u32 soc_desc_num
; /*!< SoC and HostIF (same) descriptor number */
183 u32 soc_cmlt_cnt_addr
; /*! SoC cumulative counter address */
184 u32 pp_buf_desc_num
; /*!< ACA ping pong buffer descriptor number */
185 u32 pd_desc_base
; /*!< Packet Descriptor base address in modem */
186 u32 pd_desc_num
; /*!< Packet Descriptor number in modem */
187 u32 hd_size_in_dw
; /*!< Host(SoC) descriptor size in dwords */
188 u32 pd_size_in_dw
; /*!< Packet descriptor size in dwords */
189 u32 byteswap
; /*!< Byte swap enabled or not in ACA FW */
190 u32 prefill_cnt
; /*!< Prefill counter special required for some platform */
194 struct aca_cfg_param aca_txin
;
195 struct aca_cfg_param aca_txout
;
196 struct aca_cfg_param aca_rxin
;
197 struct aca_cfg_param aca_rxout
;
200 /* ACA project/modem specific parameters. It is only valid for VRX518 */
201 struct aca_proj_param
{
202 u32 stat
; /*!< Target state */
203 u32 pd
; /*!< Target packet descripor */
204 u32 acc_cnt
; /*!< Target accumulate counter */
207 /* Project specific configuration */
208 struct aca_modem_param
{
209 struct aca_proj_param mdm_txout
;
210 struct aca_proj_param mdm_rxin
;
211 struct aca_proj_param mdm_rxout
;
214 /* Event trigger register address <offset> */
215 struct aca_event_reg_addr
{
223 * ACA common hardware low level APIs, presented as callbacks instead of
224 * separate APIs to support mulitple instances
228 void (*reset_assert
)(struct dc_ep_dev
*pdev
, u32 rd
);
229 void (*reset_deassert
)(struct dc_ep_dev
*pdev
, u32 rd
);
230 /* For hardware self-clear reset, most apply except PCIe */
231 int (*reset_device
)(struct dc_ep_dev
*pdev
, u32 hd
);
234 int (*clk_on
)(struct dc_ep_dev
*pdev
, u32 cd
);
235 int (*clk_off
)(struct dc_ep_dev
*pdev
, u32 cd
);
238 int (*clk_set
)(struct dc_ep_dev
*pdev
, u32 sysclk
, u32 ppeclk
);
239 int (*clk_get
)(struct dc_ep_dev
*pdev
, u32
*sysclk
, u32
*ppeclk
);
242 int (*gpio_dir
)(struct dc_ep_dev
*pdev
, u32 gpio
, int dir
);
243 int (*gpio_set
)(struct dc_ep_dev
*pdev
, u32 gpio
, int val
);
244 int (*gpio_get
)(struct dc_ep_dev
*pdev
, u32 gpio
, int *val
);
246 /* PinMux Callbacks */
247 int (*pinmux_set
)(struct dc_ep_dev
*pdev
, u32 gpio
, int func
);
248 int (*pinmux_get
)(struct dc_ep_dev
*pdev
, u32 gpio
, int *func
);
249 int (*gpio_pupd_set
)(struct dc_ep_dev
*pdev
, u32 gpio
, u32 val
);
250 int (*gpio_od_set
)(struct dc_ep_dev
*pdev
, u32 gpio
, int val
);
251 int (*gpio_src_set
)(struct dc_ep_dev
*pdev
, u32 gpio
, int val
);
252 int (*gpio_dcc_set
)(struct dc_ep_dev
*pdev
, u32 gpio
, u32 val
);
255 void (*icu_en
)(struct dc_ep_dev
*pdev
, u32 bit
);
256 void (*icu_mask
)(struct dc_ep_dev
*pdev
, u32 bit
);
258 /* ACA related stuff */
259 int (*aca_start
)(struct dc_ep_dev
*pdev
, u32 func
, int start
);
260 int (*aca_stop
)(struct dc_ep_dev
*pdev
, u32
*func
, int reset
);
261 /* If there is no project specific parameters, input NULL */
262 int (*aca_init
)(struct dc_ep_dev
*pdev
, struct aca_param
*aca
,
263 struct aca_modem_param
*mdm
);
264 void (*aca_event_addr_get
)(struct dc_ep_dev
*pdev
,
265 struct aca_event_reg_addr
*regs
);
266 /* UMT address needed for SoC filled in to trigger UMT msg */
267 u32 (*umt_msg_addr
)(struct dc_ep_dev
*pdev
, u32 endian
, u32 type
);
268 /* TXIN accum sub to ack PPE already processed */
269 void (*aca_txin_ack_sub
)(struct dc_ep_dev
*pdev
, u32 val
);
270 u32 (*aca_txin_hd_cnt
)(struct dc_ep_dev
*pdev
);
274 * Structure used to extract attached EP detailed information
275 * for PPE/DSL_MEI driver/Bonding
279 u32 irq
; /*!< MSI interrupt number for this device */
280 u32 aca_tx_irq
; /*!< ACA Non-empty TX irq number for PPE driver */
281 u32 aca_rx_irq
; /*!< ACA Non-empty RX irq number for PPE driver */
282 /*!< The EP inbound memory base address derived from BAR0, SoC
283 virtual address for PPE/DSL_MEI driver
285 bool switch_attached
; /*!< EP attach switch */
286 u8 __iomem
*membase
; /*!< virtual memory base address to access EP */
287 u32 phy_membase
; /*!< The EP inbound memory base address derived
288 from BAR0, physical address for PPE FW
290 u32 peer_num
; /*!< Bonding peer number available */
291 /*!< The bonding peer EP inbound memory base address derived from
292 its BAR0, SoC virtual address for PPE/DSL_MEI driver
294 u8 __iomem
*peer_membase
[DC_EP_MAX_PEER
];
295 /*!< The bonding peer EP inbound memory base address derived from
296 its BAR0, physical address for PPE FW
298 u32 peer_phy_membase
[DC_EP_MAX_PEER
];
299 const struct aca_hw_ops
*hw_ops
;
300 void *priv
; /* Pointer to driver proprietary data for internal use */
304 * This function returns the total number of EPs attached. Normally,
305 * the number should be one <standard smartPHY EP> or two <smartPHY
306 * off-chip bonding cases>. Extended case is also considered
308 * \param[in/out] dev_num Pointer to detected EP numbers in total.
309 * \return -EIO Invalid total EP number which means this
310 * module is not initialized properly
311 * \return 0 Successfully return the detected EP numbers
313 int dc_ep_dev_num_get(int *dev_num
);
316 * This function returns detailed EP device information for PPE/DSL/Bonding
317 * partner by its logical index obtained
318 * by \ref dc_ep_dev_num_get and its interrupt module number
321 * \param[in] dev_idx Logical device index referred to the related
323 * \param[in] module EP interrupt module user<PPE/MEI>
324 * \param[in/out] dev Pointer to returned detail device structure
326 * \return -EIO Invalid logical device index or too many modules
327 * referred to this module
328 * \return 0 Successfully return required device information
330 * \remarks This function normally will be called to trace the detailed device
331 * information after calling \ref dc_ep_dev_num_get
333 int dc_ep_dev_info_req(int dev_idx
, enum dc_ep_int module
,
334 struct dc_ep_dev
*dev
);
337 * This function releases the usage of this module by PPE/DSL
339 * \param[in] dev_idx Logical device index referred to the related device
340 * \return -EIO Invalid logical device index or release too many
341 * times to refer to this module
342 * \return 0 Successfully release the usage of this module
344 * \remarks This function should be called once their reference is over.
345 * The reference usage must matches \ref dc_ep_dev_info_req
347 int dc_ep_dev_info_release(int dev_idx
);