blob: fc8796fbea90ec8664a524c70f9b3c586d85dc7e [file] [log] [blame]
Rajesh Bharathwajdcc7af82019-12-15 22:42:55 -08001/* Copyright (c) 2020, 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
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <linux/slab.h>
16#include <linux/of.h>
17#include <linux/of_gpio.h>
18#include <linux/regmap.h>
19#include <linux/of_device.h>
20#include <linux/platform_device.h>
21#include <linux/regulator/consumer.h>
22#include <dt-bindings/regulator/qcom,rpmh-regulator.h>
23
24struct qcom_xr_smrtvwr {
25 struct device *dev;
26};
27
28
29static int qcom_xr_smrtvwr_probe(struct platform_device *pdev)
30{
31 int rc;
32 struct regulator *reg1, *reg2, *reg3;
33 int dp3p3_en_gpio = 142;
34 int wcd_en_gpio = 93;
35 int switch_gpio = 112;
36 int rgb_tck_oe_en_gpio = 108;
37
38 reg1 = devm_regulator_get(&pdev->dev, "pm660l_l6");
39 if (!IS_ERR(reg1)) {
40 regulator_set_load(reg1, 600000);
41 rc = regulator_enable(reg1);
42 if (rc < 0) {
43 pr_err("%s pm660l_l6 failed\n", __func__);
44 goto reg1_fail;
45 }
46 }
47
48 reg2 = devm_regulator_get(&pdev->dev, "pm660_l6");
49 if (!IS_ERR(reg2)) {
50 regulator_set_load(reg2, 600000);
51 rc = regulator_enable(reg2);
52 if (rc < 0) {
53 pr_err("%s pm660_l6 failed\n", __func__);
54 goto reg2_fail;
55 }
56 }
57
58 reg3 = devm_regulator_get(&pdev->dev, "pm660_l7");
59 if (!IS_ERR(reg3)) {
60 regulator_set_load(reg3, 600000);
61 rc = regulator_enable(reg3);
62 if (rc < 0) {
63 pr_err("%s pm660_l7 failed\n", __func__);
64 goto reg3_fail;
65 }
66 }
67
68 rc = gpio_request(dp3p3_en_gpio, "ti-dp-3v3-en-gpio");
69 if (rc) {
70 pr_err("%s dp3p3_en gpio request failed\n", __func__);
71 goto gpio3p3_fail;
72 }
73 rc = gpio_direction_output(dp3p3_en_gpio, 0);
74 if (rc) {
75 pr_err("%s dp3p3_en_gpio direction failed\n", __func__);
76 goto gpio3p3_fail;
77 }
78 gpio_set_value(dp3p3_en_gpio, 1);
79 msleep(20);
80
81 rc = gpio_request(wcd_en_gpio, "wcd9340_en_gpio");
82 if (rc) {
83 pr_err("%s wcd9340_en_gpio request failed\n", __func__);
84 goto gpiowcd_fail;
85 }
86 rc = gpio_direction_output(wcd_en_gpio, 0);
87 if (rc) {
88 pr_err("%s wcd9340_en_gpio direction failed\n", __func__);
89 goto gpiowcd_fail;
90 }
91 gpio_set_value(wcd_en_gpio, 1);
92 msleep(20);
93
94 rc = gpio_request(switch_gpio, "1p8_en_gpio");
95 if (rc) {
96 pr_err("%s 1p8_switch_gpio request failed\n", __func__);
97 goto gpio_switch_fail;
98 }
99 rc = gpio_direction_output(switch_gpio, 0);
100 if (rc) {
101 pr_err("%s 1p8_switch_gpio direction failed\n", __func__);
102 goto gpio_switch_fail;
103 }
104 gpio_set_value(switch_gpio, 1);
105 msleep(20);
106
107 rc = gpio_request(rgb_tck_oe_en_gpio, "rgb_tck_oe_en_gpio");
108 if (rc) {
109 pr_err("%s rgb_tck_oe_en_gpio request failed\n", __func__);
110 goto gpio_oe_en_fail;
111 }
112 rc = gpio_direction_output(rgb_tck_oe_en_gpio, 0);
113 if (rc) {
114 pr_err("%s rgb_tck_oe_en_gpio direction failed\n", __func__);
115 goto gpio_oe_en_fail;
116 }
117 gpio_set_value(rgb_tck_oe_en_gpio, 0);
118 msleep(20);
119
120 pr_debug("%s success\n", __func__);
121 return 0;
122
123gpio_oe_en_fail:
124 gpio_free(rgb_tck_oe_en_gpio);
125gpio_switch_fail:
126 gpio_free(switch_gpio);
127gpiowcd_fail:
128 gpio_free(wcd_en_gpio);
129gpio3p3_fail:
130 gpio_free(dp3p3_en_gpio);
131reg3_fail:
132 devm_regulator_put(reg3);
133reg2_fail:
134 devm_regulator_put(reg2);
135reg1_fail:
136 devm_regulator_put(reg1);
137
138 return rc;
139}
140
141static const struct of_device_id qcom_xr_smrtvwr_match_table[] = {
142 { .compatible = "qcom,xr-smrtvwr-misc", },
143 {}
144};
145
146MODULE_DEVICE_TABLE(of, qcom_xr_smrtvwr_match_table);
147
148static struct platform_driver qcom_xr_smrtvwr_driver = {
149 .driver = {
150 .name = "qcom-xr-smrtvwr-misc",
151 .of_match_table = qcom_xr_smrtvwr_match_table,
152 },
153 .probe = qcom_xr_smrtvwr_probe,
154};
155
156module_platform_driver(qcom_xr_smrtvwr_driver);
157
158MODULE_DESCRIPTION("QTI XR SMRTVWR MISC driver");
159MODULE_LICENSE("GPL v2");