epwmss@48300000 {
compatible = "ti,am33xx-pwmss";
reg = <0x48300000 0x10>;
ti,hwmods = "epwmss0";
#address-cells = <0x1>;
#size-cells = <0x1>;
status = "okay";
ranges = <0x48300100 0x48300100 0x80 0x48300180 0x48300180 0x80 0x48300200 0x48300200 0x80>;
ecap@48300100 {
compatible = "ti,am3352-ecap", "ti,am33xx-ecap";
#pwm-cells = <0x3>;
reg = <0x48300100 0x80>;
clocks = <0x29>;
clock-names = "fck";
interrupts = <0x1f>;
interrupt-names = "ecap0";
status = "disabled";
};
pwm@48300200 {
compatible = "ti,am3352-ehrpwm", "ti,am33xx-ehrpwm";
#pwm-cells = <0x3>;
reg = <0x48300200 0x80>;
clocks = <0x49 0x29>;
clock-names = "tbclk", "fck";
status = "okay";
pinctrl-names = "default";
pinctrl-0 = <0x4a 0x4b>;
phandle = <0x5b>;
};
};
linux-rt-4.14.79\drivers\pwm\pwm-tipwmss.c
25 static const struct of_device_id pwmss_of_match[] = {
26 { .compatible = "ti,am33xx-pwmss" },
27 {},
28 };
29 MODULE_DEVICE_TABLE(of, pwmss_of_match);
30
31 static int pwmss_probe(struct platform_device *pdev)
32 {
33 int ret;
34 struct device_node *node = pdev->dev.of_node;
35
36 pm_runtime_enable(&pdev->dev);
37
38 /* Populate all the child nodes here... */
39 ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
40 if (ret)
41 dev_err(&pdev->dev, "no child node found\n");
42
43 return ret;
44 }
39行运行: 39 ret = of_platform_populate(node, NULL, NULL, &pdev->dev);
接收解析子节点,这里不细分了
运行子节点驱动
598 ehrpwm_pwm_resume);
599
600 static struct platform_driver ehrpwm_pwm_driver = {
601 .driver = {
602 .name = "ehrpwm",
603 .of_match_table = ehrpwm_of_match,
604 .pm = &ehrpwm_pwm_pm_ops,
605 },
606 .probe = ehrpwm_pwm_probe,
607 .remove = ehrpwm_pwm_remove,
608 };
609 module_platform_driver(ehrpwm_pwm_driver);
610
611 MODULE_DESCRIPTION("EHRPWM PWM driver");
612 MODULE_AUTHOR("Texas Instruments");
613 MODULE_LICENSE("GPL");
436 static const struct of_device_id ehrpwm_of_match[] = {
437 { .compatible = "ti,am3352-ehrpwm" },
438 { .compatible = "ti,am33xx-ehrpwm" },
439 {},
440 };
441 MODULE_DEVICE_TABLE(of, ehrpwm_of_match);
匹配后运行probe
443 static int ehrpwm_pwm_probe(struct platform_device *pdev)
444 {
445 struct device_node *np = pdev->dev.of_node;
446 struct ehrpwm_pwm_chip *pc;
447 struct resource *r;
448 struct clk *clk;
449 int ret;
450
451 pc = devm_kzalloc(&pdev->dev, sizeof(*pc), GFP_KERNEL);
452 if (!pc)
453 return -ENOMEM;
454
455 clk = devm_clk_get(&pdev->dev, "fck");
456 if (IS_ERR(clk)) {
457 if (of_device_is_compatible(np, "ti,am33xx-ecap")) {
458 dev_warn(&pdev->dev, "Binding is obsolete.\n");
459 clk = devm_clk_get(pdev->dev.parent, "fck");
460 }
461 }
462
463 if (IS_ERR(clk)) {
464 dev_err(&pdev->dev, "failed to get clock\n");
465 return PTR_ERR(clk);
466 }
467
468 pc->clk_rate = clk_get_rate(clk);
469 if (!pc->clk_rate) {
470 dev_err(&pdev->dev, "failed to get clock rate\n");
471 return -EINVAL;
472 }
473
474 pc->chip.dev = &pdev->dev;
475 pc->chip.ops = &ehrpwm_pwm_ops;
476 pc->chip.of_xlate = of_pwm_xlate_with_flags;
477 pc->chip.of_pwm_n_cells = 3;
478 pc->chip.base = -1;
479 pc->chip.npwm = NUM_PWM_CHANNEL;
480
481 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
482 pc->mmio_base = devm_ioremap_resource(&pdev->dev, r);
483 if (IS_ERR(pc->mmio_base))
484 return PTR_ERR(pc->mmio_base);
485
486 /* Acquire tbclk for Time Base EHRPWM submodule */
487 pc->tbclk = devm_clk_get(&pdev->dev, "tbclk");
488 if (IS_ERR(pc->tbclk)) {
489 dev_err(&pdev->dev, "Failed to get tbclk\n");
490 return PTR_ERR(pc->tbclk);
491 }
492
493 ret = clk_prepare(pc->tbclk);
494 if (ret < 0) {
495 dev_err(&pdev->dev, "clk_prepare() failed: %d\n", ret);
496 return ret;
497 }
498
499 ret = pwmchip_add(&pc->chip);
500 if (ret < 0) {
501 dev_err(&pdev->dev, "pwmchip_add() failed: %d\n", ret);
502 goto err_clk_unprepare;
503 }
504
505 platform_set_drvdata(pdev, pc);
506 pm_runtime_enable(&pdev->dev);
507
508 return 0;
509
510 err_clk_unprepare:
511 clk_unprepare(pc->tbclk);
512
513 return ret;
514 }
515
这个函数运行获取时钟,设置频率,注册操作函数
427 static const struct pwm_ops ehrpwm_pwm_ops = {
428 .free = ehrpwm_pwm_free,
429 .config = ehrpwm_pwm_config,
430 .set_polarity = ehrpwm_pwm_set_polarity,
431 .enable = ehrpwm_pwm_enable,
432 .disable = ehrpwm_pwm_disable,
433 .owner = THIS_MODULE,
434 };