mfd: as3722: Convert MFD_AS3722 from bool to tristate
[cascardo/linux.git] / drivers / mfd / qcom_rpm.c
index 2e44323..52fafea 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/mfd/qcom_rpm.h>
 #include <linux/mfd/syscon.h>
 #include <linux/regmap.h>
+#include <linux/clk.h>
 
 #include <dt-bindings/mfd/qcom-rpm.h>
 
@@ -48,6 +49,7 @@ struct qcom_rpm {
        struct regmap *ipc_regmap;
        unsigned ipc_offset;
        unsigned ipc_bit;
+       struct clk *ramclk;
 
        struct completion ack;
        struct mutex lock;
@@ -388,11 +390,62 @@ static const struct qcom_rpm_data ipq806x_template = {
        .ack_sel_size = 7,
 };
 
+static const struct qcom_rpm_resource mdm9615_rpm_resource_table[] = {
+       [QCOM_RPM_CXO_CLK] =                    { 25, 9, 5, 1 },
+       [QCOM_RPM_SYS_FABRIC_CLK] =             { 26, 10, 9, 1 },
+       [QCOM_RPM_DAYTONA_FABRIC_CLK] =         { 27, 11, 11, 1 },
+       [QCOM_RPM_SFPB_CLK] =                   { 28, 12, 12, 1 },
+       [QCOM_RPM_CFPB_CLK] =                   { 29, 13, 13, 1 },
+       [QCOM_RPM_EBI1_CLK] =                   { 30, 14, 16, 1 },
+       [QCOM_RPM_APPS_FABRIC_HALT] =           { 31, 15, 22, 2 },
+       [QCOM_RPM_APPS_FABRIC_MODE] =           { 33, 16, 23, 3 },
+       [QCOM_RPM_APPS_FABRIC_IOCTL] =          { 36, 17, 24, 1 },
+       [QCOM_RPM_APPS_FABRIC_ARB] =            { 37, 18, 25, 27 },
+       [QCOM_RPM_PM8018_SMPS1] =               { 64, 19, 30, 2 },
+       [QCOM_RPM_PM8018_SMPS2] =               { 66, 21, 31, 2 },
+       [QCOM_RPM_PM8018_SMPS3] =               { 68, 23, 32, 2 },
+       [QCOM_RPM_PM8018_SMPS4] =               { 70, 25, 33, 2 },
+       [QCOM_RPM_PM8018_SMPS5] =               { 72, 27, 34, 2 },
+       [QCOM_RPM_PM8018_LDO1] =                { 74, 29, 35, 2 },
+       [QCOM_RPM_PM8018_LDO2] =                { 76, 31, 36, 2 },
+       [QCOM_RPM_PM8018_LDO3] =                { 78, 33, 37, 2 },
+       [QCOM_RPM_PM8018_LDO4] =                { 80, 35, 38, 2 },
+       [QCOM_RPM_PM8018_LDO5] =                { 82, 37, 39, 2 },
+       [QCOM_RPM_PM8018_LDO6] =                { 84, 39, 40, 2 },
+       [QCOM_RPM_PM8018_LDO7] =                { 86, 41, 41, 2 },
+       [QCOM_RPM_PM8018_LDO8] =                { 88, 43, 42, 2 },
+       [QCOM_RPM_PM8018_LDO9] =                { 90, 45, 43, 2 },
+       [QCOM_RPM_PM8018_LDO10] =               { 92, 47, 44, 2 },
+       [QCOM_RPM_PM8018_LDO11] =               { 94, 49, 45, 2 },
+       [QCOM_RPM_PM8018_LDO12] =               { 96, 51, 46, 2 },
+       [QCOM_RPM_PM8018_LDO13] =               { 98, 53, 47, 2 },
+       [QCOM_RPM_PM8018_LDO14] =               { 100, 55, 48, 2 },
+       [QCOM_RPM_PM8018_LVS1] =                { 102, 57, 49, 1 },
+       [QCOM_RPM_PM8018_NCP] =                 { 103, 58, 80, 2 },
+       [QCOM_RPM_CXO_BUFFERS] =                { 105, 60, 81, 1 },
+       [QCOM_RPM_USB_OTG_SWITCH] =             { 106, 61, 82, 1 },
+       [QCOM_RPM_HDMI_SWITCH] =                { 107, 62, 83, 1 },
+       [QCOM_RPM_VOLTAGE_CORNER] =             { 109, 64, 87, 1 },
+};
+
+static const struct qcom_rpm_data mdm9615_template = {
+       .version = 3,
+       .resource_table = mdm9615_rpm_resource_table,
+       .n_resources = ARRAY_SIZE(mdm9615_rpm_resource_table),
+       .req_ctx_off = 3,
+       .req_sel_off = 11,
+       .ack_ctx_off = 15,
+       .ack_sel_off = 23,
+       .req_sel_size = 4,
+       .ack_sel_size = 7,
+};
+
 static const struct of_device_id qcom_rpm_of_match[] = {
        { .compatible = "qcom,rpm-apq8064", .data = &apq8064_template },
        { .compatible = "qcom,rpm-msm8660", .data = &msm8660_template },
        { .compatible = "qcom,rpm-msm8960", .data = &msm8960_template },
        { .compatible = "qcom,rpm-ipq8064", .data = &ipq806x_template },
+       { .compatible = "qcom,rpm-mdm9615", .data = &mdm9615_template },
        { }
 };
 MODULE_DEVICE_TABLE(of, qcom_rpm_of_match);
@@ -501,6 +554,20 @@ static int qcom_rpm_probe(struct platform_device *pdev)
        mutex_init(&rpm->lock);
        init_completion(&rpm->ack);
 
+       /* Enable message RAM clock */
+       rpm->ramclk = devm_clk_get(&pdev->dev, "ram");
+       if (IS_ERR(rpm->ramclk)) {
+               ret = PTR_ERR(rpm->ramclk);
+               if (ret == -EPROBE_DEFER)
+                       return ret;
+               /*
+                * Fall through in all other cases, as the clock is
+                * optional. (Does not exist on all platforms.)
+                */
+               rpm->ramclk = NULL;
+       }
+       clk_prepare_enable(rpm->ramclk); /* Accepts NULL */
+
        irq_ack = platform_get_irq_byname(pdev, "ack");
        if (irq_ack < 0) {
                dev_err(&pdev->dev, "required ack interrupt missing\n");
@@ -538,6 +605,7 @@ static int qcom_rpm_probe(struct platform_device *pdev)
        }
 
        rpm->ipc_regmap = syscon_node_to_regmap(syscon_np);
+       of_node_put(syscon_np);
        if (IS_ERR(rpm->ipc_regmap))
                return PTR_ERR(rpm->ipc_regmap);
 
@@ -620,7 +688,11 @@ static int qcom_rpm_probe(struct platform_device *pdev)
 
 static int qcom_rpm_remove(struct platform_device *pdev)
 {
+       struct qcom_rpm *rpm = dev_get_drvdata(&pdev->dev);
+
        of_platform_depopulate(&pdev->dev);
+       clk_disable_unprepare(rpm->ramclk);
+
        return 0;
 }