2 * Synopsys G210 Test Chip driver
4 * Copyright (C) 2015-2016 Synopsys, Inc. (www.synopsys.com)
6 * Authors: Joao Pinto <jpinto@synopsys.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
16 #include "ufshcd-dwc.h"
17 #include "ufshci-dwc.h"
18 #include "tc-dwc-g210.h"
21 * tc_dwc_g210_setup_40bit_rmmi()
22 * This function configures Synopsys TC specific atributes (40-bit RMMI)
23 * @hba: Pointer to drivers structure
25 * Returns 0 on success or non-zero value on failure
27 static int tc_dwc_g210_setup_40bit_rmmi(struct ufs_hba
*hba
)
29 static const struct ufshcd_dme_attr_val setup_attrs
[] = {
30 { UIC_ARG_MIB(TX_GLOBALHIBERNATE
), 0x00, DME_LOCAL
},
31 { UIC_ARG_MIB(REFCLKMODE
), 0x01, DME_LOCAL
},
32 { UIC_ARG_MIB(CDIRECTCTRL6
), 0x80, DME_LOCAL
},
33 { UIC_ARG_MIB(CBDIVFACTOR
), 0x08, DME_LOCAL
},
34 { UIC_ARG_MIB(CBDCOCTRL5
), 0x64, DME_LOCAL
},
35 { UIC_ARG_MIB(CBPRGTUNING
), 0x09, DME_LOCAL
},
36 { UIC_ARG_MIB(RTOBSERVESELECT
), 0x00, DME_LOCAL
},
37 { UIC_ARG_MIB_SEL(TX_REFCLKFREQ
, SELIND_LN0_TX
), 0x01,
39 { UIC_ARG_MIB_SEL(TX_CFGCLKFREQVAL
, SELIND_LN0_TX
), 0x19,
41 { UIC_ARG_MIB_SEL(CFGEXTRATTR
, SELIND_LN0_TX
), 0x14,
43 { UIC_ARG_MIB_SEL(DITHERCTRL2
, SELIND_LN0_TX
), 0xd6,
45 { UIC_ARG_MIB_SEL(RX_REFCLKFREQ
, SELIND_LN0_RX
), 0x01,
47 { UIC_ARG_MIB_SEL(RX_CFGCLKFREQVAL
, SELIND_LN0_RX
), 0x19,
49 { UIC_ARG_MIB_SEL(CFGWIDEINLN
, SELIND_LN0_RX
), 4,
51 { UIC_ARG_MIB_SEL(CFGRXCDR8
, SELIND_LN0_RX
), 0x80,
53 { UIC_ARG_MIB(DIRECTCTRL10
), 0x04, DME_LOCAL
},
54 { UIC_ARG_MIB(DIRECTCTRL19
), 0x02, DME_LOCAL
},
55 { UIC_ARG_MIB_SEL(CFGRXCDR8
, SELIND_LN0_RX
), 0x80,
57 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG4
, SELIND_LN0_RX
), 0x03,
59 { UIC_ARG_MIB_SEL(CFGRXOVR8
, SELIND_LN0_RX
), 0x16,
61 { UIC_ARG_MIB_SEL(RXDIRECTCTRL2
, SELIND_LN0_RX
), 0x42,
63 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG3
, SELIND_LN0_RX
), 0xa4,
65 { UIC_ARG_MIB_SEL(RXCALCTRL
, SELIND_LN0_RX
), 0x01,
67 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG2
, SELIND_LN0_RX
), 0x01,
69 { UIC_ARG_MIB_SEL(CFGRXOVR4
, SELIND_LN0_RX
), 0x28,
71 { UIC_ARG_MIB_SEL(RXSQCTRL
, SELIND_LN0_RX
), 0x1E,
73 { UIC_ARG_MIB_SEL(CFGRXOVR6
, SELIND_LN0_RX
), 0x2f,
75 { UIC_ARG_MIB_SEL(CFGRXOVR6
, SELIND_LN0_RX
), 0x2f,
77 { UIC_ARG_MIB(CBPRGPLL2
), 0x00, DME_LOCAL
},
80 return ufshcd_dwc_dme_set_attrs(hba
, setup_attrs
,
81 ARRAY_SIZE(setup_attrs
));
85 * tc_dwc_g210_setup_20bit_rmmi_lane0()
86 * This function configures Synopsys TC 20-bit RMMI Lane 0
87 * @hba: Pointer to drivers structure
89 * Returns 0 on success or non-zero value on failure
91 static int tc_dwc_g210_setup_20bit_rmmi_lane0(struct ufs_hba
*hba
)
93 static const struct ufshcd_dme_attr_val setup_attrs
[] = {
94 { UIC_ARG_MIB_SEL(TX_REFCLKFREQ
, SELIND_LN0_TX
), 0x01,
96 { UIC_ARG_MIB_SEL(TX_CFGCLKFREQVAL
, SELIND_LN0_TX
), 0x19,
98 { UIC_ARG_MIB_SEL(RX_CFGCLKFREQVAL
, SELIND_LN0_RX
), 0x19,
100 { UIC_ARG_MIB_SEL(CFGEXTRATTR
, SELIND_LN0_TX
), 0x12,
102 { UIC_ARG_MIB_SEL(DITHERCTRL2
, SELIND_LN0_TX
), 0xd6,
104 { UIC_ARG_MIB_SEL(RX_REFCLKFREQ
, SELIND_LN0_RX
), 0x01,
106 { UIC_ARG_MIB_SEL(CFGWIDEINLN
, SELIND_LN0_RX
), 2,
108 { UIC_ARG_MIB_SEL(CFGRXCDR8
, SELIND_LN0_RX
), 0x80,
110 { UIC_ARG_MIB(DIRECTCTRL10
), 0x04, DME_LOCAL
},
111 { UIC_ARG_MIB(DIRECTCTRL19
), 0x02, DME_LOCAL
},
112 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG4
, SELIND_LN0_RX
), 0x03,
114 { UIC_ARG_MIB_SEL(CFGRXOVR8
, SELIND_LN0_RX
), 0x16,
116 { UIC_ARG_MIB_SEL(RXDIRECTCTRL2
, SELIND_LN0_RX
), 0x42,
118 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG3
, SELIND_LN0_RX
), 0xa4,
120 { UIC_ARG_MIB_SEL(RXCALCTRL
, SELIND_LN0_RX
), 0x01,
122 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG2
, SELIND_LN0_RX
), 0x01,
124 { UIC_ARG_MIB_SEL(CFGRXOVR4
, SELIND_LN0_RX
), 0x28,
126 { UIC_ARG_MIB_SEL(RXSQCTRL
, SELIND_LN0_RX
), 0x1E,
128 { UIC_ARG_MIB_SEL(CFGRXOVR6
, SELIND_LN0_RX
), 0x2f,
130 { UIC_ARG_MIB(CBPRGPLL2
), 0x00, DME_LOCAL
},
133 return ufshcd_dwc_dme_set_attrs(hba
, setup_attrs
,
134 ARRAY_SIZE(setup_attrs
));
138 * tc_dwc_g210_setup_20bit_rmmi_lane1()
139 * This function configures Synopsys TC 20-bit RMMI Lane 1
140 * @hba: Pointer to drivers structure
142 * Returns 0 on success or non-zero value on failure
144 static int tc_dwc_g210_setup_20bit_rmmi_lane1(struct ufs_hba
*hba
)
146 int connected_rx_lanes
= 0;
147 int connected_tx_lanes
= 0;
150 static const struct ufshcd_dme_attr_val setup_tx_attrs
[] = {
151 { UIC_ARG_MIB_SEL(TX_REFCLKFREQ
, SELIND_LN1_TX
), 0x0d,
153 { UIC_ARG_MIB_SEL(TX_CFGCLKFREQVAL
, SELIND_LN1_TX
), 0x19,
155 { UIC_ARG_MIB_SEL(CFGEXTRATTR
, SELIND_LN1_TX
), 0x12,
157 { UIC_ARG_MIB_SEL(DITHERCTRL2
, SELIND_LN0_TX
), 0xd6,
161 static const struct ufshcd_dme_attr_val setup_rx_attrs
[] = {
162 { UIC_ARG_MIB_SEL(RX_REFCLKFREQ
, SELIND_LN1_RX
), 0x01,
164 { UIC_ARG_MIB_SEL(RX_CFGCLKFREQVAL
, SELIND_LN1_RX
), 0x19,
166 { UIC_ARG_MIB_SEL(CFGWIDEINLN
, SELIND_LN1_RX
), 2,
168 { UIC_ARG_MIB_SEL(CFGRXCDR8
, SELIND_LN1_RX
), 0x80,
170 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG4
, SELIND_LN1_RX
), 0x03,
172 { UIC_ARG_MIB_SEL(CFGRXOVR8
, SELIND_LN1_RX
), 0x16,
174 { UIC_ARG_MIB_SEL(RXDIRECTCTRL2
, SELIND_LN1_RX
), 0x42,
176 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG3
, SELIND_LN1_RX
), 0xa4,
178 { UIC_ARG_MIB_SEL(RXCALCTRL
, SELIND_LN1_RX
), 0x01,
180 { UIC_ARG_MIB_SEL(ENARXDIRECTCFG2
, SELIND_LN1_RX
), 0x01,
182 { UIC_ARG_MIB_SEL(CFGRXOVR4
, SELIND_LN1_RX
), 0x28,
184 { UIC_ARG_MIB_SEL(RXSQCTRL
, SELIND_LN1_RX
), 0x1E,
186 { UIC_ARG_MIB_SEL(CFGRXOVR6
, SELIND_LN1_RX
), 0x2f,
190 /* Get the available lane count */
191 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_AVAILRXDATALANES
),
192 &connected_rx_lanes
);
193 ufshcd_dme_get(hba
, UIC_ARG_MIB(PA_AVAILTXDATALANES
),
194 &connected_tx_lanes
);
196 if (connected_tx_lanes
== 2) {
198 ret
= ufshcd_dwc_dme_set_attrs(hba
, setup_tx_attrs
,
199 ARRAY_SIZE(setup_tx_attrs
));
205 if (connected_rx_lanes
== 2) {
206 ret
= ufshcd_dwc_dme_set_attrs(hba
, setup_rx_attrs
,
207 ARRAY_SIZE(setup_rx_attrs
));
215 * tc_dwc_g210_setup_20bit_rmmi()
216 * This function configures Synopsys TC specific atributes (20-bit RMMI)
217 * @hba: Pointer to drivers structure
219 * Returns 0 on success or non-zero value on failure
221 static int tc_dwc_g210_setup_20bit_rmmi(struct ufs_hba
*hba
)
225 static const struct ufshcd_dme_attr_val setup_attrs
[] = {
226 { UIC_ARG_MIB(TX_GLOBALHIBERNATE
), 0x00, DME_LOCAL
},
227 { UIC_ARG_MIB(REFCLKMODE
), 0x01, DME_LOCAL
},
228 { UIC_ARG_MIB(CDIRECTCTRL6
), 0xc0, DME_LOCAL
},
229 { UIC_ARG_MIB(CBDIVFACTOR
), 0x44, DME_LOCAL
},
230 { UIC_ARG_MIB(CBDCOCTRL5
), 0x64, DME_LOCAL
},
231 { UIC_ARG_MIB(CBPRGTUNING
), 0x09, DME_LOCAL
},
232 { UIC_ARG_MIB(RTOBSERVESELECT
), 0x00, DME_LOCAL
},
235 ret
= ufshcd_dwc_dme_set_attrs(hba
, setup_attrs
,
236 ARRAY_SIZE(setup_attrs
));
240 /* Lane 0 configuration*/
241 ret
= tc_dwc_g210_setup_20bit_rmmi_lane0(hba
);
245 /* Lane 1 configuration*/
246 ret
= tc_dwc_g210_setup_20bit_rmmi_lane1(hba
);
255 * tc_dwc_g210_config_40_bit()
256 * This function configures Local (host) Synopsys 40-bit TC specific attributes
258 * @hba: Pointer to drivers structure
260 * Returns 0 on success non-zero value on failure
262 int tc_dwc_g210_config_40_bit(struct ufs_hba
*hba
)
266 dev_info(hba
->dev
, "Configuring Test Chip 40-bit RMMI\n");
267 ret
= tc_dwc_g210_setup_40bit_rmmi(hba
);
269 dev_err(hba
->dev
, "Configuration failed\n");
273 /* To write Shadow register bank to effective configuration block */
274 ret
= ufshcd_dme_set(hba
, UIC_ARG_MIB(VS_MPHYCFGUPDT
), 0x01);
278 /* To configure Debug OMC */
279 ret
= ufshcd_dme_set(hba
, UIC_ARG_MIB(VS_DEBUGOMC
), 0x01);
284 EXPORT_SYMBOL(tc_dwc_g210_config_40_bit
);
287 * tc_dwc_g210_config_20_bit()
288 * This function configures Local (host) Synopsys 20-bit TC specific attributes
290 * @hba: Pointer to drivers structure
292 * Returns 0 on success non-zero value on failure
294 int tc_dwc_g210_config_20_bit(struct ufs_hba
*hba
)
298 dev_info(hba
->dev
, "Configuring Test Chip 20-bit RMMI\n");
299 ret
= tc_dwc_g210_setup_20bit_rmmi(hba
);
301 dev_err(hba
->dev
, "Configuration failed\n");
305 /* To write Shadow register bank to effective configuration block */
306 ret
= ufshcd_dme_set(hba
, UIC_ARG_MIB(VS_MPHYCFGUPDT
), 0x01);
310 /* To configure Debug OMC */
311 ret
= ufshcd_dme_set(hba
, UIC_ARG_MIB(VS_DEBUGOMC
), 0x01);
316 EXPORT_SYMBOL(tc_dwc_g210_config_20_bit
);
318 MODULE_AUTHOR("Joao Pinto <Joao.Pinto@synopsys.com>");
319 MODULE_DESCRIPTION("Synopsys G210 Test Chip driver");
320 MODULE_LICENSE("Dual BSD/GPL");