blob: a149d92df6561acd15470a76aa83f84ec12e4bf3 [file] [log] [blame]
Yaniv Gardiadaafaa2015-01-15 16:32:35 +02001/*
2 * Copyright (c) 2013-2015, Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 */
14
15#include "phy-qcom-ufs-i.h"
16
17#define MAX_PROP_NAME 32
18#define VDDA_PHY_MIN_UV 1000000
19#define VDDA_PHY_MAX_UV 1000000
20#define VDDA_PLL_MIN_UV 1800000
21#define VDDA_PLL_MAX_UV 1800000
22#define VDDP_REF_CLK_MIN_UV 1200000
23#define VDDP_REF_CLK_MAX_UV 1200000
24
25static int __ufs_qcom_phy_init_vreg(struct phy *, struct ufs_qcom_phy_vreg *,
26 const char *, bool);
27static int ufs_qcom_phy_init_vreg(struct phy *, struct ufs_qcom_phy_vreg *,
28 const char *);
29static int ufs_qcom_phy_base_init(struct platform_device *pdev,
30 struct ufs_qcom_phy *phy_common);
31
32int ufs_qcom_phy_calibrate(struct ufs_qcom_phy *ufs_qcom_phy,
33 struct ufs_qcom_phy_calibration *tbl_A,
34 int tbl_size_A,
35 struct ufs_qcom_phy_calibration *tbl_B,
36 int tbl_size_B, bool is_rate_B)
37{
38 int i;
39 int ret = 0;
40
41 if (!tbl_A) {
42 dev_err(ufs_qcom_phy->dev, "%s: tbl_A is NULL", __func__);
43 ret = EINVAL;
44 goto out;
45 }
46
47 for (i = 0; i < tbl_size_A; i++)
48 writel_relaxed(tbl_A[i].cfg_value,
49 ufs_qcom_phy->mmio + tbl_A[i].reg_offset);
50
51 /*
52 * In case we would like to work in rate B, we need
53 * to override a registers that were configured in rate A table
54 * with registers of rate B table.
55 * table.
56 */
57 if (is_rate_B) {
58 if (!tbl_B) {
59 dev_err(ufs_qcom_phy->dev, "%s: tbl_B is NULL",
60 __func__);
61 ret = EINVAL;
62 goto out;
63 }
64
65 for (i = 0; i < tbl_size_B; i++)
66 writel_relaxed(tbl_B[i].cfg_value,
67 ufs_qcom_phy->mmio + tbl_B[i].reg_offset);
68 }
69
70 /* flush buffered writes */
71 mb();
72
73out:
74 return ret;
75}
Axel Lin358d6c82015-03-23 11:54:50 +080076EXPORT_SYMBOL_GPL(ufs_qcom_phy_calibrate);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +020077
78struct phy *ufs_qcom_phy_generic_probe(struct platform_device *pdev,
79 struct ufs_qcom_phy *common_cfg,
80 struct phy_ops *ufs_qcom_phy_gen_ops,
81 struct ufs_qcom_phy_specific_ops *phy_spec_ops)
82{
83 int err;
84 struct device *dev = &pdev->dev;
85 struct phy *generic_phy = NULL;
86 struct phy_provider *phy_provider;
87
88 err = ufs_qcom_phy_base_init(pdev, common_cfg);
89 if (err) {
90 dev_err(dev, "%s: phy base init failed %d\n", __func__, err);
91 goto out;
92 }
93
94 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
95 if (IS_ERR(phy_provider)) {
96 err = PTR_ERR(phy_provider);
97 dev_err(dev, "%s: failed to register phy %d\n", __func__, err);
98 goto out;
99 }
100
101 generic_phy = devm_phy_create(dev, NULL, ufs_qcom_phy_gen_ops);
102 if (IS_ERR(generic_phy)) {
103 err = PTR_ERR(generic_phy);
104 dev_err(dev, "%s: failed to create phy %d\n", __func__, err);
Axel Lind89a7f62015-03-03 09:05:55 +0800105 generic_phy = NULL;
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200106 goto out;
107 }
108
109 common_cfg->phy_spec_ops = phy_spec_ops;
110 common_cfg->dev = dev;
111
112out:
113 return generic_phy;
114}
Axel Lin358d6c82015-03-23 11:54:50 +0800115EXPORT_SYMBOL_GPL(ufs_qcom_phy_generic_probe);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200116
117/*
118 * This assumes the embedded phy structure inside generic_phy is of type
119 * struct ufs_qcom_phy. In order to function properly it's crucial
120 * to keep the embedded struct "struct ufs_qcom_phy common_cfg"
121 * as the first inside generic_phy.
122 */
123struct ufs_qcom_phy *get_ufs_qcom_phy(struct phy *generic_phy)
124{
125 return (struct ufs_qcom_phy *)phy_get_drvdata(generic_phy);
126}
Axel Lin358d6c82015-03-23 11:54:50 +0800127EXPORT_SYMBOL_GPL(get_ufs_qcom_phy);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200128
129static
130int ufs_qcom_phy_base_init(struct platform_device *pdev,
131 struct ufs_qcom_phy *phy_common)
132{
133 struct device *dev = &pdev->dev;
134 struct resource *res;
135 int err = 0;
136
137 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_mem");
138 if (!res) {
139 dev_err(dev, "%s: phy_mem resource not found\n", __func__);
140 err = -ENOMEM;
141 goto out;
142 }
143
144 phy_common->mmio = devm_ioremap_resource(dev, res);
145 if (IS_ERR((void const *)phy_common->mmio)) {
146 err = PTR_ERR((void const *)phy_common->mmio);
147 phy_common->mmio = NULL;
148 dev_err(dev, "%s: ioremap for phy_mem resource failed %d\n",
149 __func__, err);
150 goto out;
151 }
152
153 /* "dev_ref_clk_ctrl_mem" is optional resource */
154 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
155 "dev_ref_clk_ctrl_mem");
156 if (!res) {
157 dev_dbg(dev, "%s: dev_ref_clk_ctrl_mem resource not found\n",
158 __func__);
159 goto out;
160 }
161
162 phy_common->dev_ref_clk_ctrl_mmio = devm_ioremap_resource(dev, res);
163 if (IS_ERR((void const *)phy_common->dev_ref_clk_ctrl_mmio)) {
164 err = PTR_ERR((void const *)phy_common->dev_ref_clk_ctrl_mmio);
165 phy_common->dev_ref_clk_ctrl_mmio = NULL;
166 dev_err(dev, "%s: ioremap for dev_ref_clk_ctrl_mem resource failed %d\n",
167 __func__, err);
168 }
169
170out:
171 return err;
172}
173
174static int __ufs_qcom_phy_clk_get(struct phy *phy,
175 const char *name, struct clk **clk_out, bool err_print)
176{
177 struct clk *clk;
178 int err = 0;
179 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(phy);
180 struct device *dev = ufs_qcom_phy->dev;
181
182 clk = devm_clk_get(dev, name);
183 if (IS_ERR(clk)) {
184 err = PTR_ERR(clk);
185 if (err_print)
186 dev_err(dev, "failed to get %s err %d", name, err);
187 } else {
188 *clk_out = clk;
189 }
190
191 return err;
192}
193
194static
195int ufs_qcom_phy_clk_get(struct phy *phy,
196 const char *name, struct clk **clk_out)
197{
198 return __ufs_qcom_phy_clk_get(phy, name, clk_out, true);
199}
200
201int
202ufs_qcom_phy_init_clks(struct phy *generic_phy,
203 struct ufs_qcom_phy *phy_common)
204{
205 int err;
206
207 err = ufs_qcom_phy_clk_get(generic_phy, "tx_iface_clk",
208 &phy_common->tx_iface_clk);
209 if (err)
210 goto out;
211
212 err = ufs_qcom_phy_clk_get(generic_phy, "rx_iface_clk",
213 &phy_common->rx_iface_clk);
214 if (err)
215 goto out;
216
217 err = ufs_qcom_phy_clk_get(generic_phy, "ref_clk_src",
218 &phy_common->ref_clk_src);
219 if (err)
220 goto out;
221
222 /*
223 * "ref_clk_parent" is optional hence don't abort init if it's not
224 * found.
225 */
226 __ufs_qcom_phy_clk_get(generic_phy, "ref_clk_parent",
227 &phy_common->ref_clk_parent, false);
228
229 err = ufs_qcom_phy_clk_get(generic_phy, "ref_clk",
230 &phy_common->ref_clk);
231
232out:
233 return err;
234}
Axel Lin358d6c82015-03-23 11:54:50 +0800235EXPORT_SYMBOL_GPL(ufs_qcom_phy_init_clks);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200236
237int
238ufs_qcom_phy_init_vregulators(struct phy *generic_phy,
239 struct ufs_qcom_phy *phy_common)
240{
241 int err;
242
243 err = ufs_qcom_phy_init_vreg(generic_phy, &phy_common->vdda_pll,
244 "vdda-pll");
245 if (err)
246 goto out;
247
248 err = ufs_qcom_phy_init_vreg(generic_phy, &phy_common->vdda_phy,
249 "vdda-phy");
250
251 if (err)
252 goto out;
253
254 /* vddp-ref-clk-* properties are optional */
255 __ufs_qcom_phy_init_vreg(generic_phy, &phy_common->vddp_ref_clk,
256 "vddp-ref-clk", true);
257out:
258 return err;
259}
Axel Lin358d6c82015-03-23 11:54:50 +0800260EXPORT_SYMBOL_GPL(ufs_qcom_phy_init_vregulators);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200261
262static int __ufs_qcom_phy_init_vreg(struct phy *phy,
263 struct ufs_qcom_phy_vreg *vreg, const char *name, bool optional)
264{
265 int err = 0;
266 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(phy);
267 struct device *dev = ufs_qcom_phy->dev;
268
269 char prop_name[MAX_PROP_NAME];
270
271 vreg->name = kstrdup(name, GFP_KERNEL);
272 if (!vreg->name) {
273 err = -ENOMEM;
274 goto out;
275 }
276
277 vreg->reg = devm_regulator_get(dev, name);
278 if (IS_ERR(vreg->reg)) {
279 err = PTR_ERR(vreg->reg);
280 vreg->reg = NULL;
281 if (!optional)
282 dev_err(dev, "failed to get %s, %d\n", name, err);
283 goto out;
284 }
285
286 if (dev->of_node) {
287 snprintf(prop_name, MAX_PROP_NAME, "%s-max-microamp", name);
288 err = of_property_read_u32(dev->of_node,
289 prop_name, &vreg->max_uA);
290 if (err && err != -EINVAL) {
291 dev_err(dev, "%s: failed to read %s\n",
292 __func__, prop_name);
293 goto out;
294 } else if (err == -EINVAL || !vreg->max_uA) {
295 if (regulator_count_voltages(vreg->reg) > 0) {
296 dev_err(dev, "%s: %s is mandatory\n",
297 __func__, prop_name);
298 goto out;
299 }
300 err = 0;
301 }
302 snprintf(prop_name, MAX_PROP_NAME, "%s-always-on", name);
303 if (of_get_property(dev->of_node, prop_name, NULL))
304 vreg->is_always_on = true;
305 else
306 vreg->is_always_on = false;
307 }
308
309 if (!strcmp(name, "vdda-pll")) {
310 vreg->max_uV = VDDA_PLL_MAX_UV;
311 vreg->min_uV = VDDA_PLL_MIN_UV;
312 } else if (!strcmp(name, "vdda-phy")) {
313 vreg->max_uV = VDDA_PHY_MAX_UV;
314 vreg->min_uV = VDDA_PHY_MIN_UV;
315 } else if (!strcmp(name, "vddp-ref-clk")) {
316 vreg->max_uV = VDDP_REF_CLK_MAX_UV;
317 vreg->min_uV = VDDP_REF_CLK_MIN_UV;
318 }
319
320out:
321 if (err)
322 kfree(vreg->name);
323 return err;
324}
325
326static int ufs_qcom_phy_init_vreg(struct phy *phy,
327 struct ufs_qcom_phy_vreg *vreg, const char *name)
328{
329 return __ufs_qcom_phy_init_vreg(phy, vreg, name, false);
330}
331
332static
333int ufs_qcom_phy_cfg_vreg(struct phy *phy,
334 struct ufs_qcom_phy_vreg *vreg, bool on)
335{
336 int ret = 0;
337 struct regulator *reg = vreg->reg;
338 const char *name = vreg->name;
339 int min_uV;
340 int uA_load;
341 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(phy);
342 struct device *dev = ufs_qcom_phy->dev;
343
344 BUG_ON(!vreg);
345
346 if (regulator_count_voltages(reg) > 0) {
347 min_uV = on ? vreg->min_uV : 0;
348 ret = regulator_set_voltage(reg, min_uV, vreg->max_uV);
349 if (ret) {
350 dev_err(dev, "%s: %s set voltage failed, err=%d\n",
351 __func__, name, ret);
352 goto out;
353 }
354 uA_load = on ? vreg->max_uA : 0;
355 ret = regulator_set_optimum_mode(reg, uA_load);
356 if (ret >= 0) {
357 /*
358 * regulator_set_optimum_mode() returns new regulator
359 * mode upon success.
360 */
361 ret = 0;
362 } else {
363 dev_err(dev, "%s: %s set optimum mode(uA_load=%d) failed, err=%d\n",
364 __func__, name, uA_load, ret);
365 goto out;
366 }
367 }
368out:
369 return ret;
370}
371
372static
373int ufs_qcom_phy_enable_vreg(struct phy *phy,
374 struct ufs_qcom_phy_vreg *vreg)
375{
376 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(phy);
377 struct device *dev = ufs_qcom_phy->dev;
378 int ret = 0;
379
380 if (!vreg || vreg->enabled)
381 goto out;
382
383 ret = ufs_qcom_phy_cfg_vreg(phy, vreg, true);
384 if (ret) {
385 dev_err(dev, "%s: ufs_qcom_phy_cfg_vreg() failed, err=%d\n",
386 __func__, ret);
387 goto out;
388 }
389
390 ret = regulator_enable(vreg->reg);
391 if (ret) {
392 dev_err(dev, "%s: enable failed, err=%d\n",
393 __func__, ret);
394 goto out;
395 }
396
397 vreg->enabled = true;
398out:
399 return ret;
400}
401
402int ufs_qcom_phy_enable_ref_clk(struct phy *generic_phy)
403{
404 int ret = 0;
405 struct ufs_qcom_phy *phy = get_ufs_qcom_phy(generic_phy);
406
407 if (phy->is_ref_clk_enabled)
408 goto out;
409
410 /*
411 * reference clock is propagated in a daisy-chained manner from
412 * source to phy, so ungate them at each stage.
413 */
414 ret = clk_prepare_enable(phy->ref_clk_src);
415 if (ret) {
416 dev_err(phy->dev, "%s: ref_clk_src enable failed %d\n",
417 __func__, ret);
418 goto out;
419 }
420
421 /*
422 * "ref_clk_parent" is optional clock hence make sure that clk reference
423 * is available before trying to enable the clock.
424 */
425 if (phy->ref_clk_parent) {
426 ret = clk_prepare_enable(phy->ref_clk_parent);
427 if (ret) {
428 dev_err(phy->dev, "%s: ref_clk_parent enable failed %d\n",
429 __func__, ret);
430 goto out_disable_src;
431 }
432 }
433
434 ret = clk_prepare_enable(phy->ref_clk);
435 if (ret) {
436 dev_err(phy->dev, "%s: ref_clk enable failed %d\n",
437 __func__, ret);
438 goto out_disable_parent;
439 }
440
441 phy->is_ref_clk_enabled = true;
442 goto out;
443
444out_disable_parent:
445 if (phy->ref_clk_parent)
446 clk_disable_unprepare(phy->ref_clk_parent);
447out_disable_src:
448 clk_disable_unprepare(phy->ref_clk_src);
449out:
450 return ret;
451}
452
453static
454int ufs_qcom_phy_disable_vreg(struct phy *phy,
455 struct ufs_qcom_phy_vreg *vreg)
456{
457 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(phy);
458 struct device *dev = ufs_qcom_phy->dev;
459 int ret = 0;
460
461 if (!vreg || !vreg->enabled || vreg->is_always_on)
462 goto out;
463
464 ret = regulator_disable(vreg->reg);
465
466 if (!ret) {
467 /* ignore errors on applying disable config */
468 ufs_qcom_phy_cfg_vreg(phy, vreg, false);
469 vreg->enabled = false;
470 } else {
471 dev_err(dev, "%s: %s disable failed, err=%d\n",
472 __func__, vreg->name, ret);
473 }
474out:
475 return ret;
476}
477
478void ufs_qcom_phy_disable_ref_clk(struct phy *generic_phy)
479{
480 struct ufs_qcom_phy *phy = get_ufs_qcom_phy(generic_phy);
481
482 if (phy->is_ref_clk_enabled) {
483 clk_disable_unprepare(phy->ref_clk);
484 /*
485 * "ref_clk_parent" is optional clock hence make sure that clk
486 * reference is available before trying to disable the clock.
487 */
488 if (phy->ref_clk_parent)
489 clk_disable_unprepare(phy->ref_clk_parent);
490 clk_disable_unprepare(phy->ref_clk_src);
491 phy->is_ref_clk_enabled = false;
492 }
493}
494
495#define UFS_REF_CLK_EN (1 << 5)
496
497static void ufs_qcom_phy_dev_ref_clk_ctrl(struct phy *generic_phy, bool enable)
498{
499 struct ufs_qcom_phy *phy = get_ufs_qcom_phy(generic_phy);
500
501 if (phy->dev_ref_clk_ctrl_mmio &&
502 (enable ^ phy->is_dev_ref_clk_enabled)) {
503 u32 temp = readl_relaxed(phy->dev_ref_clk_ctrl_mmio);
504
505 if (enable)
506 temp |= UFS_REF_CLK_EN;
507 else
508 temp &= ~UFS_REF_CLK_EN;
509
510 /*
511 * If we are here to disable this clock immediately after
512 * entering into hibern8, we need to make sure that device
513 * ref_clk is active atleast 1us after the hibern8 enter.
514 */
515 if (!enable)
516 udelay(1);
517
518 writel_relaxed(temp, phy->dev_ref_clk_ctrl_mmio);
519 /* ensure that ref_clk is enabled/disabled before we return */
520 wmb();
521 /*
522 * If we call hibern8 exit after this, we need to make sure that
523 * device ref_clk is stable for atleast 1us before the hibern8
524 * exit command.
525 */
526 if (enable)
527 udelay(1);
528
529 phy->is_dev_ref_clk_enabled = enable;
530 }
531}
532
533void ufs_qcom_phy_enable_dev_ref_clk(struct phy *generic_phy)
534{
535 ufs_qcom_phy_dev_ref_clk_ctrl(generic_phy, true);
536}
537
538void ufs_qcom_phy_disable_dev_ref_clk(struct phy *generic_phy)
539{
540 ufs_qcom_phy_dev_ref_clk_ctrl(generic_phy, false);
541}
542
543/* Turn ON M-PHY RMMI interface clocks */
544int ufs_qcom_phy_enable_iface_clk(struct phy *generic_phy)
545{
546 struct ufs_qcom_phy *phy = get_ufs_qcom_phy(generic_phy);
547 int ret = 0;
548
549 if (phy->is_iface_clk_enabled)
550 goto out;
551
552 ret = clk_prepare_enable(phy->tx_iface_clk);
553 if (ret) {
554 dev_err(phy->dev, "%s: tx_iface_clk enable failed %d\n",
555 __func__, ret);
556 goto out;
557 }
558 ret = clk_prepare_enable(phy->rx_iface_clk);
559 if (ret) {
560 clk_disable_unprepare(phy->tx_iface_clk);
561 dev_err(phy->dev, "%s: rx_iface_clk enable failed %d. disabling also tx_iface_clk\n",
562 __func__, ret);
563 goto out;
564 }
565 phy->is_iface_clk_enabled = true;
566
567out:
568 return ret;
569}
570
571/* Turn OFF M-PHY RMMI interface clocks */
572void ufs_qcom_phy_disable_iface_clk(struct phy *generic_phy)
573{
574 struct ufs_qcom_phy *phy = get_ufs_qcom_phy(generic_phy);
575
576 if (phy->is_iface_clk_enabled) {
577 clk_disable_unprepare(phy->tx_iface_clk);
578 clk_disable_unprepare(phy->rx_iface_clk);
579 phy->is_iface_clk_enabled = false;
580 }
581}
582
583int ufs_qcom_phy_start_serdes(struct phy *generic_phy)
584{
585 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
586 int ret = 0;
587
588 if (!ufs_qcom_phy->phy_spec_ops->start_serdes) {
589 dev_err(ufs_qcom_phy->dev, "%s: start_serdes() callback is not supported\n",
590 __func__);
591 ret = -ENOTSUPP;
592 } else {
593 ufs_qcom_phy->phy_spec_ops->start_serdes(ufs_qcom_phy);
594 }
595
596 return ret;
597}
598
599int ufs_qcom_phy_set_tx_lane_enable(struct phy *generic_phy, u32 tx_lanes)
600{
601 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
602 int ret = 0;
603
604 if (!ufs_qcom_phy->phy_spec_ops->set_tx_lane_enable) {
605 dev_err(ufs_qcom_phy->dev, "%s: set_tx_lane_enable() callback is not supported\n",
606 __func__);
607 ret = -ENOTSUPP;
608 } else {
609 ufs_qcom_phy->phy_spec_ops->set_tx_lane_enable(ufs_qcom_phy,
610 tx_lanes);
611 }
612
613 return ret;
614}
615
616void ufs_qcom_phy_save_controller_version(struct phy *generic_phy,
617 u8 major, u16 minor, u16 step)
618{
619 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
620
621 ufs_qcom_phy->host_ctrl_rev_major = major;
622 ufs_qcom_phy->host_ctrl_rev_minor = minor;
623 ufs_qcom_phy->host_ctrl_rev_step = step;
624}
625
626int ufs_qcom_phy_calibrate_phy(struct phy *generic_phy, bool is_rate_B)
627{
628 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
629 int ret = 0;
630
631 if (!ufs_qcom_phy->phy_spec_ops->calibrate_phy) {
632 dev_err(ufs_qcom_phy->dev, "%s: calibrate_phy() callback is not supported\n",
633 __func__);
634 ret = -ENOTSUPP;
635 } else {
636 ret = ufs_qcom_phy->phy_spec_ops->
637 calibrate_phy(ufs_qcom_phy, is_rate_B);
638 if (ret)
639 dev_err(ufs_qcom_phy->dev, "%s: calibrate_phy() failed %d\n",
640 __func__, ret);
641 }
642
643 return ret;
644}
645
646int ufs_qcom_phy_remove(struct phy *generic_phy,
647 struct ufs_qcom_phy *ufs_qcom_phy)
648{
649 phy_power_off(generic_phy);
650
651 kfree(ufs_qcom_phy->vdda_pll.name);
652 kfree(ufs_qcom_phy->vdda_phy.name);
653
654 return 0;
655}
Axel Lin358d6c82015-03-23 11:54:50 +0800656EXPORT_SYMBOL_GPL(ufs_qcom_phy_remove);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200657
658int ufs_qcom_phy_exit(struct phy *generic_phy)
659{
660 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
661
662 if (ufs_qcom_phy->is_powered_on)
663 phy_power_off(generic_phy);
664
665 return 0;
666}
Axel Lin358d6c82015-03-23 11:54:50 +0800667EXPORT_SYMBOL_GPL(ufs_qcom_phy_exit);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200668
669int ufs_qcom_phy_is_pcs_ready(struct phy *generic_phy)
670{
671 struct ufs_qcom_phy *ufs_qcom_phy = get_ufs_qcom_phy(generic_phy);
672
673 if (!ufs_qcom_phy->phy_spec_ops->is_physical_coding_sublayer_ready) {
674 dev_err(ufs_qcom_phy->dev, "%s: is_physical_coding_sublayer_ready() callback is not supported\n",
675 __func__);
676 return -ENOTSUPP;
677 }
678
679 return ufs_qcom_phy->phy_spec_ops->
680 is_physical_coding_sublayer_ready(ufs_qcom_phy);
681}
682
683int ufs_qcom_phy_power_on(struct phy *generic_phy)
684{
685 struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);
686 struct device *dev = phy_common->dev;
687 int err;
688
689 err = ufs_qcom_phy_enable_vreg(generic_phy, &phy_common->vdda_phy);
690 if (err) {
691 dev_err(dev, "%s enable vdda_phy failed, err=%d\n",
692 __func__, err);
693 goto out;
694 }
695
696 phy_common->phy_spec_ops->power_control(phy_common, true);
697
698 /* vdda_pll also enables ref clock LDOs so enable it first */
699 err = ufs_qcom_phy_enable_vreg(generic_phy, &phy_common->vdda_pll);
700 if (err) {
701 dev_err(dev, "%s enable vdda_pll failed, err=%d\n",
702 __func__, err);
703 goto out_disable_phy;
704 }
705
706 err = ufs_qcom_phy_enable_ref_clk(generic_phy);
707 if (err) {
708 dev_err(dev, "%s enable phy ref clock failed, err=%d\n",
709 __func__, err);
710 goto out_disable_pll;
711 }
712
713 /* enable device PHY ref_clk pad rail */
714 if (phy_common->vddp_ref_clk.reg) {
715 err = ufs_qcom_phy_enable_vreg(generic_phy,
716 &phy_common->vddp_ref_clk);
717 if (err) {
718 dev_err(dev, "%s enable vddp_ref_clk failed, err=%d\n",
719 __func__, err);
720 goto out_disable_ref_clk;
721 }
722 }
723
724 phy_common->is_powered_on = true;
725 goto out;
726
727out_disable_ref_clk:
728 ufs_qcom_phy_disable_ref_clk(generic_phy);
729out_disable_pll:
730 ufs_qcom_phy_disable_vreg(generic_phy, &phy_common->vdda_pll);
731out_disable_phy:
732 ufs_qcom_phy_disable_vreg(generic_phy, &phy_common->vdda_phy);
733out:
734 return err;
735}
Axel Lin358d6c82015-03-23 11:54:50 +0800736EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_on);
Yaniv Gardiadaafaa2015-01-15 16:32:35 +0200737
738int ufs_qcom_phy_power_off(struct phy *generic_phy)
739{
740 struct ufs_qcom_phy *phy_common = get_ufs_qcom_phy(generic_phy);
741
742 phy_common->phy_spec_ops->power_control(phy_common, false);
743
744 if (phy_common->vddp_ref_clk.reg)
745 ufs_qcom_phy_disable_vreg(generic_phy,
746 &phy_common->vddp_ref_clk);
747 ufs_qcom_phy_disable_ref_clk(generic_phy);
748
749 ufs_qcom_phy_disable_vreg(generic_phy, &phy_common->vdda_pll);
750 ufs_qcom_phy_disable_vreg(generic_phy, &phy_common->vdda_phy);
751 phy_common->is_powered_on = false;
752
753 return 0;
754}
Axel Lin358d6c82015-03-23 11:54:50 +0800755EXPORT_SYMBOL_GPL(ufs_qcom_phy_power_off);