Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 1 | /* |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2018, The Linux Foundation. All rights reserved. |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #define pr_fmt(fmt) "[drm-dp] %s: " fmt, __func__ |
| 16 | |
| 17 | #include <linux/of_gpio.h> |
| 18 | |
| 19 | #include "dp_parser.h" |
| 20 | |
| 21 | static void dp_parser_unmap_io_resources(struct dp_parser *parser) |
| 22 | { |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 23 | int i = 0; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 24 | struct dp_io *io = &parser->io; |
| 25 | |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 26 | for (i = 0; i < io->len; i++) |
| 27 | msm_dss_iounmap(&io->data[i].io); |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 30 | static int dp_parser_reg(struct dp_parser *parser) |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 31 | { |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 32 | int rc = 0, i = 0; |
| 33 | u32 reg_count; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 34 | struct platform_device *pdev = parser->pdev; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 35 | struct dp_io *io = &parser->io; |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 36 | struct device *dev = &pdev->dev; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 37 | |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 38 | reg_count = of_property_count_strings(dev->of_node, "reg-names"); |
| 39 | if (reg_count <= 0) { |
| 40 | pr_err("no reg defined\n"); |
| 41 | return -EINVAL; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 44 | io->len = reg_count; |
| 45 | io->data = devm_kzalloc(dev, sizeof(struct dp_io_data) * reg_count, |
| 46 | GFP_KERNEL); |
| 47 | if (!io->data) |
| 48 | return -ENOMEM; |
| 49 | |
| 50 | for (i = 0; i < reg_count; i++) { |
| 51 | of_property_read_string_index(dev->of_node, |
| 52 | "reg-names", i, &io->data[i].name); |
| 53 | rc = msm_dss_ioremap_byname(pdev, &io->data[i].io, |
| 54 | io->data[i].name); |
| 55 | if (rc) { |
| 56 | pr_err("unable to remap %s resources\n", |
| 57 | io->data[i].name); |
| 58 | goto err; |
| 59 | } |
Samantha Tran | 45c3e5c | 2017-10-19 12:51:09 -0700 | [diff] [blame] | 60 | } |
| 61 | |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 62 | return 0; |
| 63 | err: |
| 64 | dp_parser_unmap_io_resources(parser); |
| 65 | return rc; |
| 66 | } |
| 67 | |
Padmanabhan Komanduru | 20a21db | 2017-07-10 16:58:59 +0530 | [diff] [blame] | 68 | static const char *dp_get_phy_aux_config_property(u32 cfg_type) |
| 69 | { |
| 70 | switch (cfg_type) { |
| 71 | case PHY_AUX_CFG0: |
| 72 | return "qcom,aux-cfg0-settings"; |
| 73 | case PHY_AUX_CFG1: |
| 74 | return "qcom,aux-cfg1-settings"; |
| 75 | case PHY_AUX_CFG2: |
| 76 | return "qcom,aux-cfg2-settings"; |
| 77 | case PHY_AUX_CFG3: |
| 78 | return "qcom,aux-cfg3-settings"; |
| 79 | case PHY_AUX_CFG4: |
| 80 | return "qcom,aux-cfg4-settings"; |
| 81 | case PHY_AUX_CFG5: |
| 82 | return "qcom,aux-cfg5-settings"; |
| 83 | case PHY_AUX_CFG6: |
| 84 | return "qcom,aux-cfg6-settings"; |
| 85 | case PHY_AUX_CFG7: |
| 86 | return "qcom,aux-cfg7-settings"; |
| 87 | case PHY_AUX_CFG8: |
| 88 | return "qcom,aux-cfg8-settings"; |
| 89 | case PHY_AUX_CFG9: |
| 90 | return "qcom,aux-cfg9-settings"; |
| 91 | default: |
| 92 | return "unknown"; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | static void dp_parser_phy_aux_cfg_reset(struct dp_parser *parser) |
| 97 | { |
| 98 | int i = 0; |
| 99 | |
| 100 | for (i = 0; i < PHY_AUX_CFG_MAX; i++) |
| 101 | parser->aux_cfg[i] = (const struct dp_aux_cfg){ 0 }; |
| 102 | } |
| 103 | |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 104 | static int dp_parser_aux(struct dp_parser *parser) |
| 105 | { |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 106 | struct device_node *of_node = parser->pdev->dev.of_node; |
Padmanabhan Komanduru | 20a21db | 2017-07-10 16:58:59 +0530 | [diff] [blame] | 107 | int len = 0, i = 0, j = 0, config_count = 0; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 108 | const char *data; |
Padmanabhan Komanduru | 20a21db | 2017-07-10 16:58:59 +0530 | [diff] [blame] | 109 | int const minimum_config_count = 1; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 110 | |
Padmanabhan Komanduru | 20a21db | 2017-07-10 16:58:59 +0530 | [diff] [blame] | 111 | for (i = 0; i < PHY_AUX_CFG_MAX; i++) { |
| 112 | const char *property = dp_get_phy_aux_config_property(i); |
| 113 | |
| 114 | data = of_get_property(of_node, property, &len); |
| 115 | if (!data) { |
| 116 | pr_err("Unable to read %s\n", property); |
| 117 | goto error; |
| 118 | } |
| 119 | |
| 120 | config_count = len - 1; |
| 121 | if ((config_count < minimum_config_count) || |
| 122 | (config_count > DP_AUX_CFG_MAX_VALUE_CNT)) { |
| 123 | pr_err("Invalid config count (%d) configs for %s\n", |
| 124 | config_count, property); |
| 125 | goto error; |
| 126 | } |
| 127 | |
| 128 | parser->aux_cfg[i].offset = data[0]; |
| 129 | parser->aux_cfg[i].cfg_cnt = config_count; |
| 130 | pr_debug("%s offset=0x%x, cfg_cnt=%d\n", |
| 131 | property, |
| 132 | parser->aux_cfg[i].offset, |
| 133 | parser->aux_cfg[i].cfg_cnt); |
| 134 | for (j = 1; j < len; j++) { |
| 135 | parser->aux_cfg[i].lut[j - 1] = data[j]; |
| 136 | pr_debug("%s lut[%d]=0x%x\n", |
| 137 | property, |
| 138 | i, |
| 139 | parser->aux_cfg[i].lut[j - 1]); |
| 140 | } |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 141 | } |
Padmanabhan Komanduru | 20a21db | 2017-07-10 16:58:59 +0530 | [diff] [blame] | 142 | return 0; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 143 | |
Padmanabhan Komanduru | 20a21db | 2017-07-10 16:58:59 +0530 | [diff] [blame] | 144 | error: |
| 145 | dp_parser_phy_aux_cfg_reset(parser); |
| 146 | return -EINVAL; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | static int dp_parser_misc(struct dp_parser *parser) |
| 150 | { |
| 151 | int rc = 0; |
| 152 | struct device_node *of_node = parser->pdev->dev.of_node; |
| 153 | |
| 154 | rc = of_property_read_u32(of_node, |
| 155 | "qcom,max-pclk-frequency-khz", &parser->max_pclk_khz); |
| 156 | if (rc) |
| 157 | parser->max_pclk_khz = DP_MAX_PIXEL_CLK_KHZ; |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | static int dp_parser_pinctrl(struct dp_parser *parser) |
| 163 | { |
| 164 | int rc = 0; |
| 165 | struct dp_pinctrl *pinctrl = &parser->pinctrl; |
| 166 | |
| 167 | pinctrl->pin = devm_pinctrl_get(&parser->pdev->dev); |
| 168 | |
| 169 | if (IS_ERR_OR_NULL(pinctrl->pin)) { |
| 170 | rc = PTR_ERR(pinctrl->pin); |
| 171 | pr_err("failed to get pinctrl, rc=%d\n", rc); |
| 172 | goto error; |
| 173 | } |
| 174 | |
| 175 | pinctrl->state_active = pinctrl_lookup_state(pinctrl->pin, |
| 176 | "mdss_dp_active"); |
| 177 | if (IS_ERR_OR_NULL(pinctrl->state_active)) { |
| 178 | rc = PTR_ERR(pinctrl->state_active); |
| 179 | pr_err("failed to get pinctrl active state, rc=%d\n", rc); |
| 180 | goto error; |
| 181 | } |
| 182 | |
| 183 | pinctrl->state_suspend = pinctrl_lookup_state(pinctrl->pin, |
| 184 | "mdss_dp_sleep"); |
| 185 | if (IS_ERR_OR_NULL(pinctrl->state_suspend)) { |
| 186 | rc = PTR_ERR(pinctrl->state_suspend); |
| 187 | pr_err("failed to get pinctrl suspend state, rc=%d\n", rc); |
| 188 | goto error; |
| 189 | } |
| 190 | error: |
| 191 | return rc; |
| 192 | } |
| 193 | |
| 194 | static int dp_parser_gpio(struct dp_parser *parser) |
| 195 | { |
| 196 | int i = 0; |
| 197 | struct device *dev = &parser->pdev->dev; |
| 198 | struct device_node *of_node = dev->of_node; |
| 199 | struct dss_module_power *mp = &parser->mp[DP_CORE_PM]; |
| 200 | static const char * const dp_gpios[] = { |
| 201 | "qcom,aux-en-gpio", |
| 202 | "qcom,aux-sel-gpio", |
| 203 | "qcom,usbplug-cc-gpio", |
| 204 | }; |
| 205 | |
| 206 | mp->gpio_config = devm_kzalloc(dev, |
| 207 | sizeof(struct dss_gpio) * ARRAY_SIZE(dp_gpios), GFP_KERNEL); |
Samantha Tran | f4259fd | 2017-09-28 16:42:12 -0700 | [diff] [blame] | 208 | if (!mp->gpio_config) |
| 209 | return -ENOMEM; |
| 210 | |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 211 | mp->num_gpio = ARRAY_SIZE(dp_gpios); |
| 212 | |
| 213 | for (i = 0; i < ARRAY_SIZE(dp_gpios); i++) { |
| 214 | mp->gpio_config[i].gpio = of_get_named_gpio(of_node, |
| 215 | dp_gpios[i], 0); |
| 216 | |
| 217 | if (!gpio_is_valid(mp->gpio_config[i].gpio)) { |
| 218 | pr_err("%s gpio not specified\n", dp_gpios[i]); |
| 219 | return -EINVAL; |
| 220 | } |
| 221 | |
| 222 | strlcpy(mp->gpio_config[i].gpio_name, dp_gpios[i], |
| 223 | sizeof(mp->gpio_config[i].gpio_name)); |
| 224 | |
| 225 | mp->gpio_config[i].value = 0; |
| 226 | } |
| 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static const char *dp_parser_supply_node_name(enum dp_pm_type module) |
| 232 | { |
| 233 | switch (module) { |
| 234 | case DP_CORE_PM: return "qcom,core-supply-entries"; |
| 235 | case DP_CTRL_PM: return "qcom,ctrl-supply-entries"; |
| 236 | case DP_PHY_PM: return "qcom,phy-supply-entries"; |
| 237 | default: return "???"; |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | static int dp_parser_get_vreg(struct dp_parser *parser, |
| 242 | enum dp_pm_type module) |
| 243 | { |
| 244 | int i = 0, rc = 0; |
| 245 | u32 tmp = 0; |
| 246 | const char *pm_supply_name = NULL; |
| 247 | struct device_node *supply_node = NULL; |
| 248 | struct device_node *of_node = parser->pdev->dev.of_node; |
| 249 | struct device_node *supply_root_node = NULL; |
| 250 | struct dss_module_power *mp = &parser->mp[module]; |
| 251 | |
| 252 | mp->num_vreg = 0; |
| 253 | pm_supply_name = dp_parser_supply_node_name(module); |
| 254 | supply_root_node = of_get_child_by_name(of_node, pm_supply_name); |
| 255 | if (!supply_root_node) { |
| 256 | pr_err("no supply entry present: %s\n", pm_supply_name); |
| 257 | goto novreg; |
| 258 | } |
| 259 | |
| 260 | mp->num_vreg = of_get_available_child_count(supply_root_node); |
| 261 | |
| 262 | if (mp->num_vreg == 0) { |
| 263 | pr_debug("no vreg\n"); |
| 264 | goto novreg; |
| 265 | } else { |
| 266 | pr_debug("vreg found. count=%d\n", mp->num_vreg); |
| 267 | } |
| 268 | |
| 269 | mp->vreg_config = devm_kzalloc(&parser->pdev->dev, |
| 270 | sizeof(struct dss_vreg) * mp->num_vreg, GFP_KERNEL); |
| 271 | if (!mp->vreg_config) { |
| 272 | rc = -ENOMEM; |
| 273 | goto error; |
| 274 | } |
| 275 | |
| 276 | for_each_child_of_node(supply_root_node, supply_node) { |
| 277 | const char *st = NULL; |
| 278 | /* vreg-name */ |
| 279 | rc = of_property_read_string(supply_node, |
| 280 | "qcom,supply-name", &st); |
| 281 | if (rc) { |
| 282 | pr_err("error reading name. rc=%d\n", |
| 283 | rc); |
| 284 | goto error; |
| 285 | } |
| 286 | snprintf(mp->vreg_config[i].vreg_name, |
| 287 | ARRAY_SIZE((mp->vreg_config[i].vreg_name)), "%s", st); |
| 288 | /* vreg-min-voltage */ |
| 289 | rc = of_property_read_u32(supply_node, |
| 290 | "qcom,supply-min-voltage", &tmp); |
| 291 | if (rc) { |
| 292 | pr_err("error reading min volt. rc=%d\n", |
| 293 | rc); |
| 294 | goto error; |
| 295 | } |
| 296 | mp->vreg_config[i].min_voltage = tmp; |
| 297 | |
| 298 | /* vreg-max-voltage */ |
| 299 | rc = of_property_read_u32(supply_node, |
| 300 | "qcom,supply-max-voltage", &tmp); |
| 301 | if (rc) { |
| 302 | pr_err("error reading max volt. rc=%d\n", |
| 303 | rc); |
| 304 | goto error; |
| 305 | } |
| 306 | mp->vreg_config[i].max_voltage = tmp; |
| 307 | |
| 308 | /* enable-load */ |
| 309 | rc = of_property_read_u32(supply_node, |
| 310 | "qcom,supply-enable-load", &tmp); |
| 311 | if (rc) { |
| 312 | pr_err("error reading enable load. rc=%d\n", |
| 313 | rc); |
| 314 | goto error; |
| 315 | } |
| 316 | mp->vreg_config[i].enable_load = tmp; |
| 317 | |
| 318 | /* disable-load */ |
| 319 | rc = of_property_read_u32(supply_node, |
| 320 | "qcom,supply-disable-load", &tmp); |
| 321 | if (rc) { |
| 322 | pr_err("error reading disable load. rc=%d\n", |
| 323 | rc); |
| 324 | goto error; |
| 325 | } |
| 326 | mp->vreg_config[i].disable_load = tmp; |
| 327 | |
| 328 | pr_debug("%s min=%d, max=%d, enable=%d, disable=%d\n", |
| 329 | mp->vreg_config[i].vreg_name, |
| 330 | mp->vreg_config[i].min_voltage, |
| 331 | mp->vreg_config[i].max_voltage, |
| 332 | mp->vreg_config[i].enable_load, |
| 333 | mp->vreg_config[i].disable_load |
| 334 | ); |
| 335 | ++i; |
| 336 | } |
| 337 | |
| 338 | return rc; |
| 339 | |
| 340 | error: |
| 341 | if (mp->vreg_config) { |
| 342 | devm_kfree(&parser->pdev->dev, mp->vreg_config); |
| 343 | mp->vreg_config = NULL; |
| 344 | } |
| 345 | novreg: |
| 346 | mp->num_vreg = 0; |
| 347 | |
| 348 | return rc; |
| 349 | } |
| 350 | |
| 351 | static void dp_parser_put_vreg_data(struct device *dev, |
| 352 | struct dss_module_power *mp) |
| 353 | { |
| 354 | if (!mp) { |
| 355 | DEV_ERR("invalid input\n"); |
| 356 | return; |
| 357 | } |
| 358 | |
| 359 | if (mp->vreg_config) { |
| 360 | devm_kfree(dev, mp->vreg_config); |
| 361 | mp->vreg_config = NULL; |
| 362 | } |
| 363 | mp->num_vreg = 0; |
| 364 | } |
| 365 | |
| 366 | static int dp_parser_regulator(struct dp_parser *parser) |
| 367 | { |
| 368 | int i, rc = 0; |
| 369 | struct platform_device *pdev = parser->pdev; |
| 370 | |
| 371 | /* Parse the regulator information */ |
| 372 | for (i = DP_CORE_PM; i < DP_MAX_PM; i++) { |
| 373 | rc = dp_parser_get_vreg(parser, i); |
| 374 | if (rc) { |
| 375 | pr_err("get_dt_vreg_data failed for %s. rc=%d\n", |
| 376 | dp_parser_pm_name(i), rc); |
| 377 | i--; |
| 378 | for (; i >= DP_CORE_PM; i--) |
| 379 | dp_parser_put_vreg_data(&pdev->dev, |
| 380 | &parser->mp[i]); |
| 381 | break; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | return rc; |
| 386 | } |
| 387 | |
| 388 | static bool dp_parser_check_prefix(const char *clk_prefix, const char *clk_name) |
| 389 | { |
| 390 | return !!strnstr(clk_name, clk_prefix, strlen(clk_name)); |
| 391 | } |
| 392 | |
| 393 | static void dp_parser_put_clk_data(struct device *dev, |
| 394 | struct dss_module_power *mp) |
| 395 | { |
| 396 | if (!mp) { |
| 397 | DEV_ERR("%s: invalid input\n", __func__); |
| 398 | return; |
| 399 | } |
| 400 | |
| 401 | if (mp->clk_config) { |
| 402 | devm_kfree(dev, mp->clk_config); |
| 403 | mp->clk_config = NULL; |
| 404 | } |
| 405 | |
| 406 | mp->num_clk = 0; |
| 407 | } |
| 408 | |
Tatenda Chipeperekwa | 2bc4487 | 2017-10-18 18:26:56 -0700 | [diff] [blame] | 409 | static void dp_parser_put_gpio_data(struct device *dev, |
| 410 | struct dss_module_power *mp) |
| 411 | { |
| 412 | if (!mp) { |
| 413 | DEV_ERR("%s: invalid input\n", __func__); |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | if (mp->gpio_config) { |
| 418 | devm_kfree(dev, mp->gpio_config); |
| 419 | mp->gpio_config = NULL; |
| 420 | } |
| 421 | |
| 422 | mp->num_gpio = 0; |
| 423 | } |
| 424 | |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 425 | static int dp_parser_init_clk_data(struct dp_parser *parser) |
| 426 | { |
| 427 | int num_clk = 0, i = 0, rc = 0; |
| 428 | int core_clk_count = 0, ctrl_clk_count = 0; |
| 429 | const char *core_clk = "core"; |
| 430 | const char *ctrl_clk = "ctrl"; |
| 431 | const char *clk_name; |
| 432 | struct device *dev = &parser->pdev->dev; |
| 433 | struct dss_module_power *core_power = &parser->mp[DP_CORE_PM]; |
| 434 | struct dss_module_power *ctrl_power = &parser->mp[DP_CTRL_PM]; |
| 435 | |
| 436 | num_clk = of_property_count_strings(dev->of_node, "clock-names"); |
| 437 | if (num_clk <= 0) { |
| 438 | pr_err("no clocks are defined\n"); |
| 439 | rc = -EINVAL; |
| 440 | goto exit; |
| 441 | } |
| 442 | |
| 443 | for (i = 0; i < num_clk; i++) { |
| 444 | of_property_read_string_index(dev->of_node, |
| 445 | "clock-names", i, &clk_name); |
| 446 | |
| 447 | if (dp_parser_check_prefix(core_clk, clk_name)) |
| 448 | core_clk_count++; |
| 449 | |
| 450 | if (dp_parser_check_prefix(ctrl_clk, clk_name)) |
| 451 | ctrl_clk_count++; |
| 452 | } |
| 453 | |
| 454 | /* Initialize the CORE power module */ |
| 455 | if (core_clk_count <= 0) { |
| 456 | pr_err("no core clocks are defined\n"); |
| 457 | rc = -EINVAL; |
| 458 | goto exit; |
| 459 | } |
| 460 | |
| 461 | core_power->num_clk = core_clk_count; |
| 462 | core_power->clk_config = devm_kzalloc(dev, |
| 463 | sizeof(struct dss_clk) * core_power->num_clk, |
| 464 | GFP_KERNEL); |
| 465 | if (!core_power->clk_config) { |
| 466 | rc = -EINVAL; |
| 467 | goto exit; |
| 468 | } |
| 469 | |
| 470 | /* Initialize the CTRL power module */ |
| 471 | if (ctrl_clk_count <= 0) { |
| 472 | pr_err("no ctrl clocks are defined\n"); |
| 473 | rc = -EINVAL; |
| 474 | goto ctrl_clock_error; |
| 475 | } |
| 476 | |
| 477 | ctrl_power->num_clk = ctrl_clk_count; |
| 478 | ctrl_power->clk_config = devm_kzalloc(dev, |
| 479 | sizeof(struct dss_clk) * ctrl_power->num_clk, |
| 480 | GFP_KERNEL); |
| 481 | if (!ctrl_power->clk_config) { |
| 482 | ctrl_power->num_clk = 0; |
| 483 | rc = -EINVAL; |
| 484 | goto ctrl_clock_error; |
| 485 | } |
| 486 | |
| 487 | return rc; |
| 488 | |
| 489 | ctrl_clock_error: |
| 490 | dp_parser_put_clk_data(dev, core_power); |
| 491 | exit: |
| 492 | return rc; |
| 493 | } |
| 494 | |
| 495 | static int dp_parser_clock(struct dp_parser *parser) |
| 496 | { |
| 497 | int rc = 0, i = 0; |
| 498 | int num_clk = 0; |
| 499 | int core_clk_index = 0, ctrl_clk_index = 0; |
| 500 | int core_clk_count = 0, ctrl_clk_count = 0; |
| 501 | const char *clk_name; |
| 502 | const char *core_clk = "core"; |
| 503 | const char *ctrl_clk = "ctrl"; |
| 504 | struct device *dev = &parser->pdev->dev; |
| 505 | struct dss_module_power *core_power = &parser->mp[DP_CORE_PM]; |
| 506 | struct dss_module_power *ctrl_power = &parser->mp[DP_CTRL_PM]; |
| 507 | |
| 508 | core_power = &parser->mp[DP_CORE_PM]; |
| 509 | ctrl_power = &parser->mp[DP_CTRL_PM]; |
| 510 | |
| 511 | rc = dp_parser_init_clk_data(parser); |
| 512 | if (rc) { |
| 513 | pr_err("failed to initialize power data\n"); |
| 514 | rc = -EINVAL; |
| 515 | goto exit; |
| 516 | } |
| 517 | |
| 518 | core_clk_count = core_power->num_clk; |
| 519 | ctrl_clk_count = ctrl_power->num_clk; |
| 520 | |
| 521 | num_clk = core_clk_count + ctrl_clk_count; |
| 522 | |
| 523 | for (i = 0; i < num_clk; i++) { |
| 524 | of_property_read_string_index(dev->of_node, "clock-names", |
| 525 | i, &clk_name); |
| 526 | |
| 527 | if (dp_parser_check_prefix(core_clk, clk_name) && |
| 528 | core_clk_index < core_clk_count) { |
| 529 | struct dss_clk *clk = |
| 530 | &core_power->clk_config[core_clk_index]; |
| 531 | strlcpy(clk->clk_name, clk_name, sizeof(clk->clk_name)); |
| 532 | clk->type = DSS_CLK_AHB; |
| 533 | core_clk_index++; |
| 534 | } else if (dp_parser_check_prefix(ctrl_clk, clk_name) && |
| 535 | ctrl_clk_index < ctrl_clk_count) { |
| 536 | struct dss_clk *clk = |
| 537 | &ctrl_power->clk_config[ctrl_clk_index]; |
| 538 | strlcpy(clk->clk_name, clk_name, sizeof(clk->clk_name)); |
| 539 | ctrl_clk_index++; |
| 540 | |
| 541 | if (!strcmp(clk_name, "ctrl_link_clk") || |
Tatenda Chipeperekwa | c44d51b | 2017-06-16 17:12:00 -0700 | [diff] [blame] | 542 | !strcmp(clk_name, "ctrl_pixel_clk")) |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 543 | clk->type = DSS_CLK_PCLK; |
| 544 | else |
| 545 | clk->type = DSS_CLK_AHB; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | pr_debug("clock parsing successful\n"); |
| 550 | |
| 551 | exit: |
| 552 | return rc; |
| 553 | } |
| 554 | |
| 555 | static int dp_parser_parse(struct dp_parser *parser) |
| 556 | { |
| 557 | int rc = 0; |
| 558 | |
| 559 | if (!parser) { |
| 560 | pr_err("invalid input\n"); |
| 561 | rc = -EINVAL; |
| 562 | goto err; |
| 563 | } |
| 564 | |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 565 | rc = dp_parser_reg(parser); |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 566 | if (rc) |
| 567 | goto err; |
| 568 | |
| 569 | rc = dp_parser_aux(parser); |
| 570 | if (rc) |
| 571 | goto err; |
| 572 | |
| 573 | rc = dp_parser_misc(parser); |
| 574 | if (rc) |
| 575 | goto err; |
| 576 | |
| 577 | rc = dp_parser_clock(parser); |
| 578 | if (rc) |
| 579 | goto err; |
| 580 | |
| 581 | rc = dp_parser_regulator(parser); |
| 582 | if (rc) |
| 583 | goto err; |
| 584 | |
| 585 | rc = dp_parser_gpio(parser); |
| 586 | if (rc) |
| 587 | goto err; |
| 588 | |
| 589 | rc = dp_parser_pinctrl(parser); |
| 590 | err: |
| 591 | return rc; |
| 592 | } |
| 593 | |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 594 | static struct dp_io_data *dp_parser_get_io(struct dp_parser *dp_parser, |
| 595 | char *name) |
| 596 | { |
| 597 | int i = 0; |
| 598 | struct dp_io *io; |
| 599 | |
| 600 | if (!dp_parser) { |
| 601 | pr_err("invalid input\n"); |
| 602 | goto err; |
| 603 | } |
| 604 | |
| 605 | io = &dp_parser->io; |
| 606 | |
| 607 | for (i = 0; i < io->len; i++) { |
| 608 | struct dp_io_data *data = &io->data[i]; |
| 609 | |
| 610 | if (!strcmp(data->name, name)) |
| 611 | return data; |
| 612 | } |
| 613 | err: |
| 614 | return NULL; |
| 615 | } |
| 616 | |
| 617 | static void dp_parser_get_io_buf(struct dp_parser *dp_parser, char *name) |
| 618 | { |
| 619 | int i = 0; |
| 620 | struct dp_io *io; |
| 621 | |
| 622 | if (!dp_parser) { |
| 623 | pr_err("invalid input\n"); |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | io = &dp_parser->io; |
| 628 | |
| 629 | for (i = 0; i < io->len; i++) { |
| 630 | struct dp_io_data *data = &io->data[i]; |
| 631 | |
| 632 | if (!strcmp(data->name, name)) { |
| 633 | if (!data->buf) |
| 634 | data->buf = devm_kzalloc(&dp_parser->pdev->dev, |
| 635 | data->io.len, GFP_KERNEL); |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | static void dp_parser_clear_io_buf(struct dp_parser *dp_parser) |
| 641 | { |
| 642 | int i = 0; |
| 643 | struct dp_io *io; |
| 644 | |
| 645 | if (!dp_parser) { |
| 646 | pr_err("invalid input\n"); |
| 647 | return; |
| 648 | } |
| 649 | |
| 650 | io = &dp_parser->io; |
| 651 | |
| 652 | for (i = 0; i < io->len; i++) { |
| 653 | struct dp_io_data *data = &io->data[i]; |
| 654 | |
| 655 | if (data->buf) |
| 656 | devm_kfree(&dp_parser->pdev->dev, data->buf); |
| 657 | |
| 658 | data->buf = NULL; |
| 659 | } |
| 660 | } |
| 661 | |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 662 | struct dp_parser *dp_parser_get(struct platform_device *pdev) |
| 663 | { |
| 664 | struct dp_parser *parser; |
| 665 | |
| 666 | parser = devm_kzalloc(&pdev->dev, sizeof(*parser), GFP_KERNEL); |
| 667 | if (!parser) |
| 668 | return ERR_PTR(-ENOMEM); |
| 669 | |
| 670 | parser->parse = dp_parser_parse; |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 671 | parser->get_io = dp_parser_get_io; |
| 672 | parser->get_io_buf = dp_parser_get_io_buf; |
| 673 | parser->clear_io_buf = dp_parser_clear_io_buf; |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 674 | parser->pdev = pdev; |
| 675 | |
| 676 | return parser; |
| 677 | } |
| 678 | |
| 679 | void dp_parser_put(struct dp_parser *parser) |
| 680 | { |
| 681 | int i = 0; |
| 682 | struct dss_module_power *power = NULL; |
| 683 | |
| 684 | if (!parser) { |
| 685 | pr_err("invalid parser module\n"); |
| 686 | return; |
| 687 | } |
| 688 | |
| 689 | power = parser->mp; |
| 690 | |
| 691 | for (i = 0; i < DP_MAX_PM; i++) { |
Tatenda Chipeperekwa | 2bc4487 | 2017-10-18 18:26:56 -0700 | [diff] [blame] | 692 | dp_parser_put_clk_data(&parser->pdev->dev, &power[i]); |
| 693 | dp_parser_put_vreg_data(&parser->pdev->dev, &power[i]); |
| 694 | dp_parser_put_gpio_data(&parser->pdev->dev, &power[i]); |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 695 | } |
| 696 | |
Samantha Tran | b6a5cd8 | 2018-02-01 14:47:16 -0800 | [diff] [blame] | 697 | dp_parser_clear_io_buf(parser); |
| 698 | devm_kfree(&parser->pdev->dev, parser->io.data); |
Ajay Singh Parmar | 769215f | 2017-03-19 22:35:13 -0700 | [diff] [blame] | 699 | devm_kfree(&parser->pdev->dev, parser); |
| 700 | } |