Anil kumar mamidala | 88f0dbd | 2014-02-04 19:09:02 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2014, 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 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/platform_device.h> |
| 18 | #include <linux/of_platform.h> |
| 19 | #include <mach/rpm-smd.h> |
| 20 | |
| 21 | #define RPM_REQUEST_TYPE_GPIO 0x6f697067 /* gpio */ |
| 22 | #define RPM_GPIO_NUMB_KEY 0x626d756e /* numb */ |
| 23 | #define RPM_GPIO_STAT_KEY 0x74617473 /* stat */ |
| 24 | #define RPM_GPIO_SETT_KEY 0x74746573 /* sett */ |
| 25 | #define RPM_GPIO_RESOURCE_ID 3 |
| 26 | #define GPIO_ON 1 |
| 27 | #define GPIO_OFF 0 |
| 28 | |
| 29 | static int msm_send_ext_buck_votes(int gpio_num, int settling_time) |
| 30 | { |
| 31 | int rc; |
| 32 | int gpio_status_sleep = GPIO_OFF; |
| 33 | int gpio_status_active = GPIO_ON; |
| 34 | |
| 35 | struct msm_rpm_kvp kvp_sleep[] = { |
| 36 | { |
| 37 | .key = RPM_GPIO_STAT_KEY, |
| 38 | .data = (void *)&gpio_status_sleep, |
| 39 | .length = sizeof(gpio_status_sleep), |
| 40 | } |
| 41 | }; |
| 42 | |
| 43 | struct msm_rpm_kvp kvp_active[] = { |
| 44 | { |
| 45 | .key = RPM_GPIO_NUMB_KEY, |
| 46 | .data = (void *)&gpio_num, |
| 47 | .length = sizeof(gpio_num), |
| 48 | }, |
| 49 | { |
| 50 | .key = RPM_GPIO_STAT_KEY, |
| 51 | .data = (void *)&gpio_status_active, |
| 52 | .length = sizeof(gpio_status_active), |
| 53 | }, |
| 54 | { |
| 55 | .key = RPM_GPIO_SETT_KEY, |
| 56 | .data = (void *)&settling_time, |
| 57 | .length = sizeof(settling_time), |
| 58 | }, |
| 59 | }; |
| 60 | |
| 61 | rc = msm_rpm_send_message(MSM_RPM_CTX_ACTIVE_SET, |
| 62 | RPM_REQUEST_TYPE_GPIO, RPM_GPIO_RESOURCE_ID, kvp_active, |
| 63 | ARRAY_SIZE(kvp_active)); |
| 64 | WARN(rc < 0, "RPM GPIO toggling (active set) did not enable!\n"); |
| 65 | |
| 66 | rc = msm_rpm_send_message(MSM_RPM_CTX_SLEEP_SET, |
| 67 | RPM_REQUEST_TYPE_GPIO, RPM_GPIO_RESOURCE_ID, kvp_sleep, |
| 68 | ARRAY_SIZE(kvp_sleep)); |
| 69 | WARN(rc < 0, "RPM GPIO toggling (sleep set) did not enable!\n"); |
| 70 | |
| 71 | return rc; |
| 72 | } |
| 73 | |
| 74 | static int msm_ext_buck_probe(struct platform_device *pdev) |
| 75 | { |
| 76 | char *key = NULL; |
| 77 | int gpio_num; |
| 78 | int settling_time_us; |
| 79 | int ret = 0; |
| 80 | |
| 81 | key = "qcom,gpio-num"; |
| 82 | ret = of_property_read_u32(pdev->dev.of_node, key, &gpio_num); |
| 83 | if (ret) { |
| 84 | pr_err("%s: Cannot read %s from dt (ret:%d)\n", |
| 85 | __func__, key, ret); |
| 86 | return ret; |
| 87 | } |
| 88 | |
| 89 | key = "qcom,settling-time-us"; |
| 90 | ret = of_property_read_u32(pdev->dev.of_node, key, |
| 91 | &settling_time_us); |
| 92 | if (ret) { |
| 93 | pr_err("%s: Cannot read %s from dt (ret:%d)\n", |
| 94 | __func__, key, ret); |
| 95 | return ret; |
| 96 | } |
| 97 | |
| 98 | ret = msm_send_ext_buck_votes(gpio_num, settling_time_us); |
| 99 | |
| 100 | return ret; |
| 101 | } |
| 102 | |
| 103 | static struct of_device_id msm_ext_buck_table[] = { |
| 104 | {.compatible = "qcom,ext-buck-control"}, |
| 105 | {}, |
| 106 | }; |
| 107 | |
| 108 | static struct platform_driver msm_ext_buck_driver = { |
| 109 | .probe = msm_ext_buck_probe, |
| 110 | .driver = { |
| 111 | .name = "ext-buck-control", |
| 112 | .owner = THIS_MODULE, |
| 113 | .of_match_table = msm_ext_buck_table, |
| 114 | }, |
| 115 | }; |
| 116 | |
| 117 | static int __init msm_ext_buck_init(void) |
| 118 | { |
| 119 | return platform_driver_register(&msm_ext_buck_driver); |
| 120 | } |
| 121 | late_initcall(msm_ext_buck_init); |