|
| 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/io.h> |
| 18 | +#include <linux/platform_device.h> |
| 19 | +#include <linux/of_platform.h> |
| 20 | +#include <mach/rpm-smd.h> |
| 21 | +#include "ext-buck-support.h" |
| 22 | + |
| 23 | +static bool msm_ext_buck; |
| 24 | + |
| 25 | +#define RPM_REQUEST_TYPE_GPIO 0x6F697067 |
| 26 | +#define RPM_GPIO_NUMB_KEY 0x626d756e |
| 27 | +#define RPM_GPIO_STAT_KEY 0x74617473 |
| 28 | +#define RPM_GPIO_SETT_KEY 0x74746573 |
| 29 | +#define RPM_GPIO_RESOURCE_ID 3 |
| 30 | +#define GPIO_SET 1 |
| 31 | +#define GPIO_RESET 0 |
| 32 | + |
| 33 | +static void msm_send_ext_buck_votes(int gpio_num, int settling_time) |
| 34 | +{ |
| 35 | + int rc; |
| 36 | + int gpio_status_sleep = GPIO_RESET; |
| 37 | + int gpio_status_active = GPIO_SET; |
| 38 | + |
| 39 | + struct msm_rpm_kvp kvp_sleep[] = { |
| 40 | + { |
| 41 | + .key = RPM_GPIO_NUMB_KEY, |
| 42 | + .data = (void *)&gpio_num, |
| 43 | + .length = sizeof(gpio_num), |
| 44 | + }, |
| 45 | + { |
| 46 | + .key = RPM_GPIO_STAT_KEY, |
| 47 | + .data = (void *)&gpio_status_sleep, |
| 48 | + .length = sizeof(gpio_status_sleep), |
| 49 | + }, |
| 50 | + { |
| 51 | + .key = RPM_GPIO_SETT_KEY, |
| 52 | + .data = (void *)&settling_time, |
| 53 | + .length = sizeof(settling_time), |
| 54 | + }, |
| 55 | + }; |
| 56 | + |
| 57 | + struct msm_rpm_kvp kvp_active[] = { |
| 58 | + { |
| 59 | + .key = RPM_GPIO_NUMB_KEY, |
| 60 | + .data = (void *)&gpio_num, |
| 61 | + .length = sizeof(gpio_num), |
| 62 | + }, |
| 63 | + { |
| 64 | + .key = RPM_GPIO_STAT_KEY, |
| 65 | + .data = (void *)&gpio_status_active, |
| 66 | + .length = sizeof(gpio_status_active), |
| 67 | + }, |
| 68 | + { |
| 69 | + .key = RPM_GPIO_SETT_KEY, |
| 70 | + .data = (void *)&settling_time, |
| 71 | + .length = sizeof(settling_time), |
| 72 | + }, |
| 73 | + }; |
| 74 | + |
| 75 | + rc = msm_rpm_send_message(MSM_RPM_CTX_SLEEP_SET, |
| 76 | + RPM_REQUEST_TYPE_GPIO, RPM_GPIO_RESOURCE_ID, kvp_sleep, 3); |
| 77 | + WARN(rc < 0, "RPM GPIO toggling (sleep set) did not enable!\n"); |
| 78 | + |
| 79 | + rc = msm_rpm_send_message(MSM_RPM_CTX_ACTIVE_SET, |
| 80 | + RPM_REQUEST_TYPE_GPIO, RPM_GPIO_RESOURCE_ID, kvp_active, 3); |
| 81 | + WARN(rc < 0, "RPM GPIO toggling (active set) did not enable!\n"); |
| 82 | +} |
| 83 | + |
| 84 | +int msm_get_ext_buck_presence(void) |
| 85 | +{ |
| 86 | + return msm_ext_buck; |
| 87 | +} |
| 88 | +EXPORT_SYMBOL(msm_get_ext_buck_presence); |
| 89 | + |
| 90 | +static int msm_ext_buck_probe(struct platform_device *pdev) |
| 91 | +{ |
| 92 | + char *key = NULL; |
| 93 | + |
| 94 | + key = "qcom,ext-buck"; |
| 95 | + msm_ext_buck = of_property_read_bool(pdev->dev.of_node, key); |
| 96 | + if (msm_ext_buck) { |
| 97 | + int gpio_num; |
| 98 | + int settling_time; |
| 99 | + |
| 100 | + key = "qcom,gpio-num"; |
| 101 | + of_property_read_u32(pdev->dev.of_node, key, |
| 102 | + &gpio_num); |
| 103 | + |
| 104 | + key = "qcom,sett-time"; |
| 105 | + of_property_read_u32(pdev->dev.of_node, key, |
| 106 | + &settling_time); |
| 107 | + |
| 108 | + msm_send_ext_buck_votes(gpio_num, settling_time); |
| 109 | + } |
| 110 | + |
| 111 | + return 0; |
| 112 | +} |
| 113 | + |
| 114 | +static struct of_device_id msm_ext_buck_table[] = { |
| 115 | + {.compatible = "qcom,ext-buck-support"}, |
| 116 | + {}, |
| 117 | +}; |
| 118 | + |
| 119 | +static struct platform_driver msm_ext_buck_driver = { |
| 120 | + .probe = msm_ext_buck_probe, |
| 121 | + .driver = { |
| 122 | + .name = "ext-buck-support", |
| 123 | + .owner = THIS_MODULE, |
| 124 | + .of_match_table = msm_ext_buck_table, |
| 125 | + }, |
| 126 | +}; |
| 127 | + |
| 128 | +static int __init msm_ext_buck_init(void) |
| 129 | +{ |
| 130 | + return platform_driver_register(&msm_ext_buck_driver); |
| 131 | +} |
| 132 | +device_initcall(msm_ext_buck_init); |
0 commit comments