mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-17 01:04:19 +08:00
5a0e3ad6af
percpu.h is included by sched.h and module.h and thus ends up being included when building most .c files. percpu.h includes slab.h which in turn includes gfp.h making everything defined by the two files universally available and complicating inclusion dependencies. percpu.h -> slab.h dependency is about to be removed. Prepare for this change by updating users of gfp and slab facilities include those headers directly instead of assuming availability. As this conversion needs to touch large number of source files, the following script is used as the basis of conversion. http://userweb.kernel.org/~tj/misc/slabh-sweep.py The script does the followings. * Scan files for gfp and slab usages and update includes such that only the necessary includes are there. ie. if only gfp is used, gfp.h, if slab is used, slab.h. * When the script inserts a new include, it looks at the include blocks and try to put the new include such that its order conforms to its surrounding. It's put in the include block which contains core kernel includes, in the same order that the rest are ordered - alphabetical, Christmas tree, rev-Xmas-tree or at the end if there doesn't seem to be any matching order. * If the script can't find a place to put a new include (mostly because the file doesn't have fitting include block), it prints out an error message indicating which .h file needs to be added to the file. The conversion was done in the following steps. 1. The initial automatic conversion of all .c files updated slightly over 4000 files, deleting around 700 includes and adding ~480 gfp.h and ~3000 slab.h inclusions. The script emitted errors for ~400 files. 2. Each error was manually checked. Some didn't need the inclusion, some needed manual addition while adding it to implementation .h or embedding .c file was more appropriate for others. This step added inclusions to around 150 files. 3. The script was run again and the output was compared to the edits from #2 to make sure no file was left behind. 4. Several build tests were done and a couple of problems were fixed. e.g. lib/decompress_*.c used malloc/free() wrappers around slab APIs requiring slab.h to be added manually. 5. The script was run on all .h files but without automatically editing them as sprinkling gfp.h and slab.h inclusions around .h files could easily lead to inclusion dependency hell. Most gfp.h inclusion directives were ignored as stuff from gfp.h was usually wildly available and often used in preprocessor macros. Each slab.h inclusion directive was examined and added manually as necessary. 6. percpu.h was updated not to include slab.h. 7. Build test were done on the following configurations and failures were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my distributed build env didn't work with gcov compiles) and a few more options had to be turned off depending on archs to make things build (like ipr on powerpc/64 which failed due to missing writeq). * x86 and x86_64 UP and SMP allmodconfig and a custom test config. * powerpc and powerpc64 SMP allmodconfig * sparc and sparc64 SMP allmodconfig * ia64 SMP allmodconfig * s390 SMP allmodconfig * alpha SMP allmodconfig * um on x86_64 SMP allmodconfig 8. percpu.h modifications were reverted so that it could be applied as a separate patch and serve as bisection point. Given the fact that I had only a couple of failures from tests on step 6, I'm fairly confident about the coverage of this conversion patch. If there is a breakage, it's likely to be something in one of the arch headers which should be easily discoverable easily on most builds of the specific arch. Signed-off-by: Tejun Heo <tj@kernel.org> Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
227 lines
4.9 KiB
C
227 lines
4.9 KiB
C
/*
|
|
* Dallas DS1216 RTC driver
|
|
*
|
|
* Copyright (c) 2007 Thomas Bogendoerfer
|
|
*
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/rtc.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/bcd.h>
|
|
#include <linux/slab.h>
|
|
|
|
#define DRV_VERSION "0.2"
|
|
|
|
struct ds1216_regs {
|
|
u8 tsec;
|
|
u8 sec;
|
|
u8 min;
|
|
u8 hour;
|
|
u8 wday;
|
|
u8 mday;
|
|
u8 month;
|
|
u8 year;
|
|
};
|
|
|
|
#define DS1216_HOUR_1224 (1 << 7)
|
|
#define DS1216_HOUR_AMPM (1 << 5)
|
|
|
|
struct ds1216_priv {
|
|
struct rtc_device *rtc;
|
|
void __iomem *ioaddr;
|
|
size_t size;
|
|
unsigned long baseaddr;
|
|
};
|
|
|
|
static const u8 magic[] = {
|
|
0xc5, 0x3a, 0xa3, 0x5c, 0xc5, 0x3a, 0xa3, 0x5c
|
|
};
|
|
|
|
/*
|
|
* Read the 64 bit we'd like to have - It a series
|
|
* of 64 bits showing up in the LSB of the base register.
|
|
*
|
|
*/
|
|
static void ds1216_read(u8 __iomem *ioaddr, u8 *buf)
|
|
{
|
|
unsigned char c;
|
|
int i, j;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
c = 0;
|
|
for (j = 0; j < 8; j++)
|
|
c |= (readb(ioaddr) & 0x1) << j;
|
|
buf[i] = c;
|
|
}
|
|
}
|
|
|
|
static void ds1216_write(u8 __iomem *ioaddr, const u8 *buf)
|
|
{
|
|
unsigned char c;
|
|
int i, j;
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
c = buf[i];
|
|
for (j = 0; j < 8; j++) {
|
|
writeb(c, ioaddr);
|
|
c = c >> 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void ds1216_switch_ds_to_clock(u8 __iomem *ioaddr)
|
|
{
|
|
/* Reset magic pointer */
|
|
readb(ioaddr);
|
|
/* Write 64 bit magic to DS1216 */
|
|
ds1216_write(ioaddr, magic);
|
|
}
|
|
|
|
static int ds1216_rtc_read_time(struct device *dev, struct rtc_time *tm)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct ds1216_priv *priv = platform_get_drvdata(pdev);
|
|
struct ds1216_regs regs;
|
|
|
|
ds1216_switch_ds_to_clock(priv->ioaddr);
|
|
ds1216_read(priv->ioaddr, (u8 *)®s);
|
|
|
|
tm->tm_sec = bcd2bin(regs.sec);
|
|
tm->tm_min = bcd2bin(regs.min);
|
|
if (regs.hour & DS1216_HOUR_1224) {
|
|
/* AM/PM mode */
|
|
tm->tm_hour = bcd2bin(regs.hour & 0x1f);
|
|
if (regs.hour & DS1216_HOUR_AMPM)
|
|
tm->tm_hour += 12;
|
|
} else
|
|
tm->tm_hour = bcd2bin(regs.hour & 0x3f);
|
|
tm->tm_wday = (regs.wday & 7) - 1;
|
|
tm->tm_mday = bcd2bin(regs.mday & 0x3f);
|
|
tm->tm_mon = bcd2bin(regs.month & 0x1f);
|
|
tm->tm_year = bcd2bin(regs.year);
|
|
if (tm->tm_year < 70)
|
|
tm->tm_year += 100;
|
|
|
|
return rtc_valid_tm(tm);
|
|
}
|
|
|
|
static int ds1216_rtc_set_time(struct device *dev, struct rtc_time *tm)
|
|
{
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
struct ds1216_priv *priv = platform_get_drvdata(pdev);
|
|
struct ds1216_regs regs;
|
|
|
|
ds1216_switch_ds_to_clock(priv->ioaddr);
|
|
ds1216_read(priv->ioaddr, (u8 *)®s);
|
|
|
|
regs.tsec = 0; /* clear 0.1 and 0.01 seconds */
|
|
regs.sec = bin2bcd(tm->tm_sec);
|
|
regs.min = bin2bcd(tm->tm_min);
|
|
regs.hour &= DS1216_HOUR_1224;
|
|
if (regs.hour && tm->tm_hour > 12) {
|
|
regs.hour |= DS1216_HOUR_AMPM;
|
|
tm->tm_hour -= 12;
|
|
}
|
|
regs.hour |= bin2bcd(tm->tm_hour);
|
|
regs.wday &= ~7;
|
|
regs.wday |= tm->tm_wday;
|
|
regs.mday = bin2bcd(tm->tm_mday);
|
|
regs.month = bin2bcd(tm->tm_mon);
|
|
regs.year = bin2bcd(tm->tm_year % 100);
|
|
|
|
ds1216_switch_ds_to_clock(priv->ioaddr);
|
|
ds1216_write(priv->ioaddr, (u8 *)®s);
|
|
return 0;
|
|
}
|
|
|
|
static const struct rtc_class_ops ds1216_rtc_ops = {
|
|
.read_time = ds1216_rtc_read_time,
|
|
.set_time = ds1216_rtc_set_time,
|
|
};
|
|
|
|
static int __init ds1216_rtc_probe(struct platform_device *pdev)
|
|
{
|
|
struct resource *res;
|
|
struct ds1216_priv *priv;
|
|
int ret = 0;
|
|
u8 dummy[8];
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!res)
|
|
return -ENODEV;
|
|
priv = kzalloc(sizeof *priv, GFP_KERNEL);
|
|
if (!priv)
|
|
return -ENOMEM;
|
|
|
|
platform_set_drvdata(pdev, priv);
|
|
|
|
priv->size = resource_size(res);
|
|
if (!request_mem_region(res->start, priv->size, pdev->name)) {
|
|
ret = -EBUSY;
|
|
goto out;
|
|
}
|
|
priv->baseaddr = res->start;
|
|
priv->ioaddr = ioremap(priv->baseaddr, priv->size);
|
|
if (!priv->ioaddr) {
|
|
ret = -ENOMEM;
|
|
goto out;
|
|
}
|
|
priv->rtc = rtc_device_register("ds1216", &pdev->dev,
|
|
&ds1216_rtc_ops, THIS_MODULE);
|
|
if (IS_ERR(priv->rtc)) {
|
|
ret = PTR_ERR(priv->rtc);
|
|
goto out;
|
|
}
|
|
|
|
/* dummy read to get clock into a known state */
|
|
ds1216_read(priv->ioaddr, dummy);
|
|
return 0;
|
|
|
|
out:
|
|
if (priv->ioaddr)
|
|
iounmap(priv->ioaddr);
|
|
if (priv->baseaddr)
|
|
release_mem_region(priv->baseaddr, priv->size);
|
|
kfree(priv);
|
|
return ret;
|
|
}
|
|
|
|
static int __exit ds1216_rtc_remove(struct platform_device *pdev)
|
|
{
|
|
struct ds1216_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
rtc_device_unregister(priv->rtc);
|
|
iounmap(priv->ioaddr);
|
|
release_mem_region(priv->baseaddr, priv->size);
|
|
kfree(priv);
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver ds1216_rtc_platform_driver = {
|
|
.driver = {
|
|
.name = "rtc-ds1216",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.remove = __exit_p(ds1216_rtc_remove),
|
|
};
|
|
|
|
static int __init ds1216_rtc_init(void)
|
|
{
|
|
return platform_driver_probe(&ds1216_rtc_platform_driver, ds1216_rtc_probe);
|
|
}
|
|
|
|
static void __exit ds1216_rtc_exit(void)
|
|
{
|
|
platform_driver_unregister(&ds1216_rtc_platform_driver);
|
|
}
|
|
|
|
MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
|
|
MODULE_DESCRIPTION("DS1216 RTC driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_VERSION(DRV_VERSION);
|
|
MODULE_ALIAS("platform:rtc-ds1216");
|
|
|
|
module_init(ds1216_rtc_init);
|
|
module_exit(ds1216_rtc_exit);
|