mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-22 20:23:57 +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>
237 lines
5.3 KiB
C
237 lines
5.3 KiB
C
/*
|
|
* Driver for the SGS-Thomson M48T35 Timekeeper RAM chip
|
|
*
|
|
* Copyright (C) 2000 Silicon Graphics, Inc.
|
|
* Written by Ulf Carlsson (ulfc@engr.sgi.com)
|
|
*
|
|
* Copyright (C) 2008 Thomas Bogendoerfer
|
|
*
|
|
* Based on code written by Paul Gortmaker.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms of the GNU General Public License as published by the
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
* option) any later version.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/rtc.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/bcd.h>
|
|
#include <linux/io.h>
|
|
|
|
#define DRV_VERSION "1.0"
|
|
|
|
struct m48t35_rtc {
|
|
u8 pad[0x7ff8]; /* starts at 0x7ff8 */
|
|
u8 control;
|
|
u8 sec;
|
|
u8 min;
|
|
u8 hour;
|
|
u8 day;
|
|
u8 date;
|
|
u8 month;
|
|
u8 year;
|
|
};
|
|
|
|
#define M48T35_RTC_SET 0x80
|
|
#define M48T35_RTC_READ 0x40
|
|
|
|
struct m48t35_priv {
|
|
struct rtc_device *rtc;
|
|
struct m48t35_rtc __iomem *reg;
|
|
size_t size;
|
|
unsigned long baseaddr;
|
|
spinlock_t lock;
|
|
};
|
|
|
|
static int m48t35_read_time(struct device *dev, struct rtc_time *tm)
|
|
{
|
|
struct m48t35_priv *priv = dev_get_drvdata(dev);
|
|
u8 control;
|
|
|
|
/*
|
|
* Only the values that we read from the RTC are set. We leave
|
|
* tm_wday, tm_yday and tm_isdst untouched. Even though the
|
|
* RTC has RTC_DAY_OF_WEEK, we ignore it, as it is only updated
|
|
* by the RTC when initially set to a non-zero value.
|
|
*/
|
|
spin_lock_irq(&priv->lock);
|
|
control = readb(&priv->reg->control);
|
|
writeb(control | M48T35_RTC_READ, &priv->reg->control);
|
|
tm->tm_sec = readb(&priv->reg->sec);
|
|
tm->tm_min = readb(&priv->reg->min);
|
|
tm->tm_hour = readb(&priv->reg->hour);
|
|
tm->tm_mday = readb(&priv->reg->date);
|
|
tm->tm_mon = readb(&priv->reg->month);
|
|
tm->tm_year = readb(&priv->reg->year);
|
|
writeb(control, &priv->reg->control);
|
|
spin_unlock_irq(&priv->lock);
|
|
|
|
tm->tm_sec = bcd2bin(tm->tm_sec);
|
|
tm->tm_min = bcd2bin(tm->tm_min);
|
|
tm->tm_hour = bcd2bin(tm->tm_hour);
|
|
tm->tm_mday = bcd2bin(tm->tm_mday);
|
|
tm->tm_mon = bcd2bin(tm->tm_mon);
|
|
tm->tm_year = bcd2bin(tm->tm_year);
|
|
|
|
/*
|
|
* Account for differences between how the RTC uses the values
|
|
* and how they are defined in a struct rtc_time;
|
|
*/
|
|
tm->tm_year += 70;
|
|
if (tm->tm_year <= 69)
|
|
tm->tm_year += 100;
|
|
|
|
tm->tm_mon--;
|
|
return rtc_valid_tm(tm);
|
|
}
|
|
|
|
static int m48t35_set_time(struct device *dev, struct rtc_time *tm)
|
|
{
|
|
struct m48t35_priv *priv = dev_get_drvdata(dev);
|
|
unsigned char mon, day, hrs, min, sec;
|
|
unsigned int yrs;
|
|
u8 control;
|
|
|
|
yrs = tm->tm_year + 1900;
|
|
mon = tm->tm_mon + 1; /* tm_mon starts at zero */
|
|
day = tm->tm_mday;
|
|
hrs = tm->tm_hour;
|
|
min = tm->tm_min;
|
|
sec = tm->tm_sec;
|
|
|
|
if (yrs < 1970)
|
|
return -EINVAL;
|
|
|
|
yrs -= 1970;
|
|
if (yrs > 255) /* They are unsigned */
|
|
return -EINVAL;
|
|
|
|
if (yrs > 169)
|
|
return -EINVAL;
|
|
|
|
if (yrs >= 100)
|
|
yrs -= 100;
|
|
|
|
sec = bin2bcd(sec);
|
|
min = bin2bcd(min);
|
|
hrs = bin2bcd(hrs);
|
|
day = bin2bcd(day);
|
|
mon = bin2bcd(mon);
|
|
yrs = bin2bcd(yrs);
|
|
|
|
spin_lock_irq(&priv->lock);
|
|
control = readb(&priv->reg->control);
|
|
writeb(control | M48T35_RTC_SET, &priv->reg->control);
|
|
writeb(yrs, &priv->reg->year);
|
|
writeb(mon, &priv->reg->month);
|
|
writeb(day, &priv->reg->date);
|
|
writeb(hrs, &priv->reg->hour);
|
|
writeb(min, &priv->reg->min);
|
|
writeb(sec, &priv->reg->sec);
|
|
writeb(control, &priv->reg->control);
|
|
spin_unlock_irq(&priv->lock);
|
|
return 0;
|
|
}
|
|
|
|
static const struct rtc_class_ops m48t35_ops = {
|
|
.read_time = m48t35_read_time,
|
|
.set_time = m48t35_set_time,
|
|
};
|
|
|
|
static int __devinit m48t35_probe(struct platform_device *pdev)
|
|
{
|
|
struct resource *res;
|
|
struct m48t35_priv *priv;
|
|
int ret = 0;
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
if (!res)
|
|
return -ENODEV;
|
|
priv = kzalloc(sizeof(struct m48t35_priv), GFP_KERNEL);
|
|
if (!priv)
|
|
return -ENOMEM;
|
|
|
|
priv->size = res->end - res->start + 1;
|
|
/*
|
|
* kludge: remove the #ifndef after ioc3 resource
|
|
* conflicts are resolved
|
|
*/
|
|
#ifndef CONFIG_SGI_IP27
|
|
if (!request_mem_region(res->start, priv->size, pdev->name)) {
|
|
ret = -EBUSY;
|
|
goto out;
|
|
}
|
|
#endif
|
|
priv->baseaddr = res->start;
|
|
priv->reg = ioremap(priv->baseaddr, priv->size);
|
|
if (!priv->reg) {
|
|
ret = -ENOMEM;
|
|
goto out;
|
|
}
|
|
|
|
spin_lock_init(&priv->lock);
|
|
|
|
platform_set_drvdata(pdev, priv);
|
|
|
|
priv->rtc = rtc_device_register("m48t35", &pdev->dev,
|
|
&m48t35_ops, THIS_MODULE);
|
|
if (IS_ERR(priv->rtc)) {
|
|
ret = PTR_ERR(priv->rtc);
|
|
goto out;
|
|
}
|
|
|
|
return 0;
|
|
|
|
out:
|
|
if (priv->reg)
|
|
iounmap(priv->reg);
|
|
if (priv->baseaddr)
|
|
release_mem_region(priv->baseaddr, priv->size);
|
|
kfree(priv);
|
|
return ret;
|
|
}
|
|
|
|
static int __devexit m48t35_remove(struct platform_device *pdev)
|
|
{
|
|
struct m48t35_priv *priv = platform_get_drvdata(pdev);
|
|
|
|
rtc_device_unregister(priv->rtc);
|
|
iounmap(priv->reg);
|
|
#ifndef CONFIG_SGI_IP27
|
|
release_mem_region(priv->baseaddr, priv->size);
|
|
#endif
|
|
kfree(priv);
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver m48t35_platform_driver = {
|
|
.driver = {
|
|
.name = "rtc-m48t35",
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.probe = m48t35_probe,
|
|
.remove = __devexit_p(m48t35_remove),
|
|
};
|
|
|
|
static int __init m48t35_init(void)
|
|
{
|
|
return platform_driver_register(&m48t35_platform_driver);
|
|
}
|
|
|
|
static void __exit m48t35_exit(void)
|
|
{
|
|
platform_driver_unregister(&m48t35_platform_driver);
|
|
}
|
|
|
|
MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
|
|
MODULE_DESCRIPTION("M48T35 RTC driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_VERSION(DRV_VERSION);
|
|
MODULE_ALIAS("platform:rtc-m48t35");
|
|
|
|
module_init(m48t35_init);
|
|
module_exit(m48t35_exit);
|