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)  * rtc class driver for the Maxim MAX6900 chip
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Author: Dale Farnsworth <dale@farnsworth.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * based on previously existing rtc class drivers
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * 2007 (c) MontaVista, Software, Inc.  This file is licensed under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * the terms of the GNU General Public License version 2.  This program
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * is licensed "as is" without any warranty of any kind, whether express
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * or implied.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/bcd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/rtc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * register indices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define MAX6900_REG_SC			0	/* seconds      00-59 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define MAX6900_REG_MN			1	/* minutes      00-59 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define MAX6900_REG_HR			2	/* hours        00-23 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define MAX6900_REG_DT			3	/* day of month 00-31 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #define MAX6900_REG_MO			4	/* month        01-12 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define MAX6900_REG_DW			5	/* day of week   1-7  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define MAX6900_REG_YR			6	/* year         00-99 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define MAX6900_REG_CT			7	/* control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 						/* register 8 is undocumented */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define MAX6900_REG_CENTURY		9	/* century */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define MAX6900_REG_LEN			10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define MAX6900_BURST_LEN		8	/* can burst r/w first 8 regs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define MAX6900_REG_CT_WP		(1 << 7)	/* Write Protect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)  * register read/write commands
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define MAX6900_REG_CONTROL_WRITE	0x8e
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define MAX6900_REG_CENTURY_WRITE	0x92
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define MAX6900_REG_CENTURY_READ	0x93
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define MAX6900_REG_RESERVED_READ	0x96
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #define MAX6900_REG_BURST_WRITE		0xbe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define MAX6900_REG_BURST_READ		0xbf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define MAX6900_IDLE_TIME_AFTER_WRITE	3	/* specification says 2.5 mS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static struct i2c_driver max6900_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int max6900_i2c_read_regs(struct i2c_client *client, u8 *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	u8 reg_burst_read[1] = { MAX6900_REG_BURST_READ };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	u8 reg_century_read[1] = { MAX6900_REG_CENTURY_READ };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	struct i2c_msg msgs[4] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		 .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		 .flags = 0,	/* write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		 .len = sizeof(reg_burst_read),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		 .buf = reg_burst_read}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		 .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		 .flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		 .len = MAX6900_BURST_LEN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		 .buf = buf}
^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) 		 .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		 .flags = 0,	/* write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 		 .len = sizeof(reg_century_read),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		 .buf = reg_century_read}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		 .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		 .flags = I2C_M_RD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		 .len = sizeof(buf[MAX6900_REG_CENTURY]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		 .buf = &buf[MAX6900_REG_CENTURY]
^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) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	rc = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (rc != ARRAY_SIZE(msgs)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		dev_err(&client->dev, "%s: register read failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int max6900_i2c_write_regs(struct i2c_client *client, u8 const *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	u8 i2c_century_buf[1 + 1] = { MAX6900_REG_CENTURY_WRITE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	struct i2c_msg century_msgs[1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		 .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		 .flags = 0,	/* write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		 .len = sizeof(i2c_century_buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		 .buf = i2c_century_buf}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	u8 i2c_burst_buf[MAX6900_BURST_LEN + 1] = { MAX6900_REG_BURST_WRITE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct i2c_msg burst_msgs[1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 		{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		 .addr = client->addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		 .flags = 0,	/* write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 		 .len = sizeof(i2c_burst_buf),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 		 .buf = i2c_burst_buf}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	 * We have to make separate calls to i2c_transfer because of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	 * the need to delay after each write to the chip.  Also,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	 * we write the century byte first, since we set the write-protect
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	 * bit as part of the burst write.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	i2c_century_buf[1] = buf[MAX6900_REG_CENTURY];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	rc = i2c_transfer(client->adapter, century_msgs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			  ARRAY_SIZE(century_msgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (rc != ARRAY_SIZE(century_msgs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		goto write_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	memcpy(&i2c_burst_buf[1], buf, MAX6900_BURST_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	rc = i2c_transfer(client->adapter, burst_msgs, ARRAY_SIZE(burst_msgs));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (rc != ARRAY_SIZE(burst_msgs))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		goto write_failed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	msleep(MAX6900_IDLE_TIME_AFTER_WRITE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  write_failed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	dev_err(&client->dev, "%s: register write failed\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int max6900_rtc_read_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	u8 regs[MAX6900_REG_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	rc = max6900_i2c_read_regs(client, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	tm->tm_sec = bcd2bin(regs[MAX6900_REG_SC]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	tm->tm_min = bcd2bin(regs[MAX6900_REG_MN]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	tm->tm_hour = bcd2bin(regs[MAX6900_REG_HR] & 0x3f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	tm->tm_mday = bcd2bin(regs[MAX6900_REG_DT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	tm->tm_mon = bcd2bin(regs[MAX6900_REG_MO]) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	tm->tm_year = bcd2bin(regs[MAX6900_REG_YR]) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		      bcd2bin(regs[MAX6900_REG_CENTURY]) * 100 - 1900;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	tm->tm_wday = bcd2bin(regs[MAX6900_REG_DW]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) static int max6900_i2c_clear_write_protect(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	return i2c_smbus_write_byte_data(client, MAX6900_REG_CONTROL_WRITE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	struct i2c_client *client = to_i2c_client(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	u8 regs[MAX6900_REG_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	rc = max6900_i2c_clear_write_protect(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	regs[MAX6900_REG_SC] = bin2bcd(tm->tm_sec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	regs[MAX6900_REG_MN] = bin2bcd(tm->tm_min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	regs[MAX6900_REG_HR] = bin2bcd(tm->tm_hour);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	regs[MAX6900_REG_DT] = bin2bcd(tm->tm_mday);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	regs[MAX6900_REG_MO] = bin2bcd(tm->tm_mon + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	regs[MAX6900_REG_DW] = bin2bcd(tm->tm_wday);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	regs[MAX6900_REG_YR] = bin2bcd(tm->tm_year % 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	regs[MAX6900_REG_CENTURY] = bin2bcd((tm->tm_year + 1900) / 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	/* set write protect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	regs[MAX6900_REG_CT] = MAX6900_REG_CT_WP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	rc = max6900_i2c_write_regs(client, regs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	if (rc < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static const struct rtc_class_ops max6900_rtc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	.read_time = max6900_rtc_read_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	.set_time = max6900_rtc_set_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) max6900_probe(struct i2c_client *client, const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	struct rtc_device *rtc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	rtc = devm_rtc_device_register(&client->dev, max6900_driver.driver.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 					&max6900_rtc_ops, THIS_MODULE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	if (IS_ERR(rtc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		return PTR_ERR(rtc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	i2c_set_clientdata(client, rtc);
^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 const struct i2c_device_id max6900_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	{ "max6900", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) MODULE_DEVICE_TABLE(i2c, max6900_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) static struct i2c_driver max6900_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		   .name = "rtc-max6900",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		   },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	.probe = max6900_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	.id_table = max6900_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) module_i2c_driver(max6900_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) MODULE_DESCRIPTION("Maxim MAX6900 RTC driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) MODULE_AUTHOR("Dale Farnsworth <dale@farnsworth.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) MODULE_LICENSE("GPL");