Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * I2C client/driver for the ST M41T80 family of i2c rtc chips. |
| 3 | * |
| 4 | * Author: Alexander Bigga <ab@mycable.de> |
| 5 | * |
| 6 | * Based on m41t00.c by Mark A. Greer <mgreer@mvista.com> |
| 7 | * |
| 8 | * 2006 (c) mycable GmbH |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | * |
| 14 | */ |
| 15 | |
Joe Perches | a737e83 | 2015-04-16 12:46:14 -0700 | [diff] [blame] | 16 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 17 | |
Maciej W. Rozycki | 35aa64f | 2008-07-23 21:30:29 -0700 | [diff] [blame] | 18 | #include <linux/bcd.h> |
| 19 | #include <linux/i2c.h> |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
Maciej W. Rozycki | 9fb1f68 | 2008-05-12 14:02:38 -0700 | [diff] [blame] | 21 | #include <linux/kernel.h> |
Maciej W. Rozycki | 35aa64f | 2008-07-23 21:30:29 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/rtc.h> |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 24 | #include <linux/slab.h> |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 25 | #include <linux/mutex.h> |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 26 | #include <linux/string.h> |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 27 | #ifdef CONFIG_RTC_DRV_M41T80_WDT |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 28 | #include <linux/fs.h> |
| 29 | #include <linux/ioctl.h> |
Maciej W. Rozycki | 35aa64f | 2008-07-23 21:30:29 -0700 | [diff] [blame] | 30 | #include <linux/miscdevice.h> |
| 31 | #include <linux/reboot.h> |
| 32 | #include <linux/watchdog.h> |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 33 | #endif |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 34 | |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 35 | #define M41T80_REG_SSEC 0x00 |
| 36 | #define M41T80_REG_SEC 0x01 |
| 37 | #define M41T80_REG_MIN 0x02 |
| 38 | #define M41T80_REG_HOUR 0x03 |
| 39 | #define M41T80_REG_WDAY 0x04 |
| 40 | #define M41T80_REG_DAY 0x05 |
| 41 | #define M41T80_REG_MON 0x06 |
| 42 | #define M41T80_REG_YEAR 0x07 |
| 43 | #define M41T80_REG_ALARM_MON 0x0a |
| 44 | #define M41T80_REG_ALARM_DAY 0x0b |
| 45 | #define M41T80_REG_ALARM_HOUR 0x0c |
| 46 | #define M41T80_REG_ALARM_MIN 0x0d |
| 47 | #define M41T80_REG_ALARM_SEC 0x0e |
| 48 | #define M41T80_REG_FLAGS 0x0f |
| 49 | #define M41T80_REG_SQW 0x13 |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 50 | |
| 51 | #define M41T80_DATETIME_REG_SIZE (M41T80_REG_YEAR + 1) |
| 52 | #define M41T80_ALARM_REG_SIZE \ |
| 53 | (M41T80_REG_ALARM_SEC + 1 - M41T80_REG_ALARM_MON) |
| 54 | |
| 55 | #define M41T80_SEC_ST (1 << 7) /* ST: Stop Bit */ |
| 56 | #define M41T80_ALMON_AFE (1 << 7) /* AFE: AF Enable Bit */ |
| 57 | #define M41T80_ALMON_SQWE (1 << 6) /* SQWE: SQW Enable Bit */ |
| 58 | #define M41T80_ALHOUR_HT (1 << 6) /* HT: Halt Update Bit */ |
| 59 | #define M41T80_FLAGS_AF (1 << 6) /* AF: Alarm Flag Bit */ |
| 60 | #define M41T80_FLAGS_BATT_LOW (1 << 4) /* BL: Battery Low Bit */ |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 61 | #define M41T80_WATCHDOG_RB2 (1 << 7) /* RB: Watchdog resolution */ |
| 62 | #define M41T80_WATCHDOG_RB1 (1 << 1) /* RB: Watchdog resolution */ |
| 63 | #define M41T80_WATCHDOG_RB0 (1 << 0) /* RB: Watchdog resolution */ |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 64 | |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 65 | #define M41T80_FEATURE_HT (1 << 0) /* Halt feature */ |
| 66 | #define M41T80_FEATURE_BL (1 << 1) /* Battery low indicator */ |
| 67 | #define M41T80_FEATURE_SQ (1 << 2) /* Squarewave feature */ |
| 68 | #define M41T80_FEATURE_WD (1 << 3) /* Extra watchdog resolution */ |
Daniel Glockner | f30281f | 2009-04-02 16:57:03 -0700 | [diff] [blame] | 69 | #define M41T80_FEATURE_SQ_ALT (1 << 4) /* RSx bits are in reg 4 */ |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 70 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 71 | static DEFINE_MUTEX(m41t80_rtc_mutex); |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 72 | static const struct i2c_device_id m41t80_id[] = { |
Daniel Glockner | f30281f | 2009-04-02 16:57:03 -0700 | [diff] [blame] | 73 | { "m41t62", M41T80_FEATURE_SQ | M41T80_FEATURE_SQ_ALT }, |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 74 | { "m41t65", M41T80_FEATURE_HT | M41T80_FEATURE_WD }, |
| 75 | { "m41t80", M41T80_FEATURE_SQ }, |
| 76 | { "m41t81", M41T80_FEATURE_HT | M41T80_FEATURE_SQ}, |
| 77 | { "m41t81s", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
| 78 | { "m41t82", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
| 79 | { "m41t83", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
| 80 | { "m41st84", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
| 81 | { "m41st85", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
| 82 | { "m41st87", M41T80_FEATURE_HT | M41T80_FEATURE_BL | M41T80_FEATURE_SQ }, |
Wolfram Sang | 6b1a523 | 2014-06-06 14:35:47 -0700 | [diff] [blame] | 83 | { "rv4162", M41T80_FEATURE_SQ | M41T80_FEATURE_WD | M41T80_FEATURE_SQ_ALT }, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 84 | { } |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 85 | }; |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 86 | MODULE_DEVICE_TABLE(i2c, m41t80_id); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 87 | |
| 88 | struct m41t80_data { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 89 | u8 features; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 90 | struct rtc_device *rtc; |
| 91 | }; |
| 92 | |
| 93 | static int m41t80_get_datetime(struct i2c_client *client, |
| 94 | struct rtc_time *tm) |
| 95 | { |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 96 | unsigned char buf[8]; |
| 97 | int err; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 98 | |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 99 | err = i2c_smbus_read_i2c_block_data(client, M41T80_REG_SSEC, |
| 100 | sizeof(buf), buf); |
| 101 | if (err < 0) { |
| 102 | dev_err(&client->dev, "Unable to read date\n"); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 103 | return -EIO; |
| 104 | } |
| 105 | |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 106 | tm->tm_sec = bcd2bin(buf[M41T80_REG_SEC] & 0x7f); |
| 107 | tm->tm_min = bcd2bin(buf[M41T80_REG_MIN] & 0x7f); |
| 108 | tm->tm_hour = bcd2bin(buf[M41T80_REG_HOUR] & 0x3f); |
| 109 | tm->tm_mday = bcd2bin(buf[M41T80_REG_DAY] & 0x3f); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 110 | tm->tm_wday = buf[M41T80_REG_WDAY] & 0x07; |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 111 | tm->tm_mon = bcd2bin(buf[M41T80_REG_MON] & 0x1f) - 1; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 112 | |
| 113 | /* assume 20YY not 19YY, and ignore the Century Bit */ |
Adrian Bunk | fe20ba7 | 2008-10-18 20:28:41 -0700 | [diff] [blame] | 114 | tm->tm_year = bcd2bin(buf[M41T80_REG_YEAR]) + 100; |
Wan ZongShun | b485fe5 | 2010-08-10 18:02:15 -0700 | [diff] [blame] | 115 | return rtc_valid_tm(tm); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* Sets the given date and time to the real time clock. */ |
| 119 | static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm) |
| 120 | { |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 121 | unsigned char buf[8]; |
| 122 | int err; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 123 | |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 124 | if (tm->tm_year < 100 || tm->tm_year > 199) |
Stefan Christ | bcebd81 | 2016-03-15 14:22:26 +0100 | [diff] [blame] | 125 | return -EINVAL; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 126 | |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 127 | buf[M41T80_REG_SSEC] = 0; |
| 128 | buf[M41T80_REG_SEC] = bin2bcd(tm->tm_sec); |
| 129 | buf[M41T80_REG_MIN] = bin2bcd(tm->tm_min); |
| 130 | buf[M41T80_REG_HOUR] = bin2bcd(tm->tm_hour); |
| 131 | buf[M41T80_REG_DAY] = bin2bcd(tm->tm_mday); |
| 132 | buf[M41T80_REG_MON] = bin2bcd(tm->tm_mon + 1); |
| 133 | buf[M41T80_REG_YEAR] = bin2bcd(tm->tm_year - 100); |
| 134 | buf[M41T80_REG_WDAY] = tm->tm_wday; |
| 135 | |
| 136 | err = i2c_smbus_write_i2c_block_data(client, M41T80_REG_SSEC, |
| 137 | sizeof(buf), buf); |
| 138 | if (err < 0) { |
| 139 | dev_err(&client->dev, "Unable to write to date registers\n"); |
| 140 | return err; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 141 | } |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 142 | |
| 143 | return err; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 146 | static int m41t80_rtc_proc(struct device *dev, struct seq_file *seq) |
| 147 | { |
| 148 | struct i2c_client *client = to_i2c_client(dev); |
| 149 | struct m41t80_data *clientdata = i2c_get_clientdata(client); |
| 150 | u8 reg; |
| 151 | |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 152 | if (clientdata->features & M41T80_FEATURE_BL) { |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 153 | reg = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS); |
| 154 | seq_printf(seq, "battery\t\t: %s\n", |
| 155 | (reg & M41T80_FLAGS_BATT_LOW) ? "exhausted" : "ok"); |
| 156 | } |
| 157 | return 0; |
| 158 | } |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 159 | |
| 160 | static int m41t80_rtc_read_time(struct device *dev, struct rtc_time *tm) |
| 161 | { |
| 162 | return m41t80_get_datetime(to_i2c_client(dev), tm); |
| 163 | } |
| 164 | |
| 165 | static int m41t80_rtc_set_time(struct device *dev, struct rtc_time *tm) |
| 166 | { |
| 167 | return m41t80_set_datetime(to_i2c_client(dev), tm); |
| 168 | } |
| 169 | |
Paul Bolle | 48e9766 | 2012-10-04 17:14:35 -0700 | [diff] [blame] | 170 | /* |
| 171 | * XXX - m41t80 alarm functionality is reported broken. |
| 172 | * until it is fixed, don't register alarm functions. |
| 173 | */ |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 174 | static struct rtc_class_ops m41t80_rtc_ops = { |
| 175 | .read_time = m41t80_rtc_read_time, |
| 176 | .set_time = m41t80_rtc_set_time, |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 177 | .proc = m41t80_rtc_proc, |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 180 | static ssize_t flags_show(struct device *dev, |
| 181 | struct device_attribute *attr, char *buf) |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 182 | { |
| 183 | struct i2c_client *client = to_i2c_client(dev); |
| 184 | int val; |
| 185 | |
| 186 | val = i2c_smbus_read_byte_data(client, M41T80_REG_FLAGS); |
| 187 | if (val < 0) |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 188 | return val; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 189 | return sprintf(buf, "%#x\n", val); |
| 190 | } |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 191 | static DEVICE_ATTR_RO(flags); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 192 | |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 193 | static ssize_t sqwfreq_show(struct device *dev, |
| 194 | struct device_attribute *attr, char *buf) |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 195 | { |
| 196 | struct i2c_client *client = to_i2c_client(dev); |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 197 | struct m41t80_data *clientdata = i2c_get_clientdata(client); |
Daniel Glockner | f30281f | 2009-04-02 16:57:03 -0700 | [diff] [blame] | 198 | int val, reg_sqw; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 199 | |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 200 | if (!(clientdata->features & M41T80_FEATURE_SQ)) |
| 201 | return -EINVAL; |
| 202 | |
Daniel Glockner | f30281f | 2009-04-02 16:57:03 -0700 | [diff] [blame] | 203 | reg_sqw = M41T80_REG_SQW; |
| 204 | if (clientdata->features & M41T80_FEATURE_SQ_ALT) |
| 205 | reg_sqw = M41T80_REG_WDAY; |
| 206 | val = i2c_smbus_read_byte_data(client, reg_sqw); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 207 | if (val < 0) |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 208 | return val; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 209 | val = (val >> 4) & 0xf; |
| 210 | switch (val) { |
| 211 | case 0: |
| 212 | break; |
| 213 | case 1: |
| 214 | val = 32768; |
| 215 | break; |
| 216 | default: |
| 217 | val = 32768 >> val; |
| 218 | } |
| 219 | return sprintf(buf, "%d\n", val); |
| 220 | } |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 221 | |
| 222 | static ssize_t sqwfreq_store(struct device *dev, |
| 223 | struct device_attribute *attr, |
| 224 | const char *buf, size_t count) |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 225 | { |
| 226 | struct i2c_client *client = to_i2c_client(dev); |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 227 | struct m41t80_data *clientdata = i2c_get_clientdata(client); |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 228 | int almon, sqw, reg_sqw, rc; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 229 | int val = simple_strtoul(buf, NULL, 0); |
| 230 | |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 231 | if (!(clientdata->features & M41T80_FEATURE_SQ)) |
| 232 | return -EINVAL; |
| 233 | |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 234 | if (val) { |
| 235 | if (!is_power_of_2(val)) |
| 236 | return -EINVAL; |
| 237 | val = ilog2(val); |
| 238 | if (val == 15) |
| 239 | val = 1; |
| 240 | else if (val < 14) |
| 241 | val = 15 - val; |
| 242 | else |
| 243 | return -EINVAL; |
| 244 | } |
| 245 | /* disable SQW, set SQW frequency & re-enable */ |
| 246 | almon = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_MON); |
| 247 | if (almon < 0) |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 248 | return almon; |
Daniel Glockner | f30281f | 2009-04-02 16:57:03 -0700 | [diff] [blame] | 249 | reg_sqw = M41T80_REG_SQW; |
| 250 | if (clientdata->features & M41T80_FEATURE_SQ_ALT) |
| 251 | reg_sqw = M41T80_REG_WDAY; |
| 252 | sqw = i2c_smbus_read_byte_data(client, reg_sqw); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 253 | if (sqw < 0) |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 254 | return sqw; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 255 | sqw = (sqw & 0x0f) | (val << 4); |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 256 | |
| 257 | rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, |
| 258 | almon & ~M41T80_ALMON_SQWE); |
| 259 | if (rc < 0) |
| 260 | return rc; |
| 261 | |
| 262 | if (val) { |
| 263 | rc = i2c_smbus_write_byte_data(client, reg_sqw, sqw); |
| 264 | if (rc < 0) |
| 265 | return rc; |
| 266 | |
| 267 | rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_MON, |
| 268 | almon | M41T80_ALMON_SQWE); |
| 269 | if (rc <0) |
| 270 | return rc; |
| 271 | } |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 272 | return count; |
| 273 | } |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 274 | static DEVICE_ATTR_RW(sqwfreq); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 275 | |
| 276 | static struct attribute *attrs[] = { |
| 277 | &dev_attr_flags.attr, |
| 278 | &dev_attr_sqwfreq.attr, |
| 279 | NULL, |
| 280 | }; |
| 281 | static struct attribute_group attr_group = { |
| 282 | .attrs = attrs, |
| 283 | }; |
| 284 | |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 285 | #ifdef CONFIG_RTC_DRV_M41T80_WDT |
| 286 | /* |
| 287 | ***************************************************************************** |
| 288 | * |
| 289 | * Watchdog Driver |
| 290 | * |
| 291 | ***************************************************************************** |
| 292 | */ |
| 293 | static struct i2c_client *save_client; |
| 294 | |
| 295 | /* Default margin */ |
| 296 | #define WD_TIMO 60 /* 1..31 seconds */ |
| 297 | |
| 298 | static int wdt_margin = WD_TIMO; |
| 299 | module_param(wdt_margin, int, 0); |
| 300 | MODULE_PARM_DESC(wdt_margin, "Watchdog timeout in seconds (default 60s)"); |
| 301 | |
| 302 | static unsigned long wdt_is_open; |
| 303 | static int boot_flag; |
| 304 | |
| 305 | /** |
| 306 | * wdt_ping: |
| 307 | * |
| 308 | * Reload counter one with the watchdog timeout. We don't bother reloading |
| 309 | * the cascade counter. |
| 310 | */ |
| 311 | static void wdt_ping(void) |
| 312 | { |
| 313 | unsigned char i2c_data[2]; |
| 314 | struct i2c_msg msgs1[1] = { |
| 315 | { |
| 316 | .addr = save_client->addr, |
| 317 | .flags = 0, |
| 318 | .len = 2, |
| 319 | .buf = i2c_data, |
| 320 | }, |
| 321 | }; |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 322 | struct m41t80_data *clientdata = i2c_get_clientdata(save_client); |
| 323 | |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 324 | i2c_data[0] = 0x09; /* watchdog register */ |
| 325 | |
| 326 | if (wdt_margin > 31) |
| 327 | i2c_data[1] = (wdt_margin & 0xFC) | 0x83; /* resolution = 4s */ |
| 328 | else |
| 329 | /* |
| 330 | * WDS = 1 (0x80), mulitplier = WD_TIMO, resolution = 1s (0x02) |
| 331 | */ |
| 332 | i2c_data[1] = wdt_margin<<2 | 0x82; |
| 333 | |
Steven A. Falco | d3a126f | 2008-10-15 22:03:07 -0700 | [diff] [blame] | 334 | /* |
| 335 | * M41T65 has three bits for watchdog resolution. Don't set bit 7, as |
| 336 | * that would be an invalid resolution. |
| 337 | */ |
| 338 | if (clientdata->features & M41T80_FEATURE_WD) |
| 339 | i2c_data[1] &= ~M41T80_WATCHDOG_RB2; |
| 340 | |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 341 | i2c_transfer(save_client->adapter, msgs1, 1); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * wdt_disable: |
| 346 | * |
| 347 | * disables watchdog. |
| 348 | */ |
| 349 | static void wdt_disable(void) |
| 350 | { |
| 351 | unsigned char i2c_data[2], i2c_buf[0x10]; |
| 352 | struct i2c_msg msgs0[2] = { |
| 353 | { |
| 354 | .addr = save_client->addr, |
| 355 | .flags = 0, |
| 356 | .len = 1, |
| 357 | .buf = i2c_data, |
| 358 | }, |
| 359 | { |
| 360 | .addr = save_client->addr, |
| 361 | .flags = I2C_M_RD, |
| 362 | .len = 1, |
| 363 | .buf = i2c_buf, |
| 364 | }, |
| 365 | }; |
| 366 | struct i2c_msg msgs1[1] = { |
| 367 | { |
| 368 | .addr = save_client->addr, |
| 369 | .flags = 0, |
| 370 | .len = 2, |
| 371 | .buf = i2c_data, |
| 372 | }, |
| 373 | }; |
| 374 | |
| 375 | i2c_data[0] = 0x09; |
| 376 | i2c_transfer(save_client->adapter, msgs0, 2); |
| 377 | |
| 378 | i2c_data[0] = 0x09; |
| 379 | i2c_data[1] = 0x00; |
| 380 | i2c_transfer(save_client->adapter, msgs1, 1); |
| 381 | } |
| 382 | |
| 383 | /** |
| 384 | * wdt_write: |
| 385 | * @file: file handle to the watchdog |
| 386 | * @buf: buffer to write (unused as data does not matter here |
| 387 | * @count: count of bytes |
| 388 | * @ppos: pointer to the position to write. No seeks allowed |
| 389 | * |
| 390 | * A write to a watchdog device is defined as a keepalive signal. Any |
| 391 | * write of data will do, as we we don't define content meaning. |
| 392 | */ |
| 393 | static ssize_t wdt_write(struct file *file, const char __user *buf, |
| 394 | size_t count, loff_t *ppos) |
| 395 | { |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 396 | if (count) { |
| 397 | wdt_ping(); |
| 398 | return 1; |
| 399 | } |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | static ssize_t wdt_read(struct file *file, char __user *buf, |
| 404 | size_t count, loff_t *ppos) |
| 405 | { |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * wdt_ioctl: |
| 411 | * @inode: inode of the device |
| 412 | * @file: file handle to the device |
| 413 | * @cmd: watchdog command |
| 414 | * @arg: argument pointer |
| 415 | * |
| 416 | * The watchdog API defines a common set of functions for all watchdogs |
| 417 | * according to their available features. We only actually usefully support |
| 418 | * querying capabilities and current status. |
| 419 | */ |
Arnd Bergmann | 5592933 | 2010-04-27 00:24:05 +0200 | [diff] [blame] | 420 | static int wdt_ioctl(struct file *file, unsigned int cmd, |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 421 | unsigned long arg) |
| 422 | { |
| 423 | int new_margin, rv; |
| 424 | static struct watchdog_info ident = { |
| 425 | .options = WDIOF_POWERUNDER | WDIOF_KEEPALIVEPING | |
| 426 | WDIOF_SETTIMEOUT, |
| 427 | .firmware_version = 1, |
| 428 | .identity = "M41T80 WTD" |
| 429 | }; |
| 430 | |
| 431 | switch (cmd) { |
| 432 | case WDIOC_GETSUPPORT: |
| 433 | return copy_to_user((struct watchdog_info __user *)arg, &ident, |
| 434 | sizeof(ident)) ? -EFAULT : 0; |
| 435 | |
| 436 | case WDIOC_GETSTATUS: |
| 437 | case WDIOC_GETBOOTSTATUS: |
| 438 | return put_user(boot_flag, (int __user *)arg); |
| 439 | case WDIOC_KEEPALIVE: |
| 440 | wdt_ping(); |
| 441 | return 0; |
| 442 | case WDIOC_SETTIMEOUT: |
| 443 | if (get_user(new_margin, (int __user *)arg)) |
| 444 | return -EFAULT; |
| 445 | /* Arbitrary, can't find the card's limits */ |
| 446 | if (new_margin < 1 || new_margin > 124) |
| 447 | return -EINVAL; |
| 448 | wdt_margin = new_margin; |
| 449 | wdt_ping(); |
| 450 | /* Fall */ |
| 451 | case WDIOC_GETTIMEOUT: |
| 452 | return put_user(wdt_margin, (int __user *)arg); |
| 453 | |
| 454 | case WDIOC_SETOPTIONS: |
| 455 | if (copy_from_user(&rv, (int __user *)arg, sizeof(int))) |
| 456 | return -EFAULT; |
| 457 | |
| 458 | if (rv & WDIOS_DISABLECARD) { |
Joe Perches | a737e83 | 2015-04-16 12:46:14 -0700 | [diff] [blame] | 459 | pr_info("disable watchdog\n"); |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 460 | wdt_disable(); |
| 461 | } |
| 462 | |
| 463 | if (rv & WDIOS_ENABLECARD) { |
Joe Perches | a737e83 | 2015-04-16 12:46:14 -0700 | [diff] [blame] | 464 | pr_info("enable watchdog\n"); |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 465 | wdt_ping(); |
| 466 | } |
| 467 | |
| 468 | return -EINVAL; |
| 469 | } |
| 470 | return -ENOTTY; |
| 471 | } |
| 472 | |
Arnd Bergmann | 5592933 | 2010-04-27 00:24:05 +0200 | [diff] [blame] | 473 | static long wdt_unlocked_ioctl(struct file *file, unsigned int cmd, |
| 474 | unsigned long arg) |
| 475 | { |
| 476 | int ret; |
| 477 | |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 478 | mutex_lock(&m41t80_rtc_mutex); |
Arnd Bergmann | 5592933 | 2010-04-27 00:24:05 +0200 | [diff] [blame] | 479 | ret = wdt_ioctl(file, cmd, arg); |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 480 | mutex_unlock(&m41t80_rtc_mutex); |
Arnd Bergmann | 5592933 | 2010-04-27 00:24:05 +0200 | [diff] [blame] | 481 | |
| 482 | return ret; |
| 483 | } |
| 484 | |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 485 | /** |
| 486 | * wdt_open: |
| 487 | * @inode: inode of device |
| 488 | * @file: file handle to device |
| 489 | * |
| 490 | */ |
| 491 | static int wdt_open(struct inode *inode, struct file *file) |
| 492 | { |
| 493 | if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) { |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 494 | mutex_lock(&m41t80_rtc_mutex); |
Arnd Bergmann | 4101273 | 2008-05-20 19:16:39 +0200 | [diff] [blame] | 495 | if (test_and_set_bit(0, &wdt_is_open)) { |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 496 | mutex_unlock(&m41t80_rtc_mutex); |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 497 | return -EBUSY; |
Arnd Bergmann | 4101273 | 2008-05-20 19:16:39 +0200 | [diff] [blame] | 498 | } |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 499 | /* |
| 500 | * Activate |
| 501 | */ |
| 502 | wdt_is_open = 1; |
Arnd Bergmann | 613655f | 2010-06-02 14:28:52 +0200 | [diff] [blame] | 503 | mutex_unlock(&m41t80_rtc_mutex); |
Jan Blunck | 09eeb1f | 2010-05-26 14:44:47 -0700 | [diff] [blame] | 504 | return nonseekable_open(inode, file); |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 505 | } |
| 506 | return -ENODEV; |
| 507 | } |
| 508 | |
| 509 | /** |
| 510 | * wdt_close: |
| 511 | * @inode: inode to board |
| 512 | * @file: file handle to board |
| 513 | * |
| 514 | */ |
| 515 | static int wdt_release(struct inode *inode, struct file *file) |
| 516 | { |
| 517 | if (MINOR(inode->i_rdev) == WATCHDOG_MINOR) |
| 518 | clear_bit(0, &wdt_is_open); |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | /** |
| 523 | * notify_sys: |
| 524 | * @this: our notifier block |
| 525 | * @code: the event being reported |
| 526 | * @unused: unused |
| 527 | * |
| 528 | * Our notifier is called on system shutdowns. We want to turn the card |
| 529 | * off at reboot otherwise the machine will reboot again during memory |
| 530 | * test or worse yet during the following fsck. This would suck, in fact |
| 531 | * trust me - if it happens it does suck. |
| 532 | */ |
| 533 | static int wdt_notify_sys(struct notifier_block *this, unsigned long code, |
| 534 | void *unused) |
| 535 | { |
| 536 | if (code == SYS_DOWN || code == SYS_HALT) |
| 537 | /* Disable Watchdog */ |
| 538 | wdt_disable(); |
| 539 | return NOTIFY_DONE; |
| 540 | } |
| 541 | |
| 542 | static const struct file_operations wdt_fops = { |
| 543 | .owner = THIS_MODULE, |
| 544 | .read = wdt_read, |
Arnd Bergmann | 5592933 | 2010-04-27 00:24:05 +0200 | [diff] [blame] | 545 | .unlocked_ioctl = wdt_unlocked_ioctl, |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 546 | .write = wdt_write, |
| 547 | .open = wdt_open, |
| 548 | .release = wdt_release, |
Arnd Bergmann | 6038f37 | 2010-08-15 18:52:59 +0200 | [diff] [blame] | 549 | .llseek = no_llseek, |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 550 | }; |
| 551 | |
| 552 | static struct miscdevice wdt_dev = { |
| 553 | .minor = WATCHDOG_MINOR, |
| 554 | .name = "watchdog", |
| 555 | .fops = &wdt_fops, |
| 556 | }; |
| 557 | |
| 558 | /* |
| 559 | * The WDT card needs to learn about soft shutdowns in order to |
| 560 | * turn the timebomb registers off. |
| 561 | */ |
| 562 | static struct notifier_block wdt_notifier = { |
| 563 | .notifier_call = wdt_notify_sys, |
| 564 | }; |
| 565 | #endif /* CONFIG_RTC_DRV_M41T80_WDT */ |
| 566 | |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 567 | /* |
| 568 | ***************************************************************************** |
| 569 | * |
| 570 | * Driver Interface |
| 571 | * |
| 572 | ***************************************************************************** |
| 573 | */ |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 574 | |
| 575 | static void m41t80_remove_sysfs_group(void *_dev) |
| 576 | { |
| 577 | struct device *dev = _dev; |
| 578 | |
| 579 | sysfs_remove_group(&dev->kobj, &attr_group); |
| 580 | } |
| 581 | |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 582 | static int m41t80_probe(struct i2c_client *client, |
| 583 | const struct i2c_device_id *id) |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 584 | { |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 585 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 586 | int rc = 0; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 587 | struct rtc_device *rtc = NULL; |
| 588 | struct rtc_time tm; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 589 | struct m41t80_data *clientdata = NULL; |
| 590 | |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 591 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_I2C_BLOCK | |
| 592 | I2C_FUNC_SMBUS_BYTE_DATA)) { |
| 593 | dev_err(&adapter->dev, "doesn't support I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_I2C_BLOCK\n"); |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 594 | return -ENODEV; |
Mylène Josserand | f2b84ee | 2016-03-29 08:56:00 +0200 | [diff] [blame^] | 595 | } |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 596 | |
Jingoo Han | 4ebabb7 | 2013-04-29 16:20:42 -0700 | [diff] [blame] | 597 | clientdata = devm_kzalloc(&client->dev, sizeof(*clientdata), |
| 598 | GFP_KERNEL); |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 599 | if (!clientdata) |
| 600 | return -ENOMEM; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 601 | |
John Stultz | a015dbc | 2011-05-06 17:24:27 -0700 | [diff] [blame] | 602 | clientdata->features = id->driver_data; |
| 603 | i2c_set_clientdata(client, clientdata); |
| 604 | |
Jingoo Han | 4ebabb7 | 2013-04-29 16:20:42 -0700 | [diff] [blame] | 605 | rtc = devm_rtc_device_register(&client->dev, client->name, |
| 606 | &m41t80_rtc_ops, THIS_MODULE); |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 607 | if (IS_ERR(rtc)) |
| 608 | return PTR_ERR(rtc); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 609 | |
| 610 | clientdata->rtc = rtc; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 611 | |
| 612 | /* Make sure HT (Halt Update) bit is cleared */ |
| 613 | rc = i2c_smbus_read_byte_data(client, M41T80_REG_ALARM_HOUR); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 614 | |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 615 | if (rc >= 0 && rc & M41T80_ALHOUR_HT) { |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 616 | if (clientdata->features & M41T80_FEATURE_HT) { |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 617 | m41t80_get_datetime(client, &tm); |
| 618 | dev_info(&client->dev, "HT bit was set!\n"); |
| 619 | dev_info(&client->dev, |
| 620 | "Power Down at " |
| 621 | "%04i-%02i-%02i %02i:%02i:%02i\n", |
| 622 | tm.tm_year + 1900, |
| 623 | tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, |
| 624 | tm.tm_min, tm.tm_sec); |
| 625 | } |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 626 | rc = i2c_smbus_write_byte_data(client, M41T80_REG_ALARM_HOUR, |
| 627 | rc & ~M41T80_ALHOUR_HT); |
| 628 | } |
| 629 | |
| 630 | if (rc < 0) { |
| 631 | dev_err(&client->dev, "Can't clear HT bit\n"); |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 632 | return rc; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /* Make sure ST (stop) bit is cleared */ |
| 636 | rc = i2c_smbus_read_byte_data(client, M41T80_REG_SEC); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 637 | |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 638 | if (rc >= 0 && rc & M41T80_SEC_ST) |
| 639 | rc = i2c_smbus_write_byte_data(client, M41T80_REG_SEC, |
| 640 | rc & ~M41T80_SEC_ST); |
| 641 | if (rc < 0) { |
| 642 | dev_err(&client->dev, "Can't clear ST bit\n"); |
Wolfram Sang | 85d7704 | 2014-06-06 14:35:46 -0700 | [diff] [blame] | 643 | return rc; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 644 | } |
| 645 | |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 646 | /* Export sysfs entries */ |
| 647 | rc = sysfs_create_group(&(&client->dev)->kobj, &attr_group); |
| 648 | if (rc) { |
| 649 | dev_err(&client->dev, "Failed to create sysfs group: %d\n", rc); |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 650 | return rc; |
Mylène Josserand | ef6b312 | 2016-03-29 08:55:58 +0200 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | rc = devm_add_action(&client->dev, m41t80_remove_sysfs_group, |
| 654 | &client->dev); |
| 655 | if (rc) { |
| 656 | m41t80_remove_sysfs_group(&client->dev); |
| 657 | dev_err(&client->dev, |
| 658 | "Failed to add sysfs cleanup action: %d\n", rc); |
| 659 | return rc; |
| 660 | } |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 661 | |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 662 | #ifdef CONFIG_RTC_DRV_M41T80_WDT |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 663 | if (clientdata->features & M41T80_FEATURE_HT) { |
Maciej W. Rozycki | 417607d | 2008-05-12 14:02:35 -0700 | [diff] [blame] | 664 | save_client = client; |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 665 | rc = misc_register(&wdt_dev); |
| 666 | if (rc) |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 667 | return rc; |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 668 | rc = register_reboot_notifier(&wdt_notifier); |
| 669 | if (rc) { |
| 670 | misc_deregister(&wdt_dev); |
Wolfram Sang | c67fedf | 2014-06-06 14:35:45 -0700 | [diff] [blame] | 671 | return rc; |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 672 | } |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 673 | } |
| 674 | #endif |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 675 | return 0; |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 676 | } |
| 677 | |
| 678 | static int m41t80_remove(struct i2c_client *client) |
| 679 | { |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 680 | #ifdef CONFIG_RTC_DRV_M41T80_WDT |
Jingoo Han | 4ebabb7 | 2013-04-29 16:20:42 -0700 | [diff] [blame] | 681 | struct m41t80_data *clientdata = i2c_get_clientdata(client); |
| 682 | |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 683 | if (clientdata->features & M41T80_FEATURE_HT) { |
Atsushi Nemoto | 617780d | 2007-07-17 04:05:04 -0700 | [diff] [blame] | 684 | misc_deregister(&wdt_dev); |
| 685 | unregister_reboot_notifier(&wdt_notifier); |
| 686 | } |
| 687 | #endif |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 688 | |
| 689 | return 0; |
| 690 | } |
| 691 | |
| 692 | static struct i2c_driver m41t80_driver = { |
| 693 | .driver = { |
David Brownell | afe1ab4 | 2007-08-22 14:01:27 -0700 | [diff] [blame] | 694 | .name = "rtc-m41t80", |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 695 | }, |
| 696 | .probe = m41t80_probe, |
| 697 | .remove = m41t80_remove, |
Jean Delvare | 3760f73 | 2008-04-29 23:11:40 +0200 | [diff] [blame] | 698 | .id_table = m41t80_id, |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 699 | }; |
| 700 | |
Axel Lin | 0abc920 | 2012-03-23 15:02:31 -0700 | [diff] [blame] | 701 | module_i2c_driver(m41t80_driver); |
Atsushi Nemoto | caaff56 | 2007-07-17 04:05:02 -0700 | [diff] [blame] | 702 | |
| 703 | MODULE_AUTHOR("Alexander Bigga <ab@mycable.de>"); |
| 704 | MODULE_DESCRIPTION("ST Microelectronics M41T80 series RTC I2C Client Driver"); |
| 705 | MODULE_LICENSE("GPL"); |