mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-25 12:10:53 +07:00
rtc: rtc-ds1302 fixes
- removed spinlock protection, it's handled by the rtc class - use platform_driver_probe - return appropriate code for rtc_read_time - style issues Signed-off-by: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
This commit is contained in:
parent
307646c958
commit
2bfc3305f6
@ -1,26 +1,25 @@
|
|||||||
/*
|
/*
|
||||||
* Dallas DS1302 RTC Support
|
* Dallas DS1302 RTC Support
|
||||||
*
|
*
|
||||||
* Copyright (C) 2002 David McCullough
|
* Copyright (C) 2002 David McCullough
|
||||||
* Copyright (C) 2003 - 2007 Paul Mundt
|
* Copyright (C) 2003 - 2007 Paul Mundt
|
||||||
*
|
*
|
||||||
* This file is subject to the terms and conditions of the GNU General Public
|
* This file is subject to the terms and conditions of the GNU General Public
|
||||||
* License version 2. See the file "COPYING" in the main directory of
|
* License version 2. See the file "COPYING" in the main directory of
|
||||||
* this archive for more details.
|
* this archive for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <linux/init.h>
|
#include <linux/init.h>
|
||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <linux/kernel.h>
|
#include <linux/kernel.h>
|
||||||
#include <linux/platform_device.h>
|
#include <linux/platform_device.h>
|
||||||
#include <linux/time.h>
|
|
||||||
#include <linux/rtc.h>
|
#include <linux/rtc.h>
|
||||||
#include <linux/spinlock.h>
|
|
||||||
#include <linux/io.h>
|
#include <linux/io.h>
|
||||||
#include <linux/bcd.h>
|
#include <linux/bcd.h>
|
||||||
#include <asm/rtc.h>
|
#include <asm/rtc.h>
|
||||||
|
|
||||||
#define DRV_NAME "rtc-ds1302"
|
#define DRV_NAME "rtc-ds1302"
|
||||||
#define DRV_VERSION "0.1.0"
|
#define DRV_VERSION "0.1.1"
|
||||||
|
|
||||||
#define RTC_CMD_READ 0x81 /* Read command */
|
#define RTC_CMD_READ 0x81 /* Read command */
|
||||||
#define RTC_CMD_WRITE 0x80 /* Write command */
|
#define RTC_CMD_WRITE 0x80 /* Write command */
|
||||||
@ -47,11 +46,6 @@
|
|||||||
#error "Add support for your platform"
|
#error "Add support for your platform"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct ds1302_rtc {
|
|
||||||
struct rtc_device *rtc_dev;
|
|
||||||
spinlock_t lock;
|
|
||||||
};
|
|
||||||
|
|
||||||
static void ds1302_sendbits(unsigned int val)
|
static void ds1302_sendbits(unsigned int val)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -105,8 +99,6 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
|||||||
{
|
{
|
||||||
struct ds1302_rtc *rtc = dev_get_drvdata(dev);
|
struct ds1302_rtc *rtc = dev_get_drvdata(dev);
|
||||||
|
|
||||||
spin_lock_irq(&rtc->lock);
|
|
||||||
|
|
||||||
tm->tm_sec = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC));
|
tm->tm_sec = bcd2bin(ds1302_readbyte(RTC_ADDR_SEC));
|
||||||
tm->tm_min = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN));
|
tm->tm_min = bcd2bin(ds1302_readbyte(RTC_ADDR_MIN));
|
||||||
tm->tm_hour = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR));
|
tm->tm_hour = bcd2bin(ds1302_readbyte(RTC_ADDR_HOUR));
|
||||||
@ -118,26 +110,17 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
|||||||
if (tm->tm_year < 70)
|
if (tm->tm_year < 70)
|
||||||
tm->tm_year += 100;
|
tm->tm_year += 100;
|
||||||
|
|
||||||
spin_unlock_irq(&rtc->lock);
|
|
||||||
|
|
||||||
dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
|
dev_dbg(dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
|
||||||
"mday=%d, mon=%d, year=%d, wday=%d\n",
|
"mday=%d, mon=%d, year=%d, wday=%d\n",
|
||||||
__func__,
|
__func__,
|
||||||
tm->tm_sec, tm->tm_min, tm->tm_hour,
|
tm->tm_sec, tm->tm_min, tm->tm_hour,
|
||||||
tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
|
tm->tm_mday, tm->tm_mon + 1, tm->tm_year, tm->tm_wday);
|
||||||
|
|
||||||
if (rtc_valid_tm(tm) < 0)
|
return rtc_valid_tm(tm);
|
||||||
dev_err(dev, "invalid date\n");
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
||||||
{
|
{
|
||||||
struct ds1302_rtc *rtc = dev_get_drvdata(dev);
|
|
||||||
|
|
||||||
spin_lock_irq(&rtc->lock);
|
|
||||||
|
|
||||||
/* Stop RTC */
|
/* Stop RTC */
|
||||||
ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);
|
ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);
|
||||||
|
|
||||||
@ -152,8 +135,6 @@ static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
|||||||
/* Start RTC */
|
/* Start RTC */
|
||||||
ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
|
ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
|
||||||
|
|
||||||
spin_unlock_irq(&rtc->lock);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,9 +151,7 @@ static int ds1302_rtc_ioctl(struct device *dev, unsigned int cmd,
|
|||||||
if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int)))
|
if (copy_from_user(&tcs_val, (int __user *)arg, sizeof(int)))
|
||||||
return -EFAULT;
|
return -EFAULT;
|
||||||
|
|
||||||
spin_lock_irq(&rtc->lock);
|
|
||||||
ds1302_writebyte(RTC_ADDR_TCR, (0xa0 | tcs_val * 0xf));
|
ds1302_writebyte(RTC_ADDR_TCR, (0xa0 | tcs_val * 0xf));
|
||||||
spin_unlock_irq(&rtc->lock);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -187,9 +166,9 @@ static struct rtc_class_ops ds1302_rtc_ops = {
|
|||||||
.ioctl = ds1302_rtc_ioctl,
|
.ioctl = ds1302_rtc_ioctl,
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __devinit ds1302_rtc_probe(struct platform_device *pdev)
|
static int __init ds1302_rtc_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct ds1302_rtc *rtc;
|
struct rtc_device *rtc;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Reset */
|
/* Reset */
|
||||||
@ -200,37 +179,23 @@ static int __devinit ds1302_rtc_probe(struct platform_device *pdev)
|
|||||||
if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42)
|
if (ds1302_readbyte(RTC_ADDR_RAM0) != 0x42)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
rtc = kzalloc(sizeof(struct ds1302_rtc), GFP_KERNEL);
|
rtc = rtc_device_register("ds1302", &pdev->dev,
|
||||||
if (unlikely(!rtc))
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
spin_lock_init(&rtc->lock);
|
|
||||||
rtc->rtc_dev = rtc_device_register("ds1302", &pdev->dev,
|
|
||||||
&ds1302_rtc_ops, THIS_MODULE);
|
&ds1302_rtc_ops, THIS_MODULE);
|
||||||
if (IS_ERR(rtc->rtc_dev)) {
|
if (IS_ERR(rtc))
|
||||||
ret = PTR_ERR(rtc->rtc_dev);
|
return PTR_ERR(rtc);
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
platform_set_drvdata(pdev, rtc);
|
platform_set_drvdata(pdev, rtc);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
out:
|
|
||||||
kfree(rtc);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __devexit ds1302_rtc_remove(struct platform_device *pdev)
|
static int __devexit ds1302_rtc_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct ds1302_rtc *rtc = platform_get_drvdata(pdev);
|
struct rtc_device *rtc = platform_get_drvdata(pdev);
|
||||||
|
|
||||||
if (likely(rtc->rtc_dev))
|
|
||||||
rtc_device_unregister(rtc->rtc_dev);
|
|
||||||
|
|
||||||
|
rtc_device_unregister(rtc);
|
||||||
platform_set_drvdata(pdev, NULL);
|
platform_set_drvdata(pdev, NULL);
|
||||||
|
|
||||||
kfree(rtc);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,13 +204,12 @@ static struct platform_driver ds1302_platform_driver = {
|
|||||||
.name = DRV_NAME,
|
.name = DRV_NAME,
|
||||||
.owner = THIS_MODULE,
|
.owner = THIS_MODULE,
|
||||||
},
|
},
|
||||||
.probe = ds1302_rtc_probe,
|
.remove = __exit_p(ds1302_rtc_remove),
|
||||||
.remove = __devexit_p(ds1302_rtc_remove),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int __init ds1302_rtc_init(void)
|
static int __init ds1302_rtc_init(void)
|
||||||
{
|
{
|
||||||
return platform_driver_register(&ds1302_platform_driver);
|
return platform_driver_probe(&ds1302_platform_driver, ds1302_rtc_probe);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void __exit ds1302_rtc_exit(void)
|
static void __exit ds1302_rtc_exit(void)
|
||||||
|
Loading…
Reference in New Issue
Block a user