Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

greybus: pwm: Add runtime_pm support

Add runtime pm support for the pmw driver.

Testing Done: Set the parameters of pwm0, and enable.
Disable pwm0 and let the module enter standby.
Enable pwm0, and observe that with an oscilloscope
that the wave form is the same as before.

Signed-off-by: Axel Haslam <haslam_axel@projectara.com>
Signed-off-by: David Lin <dtwlin@google.com>
Reviewed-by: Johan Hovold <johan@hovoldconsulting.com>
Signed-off-by: Alex Elder <elder@linaro.org>

authored by

Axel Haslam and committed by
Alex Elder
afa807b8 993dc992

+86 -12
+86 -12
drivers/staging/greybus/pwm.c
··· 43 43 u8 which) 44 44 { 45 45 struct gb_pwm_activate_request request; 46 + struct gbphy_device *gbphy_dev; 47 + int ret; 46 48 47 49 if (which > pwmc->pwm_max) 48 50 return -EINVAL; 49 51 50 52 request.which = which; 51 - return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ACTIVATE, 52 - &request, sizeof(request), NULL, 0); 53 + 54 + gbphy_dev = to_gbphy_dev(pwmc->chip.dev); 55 + ret = gbphy_runtime_get_sync(gbphy_dev); 56 + if (ret) 57 + return ret; 58 + 59 + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ACTIVATE, 60 + &request, sizeof(request), NULL, 0); 61 + 62 + gbphy_runtime_put_autosuspend(gbphy_dev); 63 + 64 + return ret; 53 65 } 54 66 55 67 static int gb_pwm_deactivate_operation(struct gb_pwm_chip *pwmc, 56 68 u8 which) 57 69 { 58 70 struct gb_pwm_deactivate_request request; 71 + struct gbphy_device *gbphy_dev; 72 + int ret; 59 73 60 74 if (which > pwmc->pwm_max) 61 75 return -EINVAL; 62 76 63 77 request.which = which; 64 - return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DEACTIVATE, 65 - &request, sizeof(request), NULL, 0); 78 + 79 + gbphy_dev = to_gbphy_dev(pwmc->chip.dev); 80 + ret = gbphy_runtime_get_sync(gbphy_dev); 81 + if (ret) 82 + return ret; 83 + 84 + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DEACTIVATE, 85 + &request, sizeof(request), NULL, 0); 86 + 87 + gbphy_runtime_put_autosuspend(gbphy_dev); 88 + 89 + return ret; 66 90 } 67 91 68 92 static int gb_pwm_config_operation(struct gb_pwm_chip *pwmc, 69 93 u8 which, u32 duty, u32 period) 70 94 { 71 95 struct gb_pwm_config_request request; 96 + struct gbphy_device *gbphy_dev; 97 + int ret; 72 98 73 99 if (which > pwmc->pwm_max) 74 100 return -EINVAL; ··· 102 76 request.which = which; 103 77 request.duty = cpu_to_le32(duty); 104 78 request.period = cpu_to_le32(period); 105 - return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_CONFIG, 106 - &request, sizeof(request), NULL, 0); 79 + 80 + gbphy_dev = to_gbphy_dev(pwmc->chip.dev); 81 + ret = gbphy_runtime_get_sync(gbphy_dev); 82 + if (ret) 83 + return ret; 84 + 85 + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_CONFIG, 86 + &request, sizeof(request), NULL, 0); 87 + 88 + gbphy_runtime_put_autosuspend(gbphy_dev); 89 + 90 + return ret; 107 91 } 108 92 109 93 static int gb_pwm_set_polarity_operation(struct gb_pwm_chip *pwmc, 110 94 u8 which, u8 polarity) 111 95 { 112 96 struct gb_pwm_polarity_request request; 97 + struct gbphy_device *gbphy_dev; 98 + int ret; 113 99 114 100 if (which > pwmc->pwm_max) 115 101 return -EINVAL; 116 102 117 103 request.which = which; 118 104 request.polarity = polarity; 119 - return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_POLARITY, 120 - &request, sizeof(request), NULL, 0); 105 + 106 + gbphy_dev = to_gbphy_dev(pwmc->chip.dev); 107 + ret = gbphy_runtime_get_sync(gbphy_dev); 108 + if (ret) 109 + return ret; 110 + 111 + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_POLARITY, 112 + &request, sizeof(request), NULL, 0); 113 + 114 + gbphy_runtime_put_autosuspend(gbphy_dev); 115 + 116 + return ret; 121 117 } 122 118 123 119 static int gb_pwm_enable_operation(struct gb_pwm_chip *pwmc, 124 120 u8 which) 125 121 { 126 122 struct gb_pwm_enable_request request; 123 + struct gbphy_device *gbphy_dev; 124 + int ret; 127 125 128 126 if (which > pwmc->pwm_max) 129 127 return -EINVAL; 130 128 131 129 request.which = which; 132 - return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ENABLE, 133 - &request, sizeof(request), NULL, 0); 130 + 131 + gbphy_dev = to_gbphy_dev(pwmc->chip.dev); 132 + ret = gbphy_runtime_get_sync(gbphy_dev); 133 + if (ret) 134 + return ret; 135 + 136 + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_ENABLE, 137 + &request, sizeof(request), NULL, 0); 138 + if (ret) 139 + gbphy_runtime_put_autosuspend(gbphy_dev); 140 + 141 + return ret; 134 142 } 135 143 136 144 static int gb_pwm_disable_operation(struct gb_pwm_chip *pwmc, 137 145 u8 which) 138 146 { 139 147 struct gb_pwm_disable_request request; 148 + struct gbphy_device *gbphy_dev; 149 + int ret; 140 150 141 151 if (which > pwmc->pwm_max) 142 152 return -EINVAL; 143 153 144 154 request.which = which; 145 - return gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DISABLE, 146 - &request, sizeof(request), NULL, 0); 155 + 156 + ret = gb_operation_sync(pwmc->connection, GB_PWM_TYPE_DISABLE, 157 + &request, sizeof(request), NULL, 0); 158 + 159 + gbphy_dev = to_gbphy_dev(pwmc->chip.dev); 160 + gbphy_runtime_put_autosuspend(gbphy_dev); 161 + 162 + return ret; 147 163 } 148 164 149 165 static int gb_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) ··· 293 225 goto exit_connection_disable; 294 226 } 295 227 228 + gbphy_runtime_put_autosuspend(gbphy_dev); 296 229 return 0; 297 230 298 231 exit_connection_disable: ··· 309 240 { 310 241 struct gb_pwm_chip *pwmc = gb_gbphy_get_data(gbphy_dev); 311 242 struct gb_connection *connection = pwmc->connection; 243 + int ret; 244 + 245 + ret = gbphy_runtime_get_sync(gbphy_dev); 246 + if (ret) 247 + gbphy_runtime_get_noresume(gbphy_dev); 312 248 313 249 pwmchip_remove(&pwmc->chip); 314 250 gb_connection_disable(connection);