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

ptp_qoriq: convert to use ptp_qoriq_init/free

Moved QorIQ PTP clock initialization/free into new functions
ptp_qoriq_init()/ptp_qoriq_free(). These functions could also
be reused by ENETC PTP drvier which is a PCI driver for same
1588 timer IP block.

Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Yangbo Lu and committed by
David S. Miller
ff54571a 73356e4e

+80 -67
+77 -67
drivers/ptp/ptp_qoriq.c
··· 458 458 return 0; 459 459 } 460 460 461 - static int ptp_qoriq_probe(struct platform_device *dev) 461 + int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base, 462 + const struct ptp_clock_info caps) 462 463 { 463 - struct device_node *node = dev->dev.of_node; 464 - struct ptp_qoriq *ptp_qoriq; 464 + struct device_node *node = ptp_qoriq->dev->of_node; 465 465 struct ptp_qoriq_registers *regs; 466 466 struct timespec64 now; 467 - int err = -ENOMEM; 468 - u32 tmr_ctrl; 469 467 unsigned long flags; 470 - void __iomem *base; 468 + u32 tmr_ctrl; 471 469 472 - ptp_qoriq = kzalloc(sizeof(*ptp_qoriq), GFP_KERNEL); 473 - if (!ptp_qoriq) 474 - goto no_memory; 475 - 476 - err = -EINVAL; 477 - 478 - ptp_qoriq->dev = &dev->dev; 479 - ptp_qoriq->caps = ptp_qoriq_caps; 470 + ptp_qoriq->base = base; 471 + ptp_qoriq->caps = caps; 480 472 481 473 if (of_property_read_u32(node, "fsl,cksel", &ptp_qoriq->cksel)) 482 474 ptp_qoriq->cksel = DEFAULT_CKSEL; ··· 493 501 pr_warn("device tree node missing required elements, try automatic configuration\n"); 494 502 495 503 if (ptp_qoriq_auto_config(ptp_qoriq, node)) 496 - goto no_config; 504 + return -ENODEV; 497 505 } 498 - 499 - err = -ENODEV; 500 - 501 - ptp_qoriq->irq = platform_get_irq(dev, 0); 502 - 503 - if (ptp_qoriq->irq < 0) { 504 - pr_err("irq not in device tree\n"); 505 - goto no_node; 506 - } 507 - if (request_irq(ptp_qoriq->irq, ptp_qoriq_isr, IRQF_SHARED, 508 - DRIVER, ptp_qoriq)) { 509 - pr_err("request_irq failed\n"); 510 - goto no_node; 511 - } 512 - 513 - ptp_qoriq->rsrc = platform_get_resource(dev, IORESOURCE_MEM, 0); 514 - if (!ptp_qoriq->rsrc) { 515 - pr_err("no resource\n"); 516 - goto no_resource; 517 - } 518 - if (request_resource(&iomem_resource, ptp_qoriq->rsrc)) { 519 - pr_err("resource busy\n"); 520 - goto no_resource; 521 - } 522 - 523 - spin_lock_init(&ptp_qoriq->lock); 524 - 525 - base = ioremap(ptp_qoriq->rsrc->start, 526 - resource_size(ptp_qoriq->rsrc)); 527 - if (!base) { 528 - pr_err("ioremap ptp registers failed\n"); 529 - goto no_ioremap; 530 - } 531 - 532 - ptp_qoriq->base = base; 533 506 534 507 if (of_device_is_compatible(node, "fsl,fman-ptp-timer")) { 535 508 ptp_qoriq->regs.ctrl_regs = base + FMAN_CTRL_REGS_OFFSET; ··· 515 558 (ptp_qoriq->tclk_period & TCLK_PERIOD_MASK) << TCLK_PERIOD_SHIFT | 516 559 (ptp_qoriq->cksel & CKSEL_MASK) << CKSEL_SHIFT; 517 560 561 + spin_lock_init(&ptp_qoriq->lock); 518 562 spin_lock_irqsave(&ptp_qoriq->lock, flags); 519 563 520 564 regs = &ptp_qoriq->regs; ··· 529 571 530 572 spin_unlock_irqrestore(&ptp_qoriq->lock, flags); 531 573 532 - ptp_qoriq->clock = ptp_clock_register(&ptp_qoriq->caps, &dev->dev); 533 - if (IS_ERR(ptp_qoriq->clock)) { 534 - err = PTR_ERR(ptp_qoriq->clock); 535 - goto no_clock; 536 - } 574 + ptp_qoriq->clock = ptp_clock_register(&ptp_qoriq->caps, ptp_qoriq->dev); 575 + if (IS_ERR(ptp_qoriq->clock)) 576 + return PTR_ERR(ptp_qoriq->clock); 577 + 537 578 ptp_qoriq->phc_index = ptp_clock_index(ptp_qoriq->clock); 538 - 539 579 ptp_qoriq_create_debugfs(ptp_qoriq); 540 - platform_set_drvdata(dev, ptp_qoriq); 580 + return 0; 581 + } 582 + EXPORT_SYMBOL_GPL(ptp_qoriq_init); 541 583 584 + void ptp_qoriq_free(struct ptp_qoriq *ptp_qoriq) 585 + { 586 + struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 587 + 588 + qoriq_write(&regs->ctrl_regs->tmr_temask, 0); 589 + qoriq_write(&regs->ctrl_regs->tmr_ctrl, 0); 590 + 591 + ptp_qoriq_remove_debugfs(ptp_qoriq); 592 + ptp_clock_unregister(ptp_qoriq->clock); 593 + iounmap(ptp_qoriq->base); 594 + free_irq(ptp_qoriq->irq, ptp_qoriq); 595 + } 596 + EXPORT_SYMBOL_GPL(ptp_qoriq_free); 597 + 598 + static int ptp_qoriq_probe(struct platform_device *dev) 599 + { 600 + struct ptp_qoriq *ptp_qoriq; 601 + int err = -ENOMEM; 602 + void __iomem *base; 603 + 604 + ptp_qoriq = kzalloc(sizeof(*ptp_qoriq), GFP_KERNEL); 605 + if (!ptp_qoriq) 606 + goto no_memory; 607 + 608 + ptp_qoriq->dev = &dev->dev; 609 + 610 + err = -ENODEV; 611 + 612 + ptp_qoriq->irq = platform_get_irq(dev, 0); 613 + if (ptp_qoriq->irq < 0) { 614 + pr_err("irq not in device tree\n"); 615 + goto no_node; 616 + } 617 + if (request_irq(ptp_qoriq->irq, ptp_qoriq_isr, IRQF_SHARED, 618 + DRIVER, ptp_qoriq)) { 619 + pr_err("request_irq failed\n"); 620 + goto no_node; 621 + } 622 + 623 + ptp_qoriq->rsrc = platform_get_resource(dev, IORESOURCE_MEM, 0); 624 + if (!ptp_qoriq->rsrc) { 625 + pr_err("no resource\n"); 626 + goto no_resource; 627 + } 628 + if (request_resource(&iomem_resource, ptp_qoriq->rsrc)) { 629 + pr_err("resource busy\n"); 630 + goto no_resource; 631 + } 632 + 633 + base = ioremap(ptp_qoriq->rsrc->start, 634 + resource_size(ptp_qoriq->rsrc)); 635 + if (!base) { 636 + pr_err("ioremap ptp registers failed\n"); 637 + goto no_ioremap; 638 + } 639 + 640 + err = ptp_qoriq_init(ptp_qoriq, base, ptp_qoriq_caps); 641 + if (err) 642 + goto no_clock; 643 + 644 + platform_set_drvdata(dev, ptp_qoriq); 542 645 return 0; 543 646 544 647 no_clock: ··· 608 589 release_resource(ptp_qoriq->rsrc); 609 590 no_resource: 610 591 free_irq(ptp_qoriq->irq, ptp_qoriq); 611 - no_config: 612 592 no_node: 613 593 kfree(ptp_qoriq); 614 594 no_memory: ··· 617 599 static int ptp_qoriq_remove(struct platform_device *dev) 618 600 { 619 601 struct ptp_qoriq *ptp_qoriq = platform_get_drvdata(dev); 620 - struct ptp_qoriq_registers *regs = &ptp_qoriq->regs; 621 602 622 - qoriq_write(&regs->ctrl_regs->tmr_temask, 0); 623 - qoriq_write(&regs->ctrl_regs->tmr_ctrl, 0); 624 - 625 - ptp_qoriq_remove_debugfs(ptp_qoriq); 626 - ptp_clock_unregister(ptp_qoriq->clock); 627 - iounmap(ptp_qoriq->base); 603 + ptp_qoriq_free(ptp_qoriq); 628 604 release_resource(ptp_qoriq->rsrc); 629 - free_irq(ptp_qoriq->irq, ptp_qoriq); 630 605 kfree(ptp_qoriq); 631 - 632 606 return 0; 633 607 } 634 608
+3
include/linux/fsl/ptp_qoriq.h
··· 173 173 } 174 174 175 175 irqreturn_t ptp_qoriq_isr(int irq, void *priv); 176 + int ptp_qoriq_init(struct ptp_qoriq *ptp_qoriq, void __iomem *base, 177 + const struct ptp_clock_info caps); 178 + void ptp_qoriq_free(struct ptp_qoriq *ptp_qoriq); 176 179 int ptp_qoriq_adjfine(struct ptp_clock_info *ptp, long scaled_ppm); 177 180 int ptp_qoriq_adjtime(struct ptp_clock_info *ptp, s64 delta); 178 181 int ptp_qoriq_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts);