Rajesh Bharathwaj | dcc7af8 | 2019-12-15 22:42:55 -0800 | [diff] [blame] | 1 | /* 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 | |
| 24 | struct qcom_xr_smrtvwr { |
| 25 | struct device *dev; |
| 26 | }; |
| 27 | |
| 28 | |
| 29 | static 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; |
Rajesh Bharathwaj | dcc7af8 | 2019-12-15 22:42:55 -0800 | [diff] [blame] | 35 | int rgb_tck_oe_en_gpio = 108; |
| 36 | |
| 37 | reg1 = devm_regulator_get(&pdev->dev, "pm660l_l6"); |
| 38 | if (!IS_ERR(reg1)) { |
| 39 | regulator_set_load(reg1, 600000); |
| 40 | rc = regulator_enable(reg1); |
| 41 | if (rc < 0) { |
| 42 | pr_err("%s pm660l_l6 failed\n", __func__); |
| 43 | goto reg1_fail; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | reg2 = devm_regulator_get(&pdev->dev, "pm660_l6"); |
| 48 | if (!IS_ERR(reg2)) { |
| 49 | regulator_set_load(reg2, 600000); |
| 50 | rc = regulator_enable(reg2); |
| 51 | if (rc < 0) { |
| 52 | pr_err("%s pm660_l6 failed\n", __func__); |
| 53 | goto reg2_fail; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | reg3 = devm_regulator_get(&pdev->dev, "pm660_l7"); |
| 58 | if (!IS_ERR(reg3)) { |
| 59 | regulator_set_load(reg3, 600000); |
| 60 | rc = regulator_enable(reg3); |
| 61 | if (rc < 0) { |
| 62 | pr_err("%s pm660_l7 failed\n", __func__); |
| 63 | goto reg3_fail; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | rc = gpio_request(dp3p3_en_gpio, "ti-dp-3v3-en-gpio"); |
| 68 | if (rc) { |
| 69 | pr_err("%s dp3p3_en gpio request failed\n", __func__); |
| 70 | goto gpio3p3_fail; |
| 71 | } |
| 72 | rc = gpio_direction_output(dp3p3_en_gpio, 0); |
| 73 | if (rc) { |
| 74 | pr_err("%s dp3p3_en_gpio direction failed\n", __func__); |
| 75 | goto gpio3p3_fail; |
| 76 | } |
| 77 | gpio_set_value(dp3p3_en_gpio, 1); |
| 78 | msleep(20); |
| 79 | |
| 80 | rc = gpio_request(wcd_en_gpio, "wcd9340_en_gpio"); |
| 81 | if (rc) { |
| 82 | pr_err("%s wcd9340_en_gpio request failed\n", __func__); |
| 83 | goto gpiowcd_fail; |
| 84 | } |
| 85 | rc = gpio_direction_output(wcd_en_gpio, 0); |
| 86 | if (rc) { |
| 87 | pr_err("%s wcd9340_en_gpio direction failed\n", __func__); |
| 88 | goto gpiowcd_fail; |
| 89 | } |
| 90 | gpio_set_value(wcd_en_gpio, 1); |
| 91 | msleep(20); |
| 92 | |
Rajesh Bharathwaj | dcc7af8 | 2019-12-15 22:42:55 -0800 | [diff] [blame] | 93 | rc = gpio_request(rgb_tck_oe_en_gpio, "rgb_tck_oe_en_gpio"); |
| 94 | if (rc) { |
| 95 | pr_err("%s rgb_tck_oe_en_gpio request failed\n", __func__); |
| 96 | goto gpio_oe_en_fail; |
| 97 | } |
| 98 | rc = gpio_direction_output(rgb_tck_oe_en_gpio, 0); |
| 99 | if (rc) { |
| 100 | pr_err("%s rgb_tck_oe_en_gpio direction failed\n", __func__); |
| 101 | goto gpio_oe_en_fail; |
| 102 | } |
| 103 | gpio_set_value(rgb_tck_oe_en_gpio, 0); |
| 104 | msleep(20); |
| 105 | |
| 106 | pr_debug("%s success\n", __func__); |
| 107 | return 0; |
| 108 | |
| 109 | gpio_oe_en_fail: |
| 110 | gpio_free(rgb_tck_oe_en_gpio); |
Rajesh Bharathwaj | dcc7af8 | 2019-12-15 22:42:55 -0800 | [diff] [blame] | 111 | gpiowcd_fail: |
| 112 | gpio_free(wcd_en_gpio); |
| 113 | gpio3p3_fail: |
| 114 | gpio_free(dp3p3_en_gpio); |
| 115 | reg3_fail: |
| 116 | devm_regulator_put(reg3); |
| 117 | reg2_fail: |
| 118 | devm_regulator_put(reg2); |
| 119 | reg1_fail: |
| 120 | devm_regulator_put(reg1); |
| 121 | |
| 122 | return rc; |
| 123 | } |
| 124 | |
| 125 | static const struct of_device_id qcom_xr_smrtvwr_match_table[] = { |
| 126 | { .compatible = "qcom,xr-smrtvwr-misc", }, |
| 127 | {} |
| 128 | }; |
| 129 | |
| 130 | MODULE_DEVICE_TABLE(of, qcom_xr_smrtvwr_match_table); |
| 131 | |
| 132 | static struct platform_driver qcom_xr_smrtvwr_driver = { |
| 133 | .driver = { |
| 134 | .name = "qcom-xr-smrtvwr-misc", |
| 135 | .of_match_table = qcom_xr_smrtvwr_match_table, |
| 136 | }, |
| 137 | .probe = qcom_xr_smrtvwr_probe, |
| 138 | }; |
| 139 | |
| 140 | module_platform_driver(qcom_xr_smrtvwr_driver); |
| 141 | |
| 142 | MODULE_DESCRIPTION("QTI XR SMRTVWR MISC driver"); |
| 143 | MODULE_LICENSE("GPL v2"); |