On 26/12/2022 10:39:41+0800, Jacky Bai wrote: > +static int bbnsm_rtc_read_time(struct device *dev, struct rtc_time *tm) > +{ > + struct bbnsm_rtc *bbnsm = dev_get_drvdata(dev); > + unsigned long time; > + u32 val; > + > + regmap_read(bbnsm->regmap, BBNSM_CTRL, &val); > + if ((val & RTC_EN_MSK) != RTC_EN) { > + dev_warn(dev, "RTC is not enabled, time is invalid!\n"); I don't think this message is necessary. > + return -EINVAL; > + } > + > + time = bbnsm_read_counter(bbnsm); > + rtc_time64_to_tm(time, tm); > + > + return 0; > +} > + [...] > +static int bbnsm_rtc_probe(struct platform_device *pdev) > +{ > + struct bbnsm_rtc *bbnsm; > + int ret; > + > + bbnsm = devm_kzalloc(&pdev->dev, sizeof(*bbnsm), GFP_KERNEL); > + if (!bbnsm) > + return -ENOMEM; > + > + bbnsm->rtc = devm_rtc_allocate_device(&pdev->dev); > + > + bbnsm->regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "nxp,bbnsm-regmap"); > + if (IS_ERR(bbnsm->regmap)) { > + dev_err(&pdev->dev, "bbnsm get regmap failed\n"); Maybe this should be a dev_dbg? > + return PTR_ERR(bbnsm->regmap); > + } > + > + bbnsm->irq = platform_get_irq(pdev, 0); > + if (bbnsm->irq < 0) > + return bbnsm->irq; > + > + platform_set_drvdata(pdev, bbnsm); > + > + /* clear all the pending events */ > + regmap_write(bbnsm->regmap, BBNSM_EVENTS, 0x7A); > + > + device_init_wakeup(&pdev->dev, true); > + dev_pm_set_wake_irq(&pdev->dev, bbnsm->irq); > + > + ret = devm_request_irq(&pdev->dev, bbnsm->irq, bbnsm_rtc_irq_handler, > + IRQF_SHARED, "rtc alarm", &pdev->dev); > + if (ret) { > + dev_err(&pdev->dev, "failed to request irq %d: %d\n", > + bbnsm->irq, ret); > + return ret; > + } > + > + bbnsm->rtc->ops = &bbnsm_rtc_ops; > + bbnsm->rtc->range_max = U32_MAX; > + > + return devm_rtc_register_device(bbnsm->rtc); > +} > + > +static const struct of_device_id bbnsm_dt_ids[] = { > + { .compatible = "nxp,bbnsm-rtc", }, > + { /* sentinel */ }, > +}; > +MODULE_DEVICE_TABLE(of, bbnsm_dt_ids); > + > +static struct platform_driver bbnsm_rtc_driver = { > + .driver = { > + .name = "bbnsm_rtc", > + .of_match_table = bbnsm_dt_ids, > + }, > + .probe = bbnsm_rtc_probe, > +}; > +module_platform_driver(bbnsm_rtc_driver); > + > +MODULE_AUTHOR("Jacky Bai <ping.bai@xxxxxxx>"); > +MODULE_DESCRIPTION("NXP BBNSM RTC Driver"); > +MODULE_LICENSE("GPL"); > -- > 2.37.1 > -- Alexandre Belloni, co-owner and COO, Bootlin Embedded Linux and Kernel engineering https://bootlin.com