Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Realtek RTD129x RTC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2017 Andreas Färber
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of_address.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define RTD_RTCSEC		0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define RTD_RTCMIN		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define RTD_RTCHR		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define RTD_RTCDATE1		0x0c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define RTD_RTCDATE2		0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define RTD_RTCACR		0x28
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define RTD_RTCEN		0x2c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define RTD_RTCCR		0x30
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define RTD_RTCSEC_RTCSEC_MASK		0x7f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define RTD_RTCMIN_RTCMIN_MASK		0x3f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define RTD_RTCHR_RTCHR_MASK		0x1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define RTD_RTCDATE1_RTCDATE1_MASK	0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define RTD_RTCDATE2_RTCDATE2_MASK	0x7f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define RTD_RTCACR_RTCPWR		BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define RTD_RTCEN_RTCEN_MASK		0xff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define RTD_RTCCR_RTCRST		BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) struct rtd119x_rtc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	void __iomem *base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	struct clk *clk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct rtc_device *rtcdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	unsigned int base_year;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static inline int rtd119x_rtc_days_in_year(int year)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	return 365 + (is_leap_year(year) ? 1 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static void rtd119x_rtc_reset(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct rtd119x_rtc *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	val = readl_relaxed(data->base + RTD_RTCCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	val |= RTD_RTCCR_RTCRST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	writel_relaxed(val, data->base + RTD_RTCCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	val &= ~RTD_RTCCR_RTCRST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	writel(val, data->base + RTD_RTCCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static void rtd119x_rtc_set_enabled(struct device *dev, bool enable)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	struct rtd119x_rtc *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	val = readl_relaxed(data->base + RTD_RTCEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	if (enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		if ((val & RTD_RTCEN_RTCEN_MASK) == 0x5a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		writel_relaxed(0x5a, data->base + RTD_RTCEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		writel_relaxed(0, data->base + RTD_RTCEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) static int rtd119x_rtc_read_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	struct rtd119x_rtc *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	s32 day;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	u32 sec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	unsigned int year;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	int tries = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	while (true) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		tm->tm_sec = (readl_relaxed(data->base + RTD_RTCSEC) & RTD_RTCSEC_RTCSEC_MASK) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		tm->tm_min  = readl_relaxed(data->base + RTD_RTCMIN) & RTD_RTCMIN_RTCMIN_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		tm->tm_hour = readl_relaxed(data->base + RTD_RTCHR) & RTD_RTCHR_RTCHR_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		day  =  readl_relaxed(data->base + RTD_RTCDATE1) & RTD_RTCDATE1_RTCDATE1_MASK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		day |= (readl_relaxed(data->base + RTD_RTCDATE2) & RTD_RTCDATE2_RTCDATE2_MASK) << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		sec  = (readl_relaxed(data->base + RTD_RTCSEC) & RTD_RTCSEC_RTCSEC_MASK) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		tries++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		if (sec == tm->tm_sec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		if (tries >= 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	if (tries > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		dev_dbg(dev, "%s: needed %i tries\n", __func__, tries);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	year = data->base_year;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	while (day >= rtd119x_rtc_days_in_year(year)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 		day -= rtd119x_rtc_days_in_year(year);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		year++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	tm->tm_year = year - 1900;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	tm->tm_yday = day;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	tm->tm_mon = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	while (day >= rtc_month_days(tm->tm_mon, year)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		day -= rtc_month_days(tm->tm_mon, year);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		tm->tm_mon++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	tm->tm_mday = day + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static int rtd119x_rtc_set_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	struct rtd119x_rtc *data = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	unsigned int day;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (1900 + tm->tm_year < data->base_year)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	day = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	for (i = data->base_year; i < 1900 + tm->tm_year; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		day += rtd119x_rtc_days_in_year(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	day += tm->tm_yday;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (day > 0x7fff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	rtd119x_rtc_set_enabled(dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	writel_relaxed((tm->tm_sec << 1) & RTD_RTCSEC_RTCSEC_MASK, data->base + RTD_RTCSEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	writel_relaxed(tm->tm_min & RTD_RTCMIN_RTCMIN_MASK, data->base + RTD_RTCMIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	writel_relaxed(tm->tm_hour & RTD_RTCHR_RTCHR_MASK, data->base + RTD_RTCHR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	writel_relaxed(day & RTD_RTCDATE1_RTCDATE1_MASK, data->base + RTD_RTCDATE1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	writel_relaxed((day >> 8) & RTD_RTCDATE2_RTCDATE2_MASK, data->base + RTD_RTCDATE2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	rtd119x_rtc_set_enabled(dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static const struct rtc_class_ops rtd119x_rtc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	.read_time	= rtd119x_rtc_read_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	.set_time	= rtd119x_rtc_set_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static const struct of_device_id rtd119x_rtc_dt_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	 { .compatible = "realtek,rtd1295-rtc" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	 { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int rtd119x_rtc_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct rtd119x_rtc *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (!data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	platform_set_drvdata(pdev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	data->base_year = 2014;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	data->base = devm_platform_ioremap_resource(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	if (IS_ERR(data->base))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		return PTR_ERR(data->base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	data->clk = of_clk_get(pdev->dev.of_node, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (IS_ERR(data->clk))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		return PTR_ERR(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	ret = clk_prepare_enable(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		clk_put(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	val = readl_relaxed(data->base + RTD_RTCACR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (!(val & RTD_RTCACR_RTCPWR)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		writel_relaxed(RTD_RTCACR_RTCPWR, data->base + RTD_RTCACR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		rtd119x_rtc_reset(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		writel_relaxed(0, data->base + RTD_RTCMIN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		writel_relaxed(0, data->base + RTD_RTCHR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		writel_relaxed(0, data->base + RTD_RTCDATE1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		writel_relaxed(0, data->base + RTD_RTCDATE2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	rtd119x_rtc_set_enabled(&pdev->dev, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	data->rtcdev = devm_rtc_device_register(&pdev->dev, "rtc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 						&rtd119x_rtc_ops, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	if (IS_ERR(data->rtcdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		dev_err(&pdev->dev, "failed to register rtc device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		clk_disable_unprepare(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		clk_put(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		return PTR_ERR(data->rtcdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static int rtd119x_rtc_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	struct rtd119x_rtc *data = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	rtd119x_rtc_set_enabled(&pdev->dev, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	clk_disable_unprepare(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	clk_put(data->clk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static struct platform_driver rtd119x_rtc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	.probe = rtd119x_rtc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	.remove = rtd119x_rtc_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		.name = "rtd1295-rtc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		.of_match_table	= rtd119x_rtc_dt_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) builtin_platform_driver(rtd119x_rtc_driver);