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

Configure Feed

Select the types of activity you want to include in your feed.

usb: dwc3: dwc3-octeon: Move node parsing into driver probe

Parse and verify device tree node first, then setup UCTL bridge
using verified values. This avoids needless allocations
in case DT misconfiguration was found in the middle of setup.

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
Link: https://lore.kernel.org/r/ZMd/x3MHA4/QowMO@lenoch
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Ladislav Michl and committed by
Greg Kroah-Hartman
dc0092ce c6110163

+60 -75
+60 -75
drivers/usb/dwc3/dwc3-octeon.c
··· 261 261 } 262 262 263 263 static int dwc3_octeon_setup(struct dwc3_octeon *octeon, 264 + int ref_clk_sel, int ref_clk_fsel, int mpll_mul, 264 265 int power_gpio, int power_active_low) 265 266 { 266 - int i, div, mpll_mul, ref_clk_fsel, ref_clk_sel = 2; 267 - u32 clock_rate; 268 267 u64 val; 268 + int div; 269 269 struct device *dev = octeon->dev; 270 270 void __iomem *uctl_ctl_reg = octeon->base + USBDRD_UCTL_CTL; 271 271 void __iomem *uctl_host_cfg_reg = octeon->base + USBDRD_UCTL_HOST_CFG; 272 - 273 - if (dev->of_node) { 274 - const char *ss_clock_type; 275 - const char *hs_clock_type; 276 - 277 - i = of_property_read_u32(dev->of_node, 278 - "refclk-frequency", &clock_rate); 279 - if (i) { 280 - dev_err(dev, "No UCTL \"refclk-frequency\"\n"); 281 - return -EINVAL; 282 - } 283 - i = of_property_read_string(dev->of_node, 284 - "refclk-type-ss", &ss_clock_type); 285 - if (i) { 286 - dev_err(dev, "No UCTL \"refclk-type-ss\"\n"); 287 - return -EINVAL; 288 - } 289 - i = of_property_read_string(dev->of_node, 290 - "refclk-type-hs", &hs_clock_type); 291 - if (i) { 292 - dev_err(dev, "No UCTL \"refclk-type-hs\"\n"); 293 - return -EINVAL; 294 - } 295 - if (strcmp("dlmc_ref_clk0", ss_clock_type) == 0) { 296 - if (strcmp(hs_clock_type, "dlmc_ref_clk0") == 0) 297 - ref_clk_sel = 0; 298 - else if (strcmp(hs_clock_type, "pll_ref_clk") == 0) 299 - ref_clk_sel = 2; 300 - else 301 - dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 302 - hs_clock_type); 303 - } else if (strcmp(ss_clock_type, "dlmc_ref_clk1") == 0) { 304 - if (strcmp(hs_clock_type, "dlmc_ref_clk1") == 0) 305 - ref_clk_sel = 1; 306 - else if (strcmp(hs_clock_type, "pll_ref_clk") == 0) 307 - ref_clk_sel = 3; 308 - else { 309 - dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 310 - hs_clock_type); 311 - ref_clk_sel = 3; 312 - } 313 - } else 314 - dev_warn(dev, "Invalid SS clock type %s, using dlmc_ref_clk0 instead\n", 315 - ss_clock_type); 316 - 317 - if ((ref_clk_sel == 0 || ref_clk_sel == 1) && 318 - (clock_rate != 100000000)) 319 - dev_warn(dev, "Invalid UCTL clock rate of %u, using 100000000 instead\n", 320 - clock_rate); 321 - 322 - } else { 323 - dev_err(dev, "No USB UCTL device node\n"); 324 - return -EINVAL; 325 - } 326 272 327 273 /* 328 274 * Step 1: Wait for all voltages to be stable...that surely ··· 313 367 val &= ~USBDRD_UCTL_CTL_REF_CLK_SEL; 314 368 val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_SEL, ref_clk_sel); 315 369 316 - ref_clk_fsel = 0x07; 317 - switch (clock_rate) { 318 - default: 319 - dev_warn(dev, "Invalid ref_clk %u, using 100000000 instead\n", 320 - clock_rate); 321 - fallthrough; 322 - case 100000000: 323 - mpll_mul = 0x19; 324 - if (ref_clk_sel < 2) 325 - ref_clk_fsel = 0x27; 326 - break; 327 - case 50000000: 328 - mpll_mul = 0x32; 329 - break; 330 - case 125000000: 331 - mpll_mul = 0x28; 332 - break; 333 - } 334 370 val &= ~USBDRD_UCTL_CTL_REF_CLK_FSEL; 335 371 val |= FIELD_PREP(USBDRD_UCTL_CTL_REF_CLK_FSEL, ref_clk_fsel); 336 372 ··· 411 483 struct device *dev = &pdev->dev; 412 484 struct device_node *node = dev->of_node; 413 485 struct dwc3_octeon *octeon; 486 + const char *hs_clock_type, *ss_clock_type; 487 + int ref_clk_sel, ref_clk_fsel, mpll_mul; 414 488 int power_active_low, power_gpio; 415 489 int err, len; 490 + u32 clock_rate; 491 + 492 + if (of_property_read_u32(node, "refclk-frequency", &clock_rate)) { 493 + dev_err(dev, "No UCTL \"refclk-frequency\"\n"); 494 + return -EINVAL; 495 + } 496 + if (of_property_read_string(node, "refclk-type-ss", &ss_clock_type)) { 497 + dev_err(dev, "No UCTL \"refclk-type-ss\"\n"); 498 + return -EINVAL; 499 + } 500 + if (of_property_read_string(node, "refclk-type-hs", &hs_clock_type)) { 501 + dev_err(dev, "No UCTL \"refclk-type-hs\"\n"); 502 + return -EINVAL; 503 + } 504 + 505 + ref_clk_sel = 2; 506 + if (strcmp("dlmc_ref_clk0", ss_clock_type) == 0) { 507 + if (strcmp(hs_clock_type, "dlmc_ref_clk0") == 0) 508 + ref_clk_sel = 0; 509 + else if (strcmp(hs_clock_type, "pll_ref_clk")) 510 + dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 511 + hs_clock_type); 512 + } else if (strcmp(ss_clock_type, "dlmc_ref_clk1") == 0) { 513 + if (strcmp(hs_clock_type, "dlmc_ref_clk1") == 0) { 514 + ref_clk_sel = 1; 515 + } else { 516 + ref_clk_sel = 3; 517 + if (strcmp(hs_clock_type, "pll_ref_clk")) 518 + dev_warn(dev, "Invalid HS clock type %s, using pll_ref_clk instead\n", 519 + hs_clock_type); 520 + } 521 + } else { 522 + dev_warn(dev, "Invalid SS clock type %s, using dlmc_ref_clk0 instead\n", 523 + ss_clock_type); 524 + } 525 + 526 + ref_clk_fsel = 0x07; 527 + switch (clock_rate) { 528 + default: 529 + dev_warn(dev, "Invalid ref_clk %u, using 100000000 instead\n", 530 + clock_rate); 531 + fallthrough; 532 + case 100000000: 533 + mpll_mul = 0x19; 534 + if (ref_clk_sel < 2) 535 + ref_clk_fsel = 0x27; 536 + break; 537 + case 50000000: 538 + mpll_mul = 0x32; 539 + break; 540 + case 125000000: 541 + mpll_mul = 0x28; 542 + break; 543 + } 416 544 417 545 power_gpio = DWC3_GPIO_POWER_NONE; 418 546 power_active_low = 0; ··· 499 515 if (IS_ERR(octeon->base)) 500 516 return PTR_ERR(octeon->base); 501 517 502 - err = dwc3_octeon_setup(octeon, power_gpio, power_active_low); 518 + err = dwc3_octeon_setup(octeon, ref_clk_sel, ref_clk_fsel, mpll_mul, 519 + power_gpio, power_active_low); 503 520 if (err) 504 521 return err; 505 522