Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

rtc: rtc-ds3234 fixes

- no changelogs in code
- no banners
- use local buffers
- fix probe sequence
- do not init .driver.bus

Signed-off-by: Alessandro Zummo <a.zummo@towertech.it>
Cc: Dennis Aberilla <denzzzhome@yahoo.com>
Acked-by: David Brownell <david-b@pacbell.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Alessandro Zummo and committed by
Linus Torvalds
f6009157 a5771c6c

+33 -133
+33 -133
drivers/rtc/rtc-ds3234.c
··· 1 - /* drivers/rtc/rtc-ds3234.c 1 + /* rtc-ds3234.c 2 2 * 3 3 * Driver for Dallas Semiconductor (DS3234) SPI RTC with Integrated Crystal 4 4 * and SRAM. ··· 9 9 * it under the terms of the GNU General Public License version 2 as 10 10 * published by the Free Software Foundation. 11 11 * 12 - * Changelog: 13 - * 14 - * 07-May-2008: Dennis Aberilla <denzzzhome@yahoo.com> 15 - * - Created based on the max6902 code. Only implements the 16 - * date/time keeping functions; no SRAM yet. 17 12 */ 18 13 14 + #include <linux/init.h> 15 + #include <linux/module.h> 19 16 #include <linux/device.h> 20 17 #include <linux/platform_device.h> 21 18 #include <linux/rtc.h> ··· 31 34 #define DS3234_REG_CONTROL 0x0E 32 35 #define DS3234_REG_CONT_STAT 0x0F 33 36 34 - #undef DS3234_DEBUG 35 - 36 - struct ds3234 { 37 - struct rtc_device *rtc; 38 - u8 buf[8]; /* Burst read: addr + 7 regs */ 39 - u8 tx_buf[2]; 40 - u8 rx_buf[2]; 41 - }; 42 - 43 - static void ds3234_set_reg(struct device *dev, unsigned char address, 37 + static int ds3234_set_reg(struct device *dev, unsigned char address, 44 38 unsigned char data) 45 39 { 46 40 struct spi_device *spi = to_spi_device(dev); ··· 41 53 buf[0] = address | 0x80; 42 54 buf[1] = data; 43 55 44 - spi_write(spi, buf, 2); 56 + return spi_write_then_read(spi, buf, 2, NULL, 0); 45 57 } 46 58 47 59 static int ds3234_get_reg(struct device *dev, unsigned char address, 48 60 unsigned char *data) 49 61 { 50 62 struct spi_device *spi = to_spi_device(dev); 51 - struct ds3234 *chip = dev_get_drvdata(dev); 52 - struct spi_message message; 53 - struct spi_transfer xfer; 54 - int status; 55 63 56 - if (!data) 57 - return -EINVAL; 64 + *data = address & 0x7f; 58 65 59 - /* Build our spi message */ 60 - spi_message_init(&message); 61 - memset(&xfer, 0, sizeof(xfer)); 62 - 63 - /* Address + dummy tx byte */ 64 - xfer.len = 2; 65 - xfer.tx_buf = chip->tx_buf; 66 - xfer.rx_buf = chip->rx_buf; 67 - 68 - chip->tx_buf[0] = address; 69 - chip->tx_buf[1] = 0xff; 70 - 71 - spi_message_add_tail(&xfer, &message); 72 - 73 - /* do the i/o */ 74 - status = spi_sync(spi, &message); 75 - if (status == 0) 76 - status = message.status; 77 - else 78 - return status; 79 - 80 - *data = chip->rx_buf[1]; 81 - 82 - return status; 66 + return spi_write_then_read(spi, data, 1, data, 1); 83 67 } 84 68 85 - static int ds3234_get_datetime(struct device *dev, struct rtc_time *dt) 69 + static int ds3234_read_time(struct device *dev, struct rtc_time *dt) 86 70 { 71 + int err; 72 + unsigned char buf[8]; 87 73 struct spi_device *spi = to_spi_device(dev); 88 - struct ds3234 *chip = dev_get_drvdata(dev); 89 - struct spi_message message; 90 - struct spi_transfer xfer; 91 - int status; 92 74 93 - /* build the message */ 94 - spi_message_init(&message); 95 - memset(&xfer, 0, sizeof(xfer)); 96 - xfer.len = 1 + 7; /* Addr + 7 registers */ 97 - xfer.tx_buf = chip->buf; 98 - xfer.rx_buf = chip->buf; 99 - chip->buf[0] = 0x00; /* Start address */ 100 - spi_message_add_tail(&xfer, &message); 75 + buf[0] = 0x00; /* Start address */ 101 76 102 - /* do the i/o */ 103 - status = spi_sync(spi, &message); 104 - if (status == 0) 105 - status = message.status; 106 - else 107 - return status; 77 + err = spi_write_then_read(spi, buf, 1, buf, 8); 78 + if (err != 0) 79 + return err; 108 80 109 81 /* Seconds, Minutes, Hours, Day, Date, Month, Year */ 110 - dt->tm_sec = bcd2bin(chip->buf[1]); 111 - dt->tm_min = bcd2bin(chip->buf[2]); 112 - dt->tm_hour = bcd2bin(chip->buf[3] & 0x3f); 113 - dt->tm_wday = bcd2bin(chip->buf[4]) - 1; /* 0 = Sun */ 114 - dt->tm_mday = bcd2bin(chip->buf[5]); 115 - dt->tm_mon = bcd2bin(chip->buf[6] & 0x1f) - 1; /* 0 = Jan */ 116 - dt->tm_year = bcd2bin(chip->buf[7] & 0xff) + 100; /* Assume 20YY */ 82 + dt->tm_sec = bcd2bin(buf[0]); 83 + dt->tm_min = bcd2bin(buf[1]); 84 + dt->tm_hour = bcd2bin(buf[2] & 0x3f); 85 + dt->tm_wday = bcd2bin(buf[3]) - 1; /* 0 = Sun */ 86 + dt->tm_mday = bcd2bin(buf[4]); 87 + dt->tm_mon = bcd2bin(buf[5] & 0x1f) - 1; /* 0 = Jan */ 88 + dt->tm_year = bcd2bin(buf[6] & 0xff) + 100; /* Assume 20YY */ 117 89 118 - #ifdef DS3234_DEBUG 119 - dev_dbg(dev, "\n%s : Read RTC values\n", __func__); 120 - dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); 121 - dev_dbg(dev, "tm_min : %i\n", dt->tm_min); 122 - dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); 123 - dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); 124 - dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); 125 - dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon); 126 - dev_dbg(dev, "tm_year: %i\n", dt->tm_year); 127 - #endif 128 - 129 - return 0; 90 + return rtc_valid_tm(dt); 130 91 } 131 92 132 - static int ds3234_set_datetime(struct device *dev, struct rtc_time *dt) 93 + static int ds3234_set_time(struct device *dev, struct rtc_time *dt) 133 94 { 134 - #ifdef DS3234_DEBUG 135 - dev_dbg(dev, "\n%s : Setting RTC values\n", __func__); 136 - dev_dbg(dev, "tm_sec : %i\n", dt->tm_sec); 137 - dev_dbg(dev, "tm_min : %i\n", dt->tm_min); 138 - dev_dbg(dev, "tm_hour: %i\n", dt->tm_hour); 139 - dev_dbg(dev, "tm_wday: %i\n", dt->tm_wday); 140 - dev_dbg(dev, "tm_mday: %i\n", dt->tm_mday); 141 - dev_dbg(dev, "tm_mon : %i\n", dt->tm_mon); 142 - dev_dbg(dev, "tm_year: %i\n", dt->tm_year); 143 - #endif 144 - 145 95 ds3234_set_reg(dev, DS3234_REG_SECONDS, bin2bcd(dt->tm_sec)); 146 96 ds3234_set_reg(dev, DS3234_REG_MINUTES, bin2bcd(dt->tm_min)); 147 97 ds3234_set_reg(dev, DS3234_REG_HOURS, bin2bcd(dt->tm_hour) & 0x3f); ··· 100 174 return 0; 101 175 } 102 176 103 - static int ds3234_read_time(struct device *dev, struct rtc_time *tm) 104 - { 105 - return ds3234_get_datetime(dev, tm); 106 - } 107 - 108 - static int ds3234_set_time(struct device *dev, struct rtc_time *tm) 109 - { 110 - return ds3234_set_datetime(dev, tm); 111 - } 112 - 113 177 static const struct rtc_class_ops ds3234_rtc_ops = { 114 178 .read_time = ds3234_read_time, 115 179 .set_time = ds3234_set_time, ··· 109 193 { 110 194 struct rtc_device *rtc; 111 195 unsigned char tmp; 112 - struct ds3234 *chip; 113 196 int res; 114 - 115 - rtc = rtc_device_register("ds3234", 116 - &spi->dev, &ds3234_rtc_ops, THIS_MODULE); 117 - if (IS_ERR(rtc)) 118 - return PTR_ERR(rtc); 119 197 120 198 spi->mode = SPI_MODE_3; 121 199 spi->bits_per_word = 8; 122 200 spi_setup(spi); 123 201 124 - chip = kzalloc(sizeof(struct ds3234), GFP_KERNEL); 125 - if (!chip) { 126 - rtc_device_unregister(rtc); 127 - return -ENOMEM; 128 - } 129 - chip->rtc = rtc; 130 - dev_set_drvdata(&spi->dev, chip); 131 - 132 202 res = ds3234_get_reg(&spi->dev, DS3234_REG_SECONDS, &tmp); 133 - if (res) { 134 - rtc_device_unregister(rtc); 203 + if (res != 0) 135 204 return res; 136 - } 137 205 138 206 /* Control settings 139 207 * ··· 146 246 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp); 147 247 dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp); 148 248 249 + rtc = rtc_device_register("ds3234", 250 + &spi->dev, &ds3234_rtc_ops, THIS_MODULE); 251 + if (IS_ERR(rtc)) 252 + return PTR_ERR(rtc); 253 + 254 + dev_set_drvdata(&spi->dev, rtc); 255 + 149 256 return 0; 150 257 } 151 258 152 259 static int __devexit ds3234_remove(struct spi_device *spi) 153 260 { 154 - struct ds3234 *chip = platform_get_drvdata(spi); 155 - struct rtc_device *rtc = chip->rtc; 261 + struct rtc_device *rtc = platform_get_drvdata(spi); 156 262 157 - if (rtc) 158 - rtc_device_unregister(rtc); 159 - 160 - kfree(chip); 161 - 263 + rtc_device_unregister(rtc); 162 264 return 0; 163 265 } 164 266 165 267 static struct spi_driver ds3234_driver = { 166 268 .driver = { 167 269 .name = "ds3234", 168 - .bus = &spi_bus_type, 169 270 .owner = THIS_MODULE, 170 271 }, 171 272 .probe = ds3234_probe, ··· 175 274 176 275 static __init int ds3234_init(void) 177 276 { 178 - printk(KERN_INFO "DS3234 SPI RTC Driver\n"); 179 277 return spi_register_driver(&ds3234_driver); 180 278 } 181 279 module_init(ds3234_init);