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) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * rtc-as3722.c - Real Time Clock driver for ams AS3722 PMICs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2013 ams AG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2013, NVIDIA Corporation. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * Author: Florian Lobmaier <florian.lobmaier@ams.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Author: Laxman Dewangan <ldewangan@nvidia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/bcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/completion.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mfd/as3722.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define AS3722_RTC_START_YEAR	  2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct as3722_rtc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct rtc_device	*rtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	struct device		*dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct as3722		*as3722;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	int			alarm_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	bool			irq_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static void as3722_time_to_reg(u8 *rbuff, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	rbuff[0] = bin2bcd(tm->tm_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	rbuff[1] = bin2bcd(tm->tm_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	rbuff[2] = bin2bcd(tm->tm_hour);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	rbuff[3] = bin2bcd(tm->tm_mday);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	rbuff[4] = bin2bcd(tm->tm_mon + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	rbuff[5] = bin2bcd(tm->tm_year - (AS3722_RTC_START_YEAR - 1900));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) static void as3722_reg_to_time(u8 *rbuff, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	tm->tm_sec = bcd2bin(rbuff[0] & 0x7F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	tm->tm_min = bcd2bin(rbuff[1] & 0x7F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	tm->tm_hour = bcd2bin(rbuff[2] & 0x3F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	tm->tm_mday = bcd2bin(rbuff[3] & 0x3F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	tm->tm_mon = bcd2bin(rbuff[4] & 0x1F) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	tm->tm_year = (AS3722_RTC_START_YEAR - 1900) + bcd2bin(rbuff[5] & 0x7F);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static int as3722_rtc_read_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct as3722 *as3722 = as3722_rtc->as3722;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	u8 as_time_array[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	ret = as3722_block_read(as3722, AS3722_RTC_SECOND_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 			6, as_time_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		dev_err(dev, "RTC_SECOND reg block read failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	as3722_reg_to_time(as_time_array, tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static int as3722_rtc_set_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct as3722 *as3722 = as3722_rtc->as3722;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	u8 as_time_array[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (tm->tm_year < (AS3722_RTC_START_YEAR - 1900))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	as3722_time_to_reg(as_time_array, tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	ret = as3722_block_write(as3722, AS3722_RTC_SECOND_REG, 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 			as_time_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		dev_err(dev, "RTC_SECOND reg block write failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int as3722_rtc_alarm_irq_enable(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		unsigned int enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	if (enabled && !as3722_rtc->irq_enable) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		enable_irq(as3722_rtc->alarm_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		as3722_rtc->irq_enable = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	} else if (!enabled && as3722_rtc->irq_enable)  {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		disable_irq(as3722_rtc->alarm_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		as3722_rtc->irq_enable = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int as3722_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	struct as3722 *as3722 = as3722_rtc->as3722;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	u8 as_time_array[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	ret = as3722_block_read(as3722, AS3722_RTC_ALARM_SECOND_REG, 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 			as_time_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		dev_err(dev, "RTC_ALARM_SECOND block read failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	as3722_reg_to_time(as_time_array, &alrm->time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int as3722_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	struct as3722 *as3722 = as3722_rtc->as3722;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	u8 as_time_array[6];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	if (alrm->time.tm_year < (AS3722_RTC_START_YEAR - 1900))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	ret = as3722_rtc_alarm_irq_enable(dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		dev_err(dev, "Disable RTC alarm failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	as3722_time_to_reg(as_time_array, &alrm->time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	ret = as3722_block_write(as3722, AS3722_RTC_ALARM_SECOND_REG, 6,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 			as_time_array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 		dev_err(dev, "RTC_ALARM_SECOND block write failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (alrm->enabled)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		ret = as3722_rtc_alarm_irq_enable(dev, alrm->enabled);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static irqreturn_t as3722_alarm_irq(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	struct as3722_rtc *as3722_rtc = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	rtc_update_irq(as3722_rtc->rtc, 1, RTC_IRQF | RTC_AF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static const struct rtc_class_ops as3722_rtc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	.read_time = as3722_rtc_read_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	.set_time = as3722_rtc_set_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	.read_alarm = as3722_rtc_read_alarm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	.set_alarm = as3722_rtc_set_alarm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	.alarm_irq_enable = as3722_rtc_alarm_irq_enable,
^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 as3722_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 as3722 *as3722 = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	struct as3722_rtc *as3722_rtc;
^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) 	as3722_rtc = devm_kzalloc(&pdev->dev, sizeof(*as3722_rtc), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	if (!as3722_rtc)
^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) 	as3722_rtc->as3722 = as3722;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	as3722_rtc->dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	platform_set_drvdata(pdev, as3722_rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	/* Enable the RTC to make sure it is running. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	ret = as3722_update_bits(as3722, AS3722_RTC_CONTROL_REG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			AS3722_RTC_ON | AS3722_RTC_ALARM_WAKEUP_EN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			AS3722_RTC_ON | AS3722_RTC_ALARM_WAKEUP_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 		dev_err(&pdev->dev, "RTC_CONTROL reg write failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	device_init_wakeup(&pdev->dev, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	as3722_rtc->rtc = devm_rtc_device_register(&pdev->dev, "as3722-rtc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 				&as3722_rtc_ops, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	if (IS_ERR(as3722_rtc->rtc)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		ret = PTR_ERR(as3722_rtc->rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		dev_err(&pdev->dev, "RTC register failed: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	as3722_rtc->alarm_irq = platform_get_irq(pdev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 	dev_info(&pdev->dev, "RTC interrupt %d\n", as3722_rtc->alarm_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	ret = devm_request_threaded_irq(&pdev->dev, as3722_rtc->alarm_irq, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 			as3722_alarm_irq, IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 			"rtc-alarm", as3722_rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		dev_err(&pdev->dev, "Failed to request alarm IRQ %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 				as3722_rtc->alarm_irq, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	disable_irq(as3722_rtc->alarm_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static int as3722_rtc_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 		enable_irq_wake(as3722_rtc->alarm_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static int as3722_rtc_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct as3722_rtc *as3722_rtc = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (device_may_wakeup(dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		disable_irq_wake(as3722_rtc->alarm_irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static SIMPLE_DEV_PM_OPS(as3722_rtc_pm_ops, as3722_rtc_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			 as3722_rtc_resume);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) static struct platform_driver as3722_rtc_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	.probe = as3722_rtc_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		.name = "as3722-rtc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 		.pm = &as3722_rtc_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) module_platform_driver(as3722_rtc_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) MODULE_DESCRIPTION("RTC driver for AS3722 PMICs");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) MODULE_ALIAS("platform:as3722-rtc");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) MODULE_AUTHOR("Florian Lobmaier <florian.lobmaier@ams.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) MODULE_LICENSE("GPL");