summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/sysfs.c3
-rw-r--r--drivers/base/attribute_container.c2
-rw-r--r--drivers/block/aoe/aoe.h11
-rw-r--r--drivers/block/aoe/aoecmd.c156
-rw-r--r--drivers/block/aoe/aoedev.c3
-rw-r--r--drivers/block/aoe/aoenet.c7
-rw-r--r--drivers/block/mtip32xx/mtip32xx.c3
-rw-r--r--drivers/block/nbd.c11
-rw-r--r--drivers/block/xen-blkback/xenbus.c2
-rw-r--r--drivers/cdrom/cdrom.c2
-rw-r--r--drivers/cdrom/gdrom.c2
-rw-r--r--drivers/char/mem.c47
-rw-r--r--drivers/devfreq/devfreq.c2
-rw-r--r--drivers/dma/dmaengine.c7
-rw-r--r--drivers/dma/ioat/dma.c3
-rw-r--r--drivers/dma/ioat/dma_v2.h1
-rw-r--r--drivers/dma/ioat/dma_v3.c114
-rw-r--r--drivers/dma/ioat/hw.h27
-rw-r--r--drivers/dma/iop-adma.c66
-rw-r--r--drivers/dma/mv_xor.c85
-rw-r--r--drivers/dma/mv_xor.h1
-rw-r--r--drivers/dma/pl330.c4
-rw-r--r--drivers/dma/ppc4xx/adma.c47
-rw-r--r--drivers/extcon/extcon-class.c2
-rw-r--r--drivers/firmware/dmi_scan.c12
-rw-r--r--drivers/gpu/drm/i915/intel_lvds.c16
-rw-r--r--drivers/gpu/drm/radeon/mkregtable.c13
-rw-r--r--drivers/hsi/hsi.c2
-rw-r--r--drivers/hwmon/adt7470.c2
-rw-r--r--drivers/ide/ide-cd.c2
-rw-r--r--drivers/ide/ide-gd.c2
-rw-r--r--drivers/ide/ide-probe.c4
-rw-r--r--drivers/ide/ide-tape.c2
-rw-r--r--drivers/infiniband/core/sysfs.c2
-rw-r--r--drivers/infiniband/hw/qib/qib_file_ops.c2
-rw-r--r--drivers/isdn/mISDN/dsp_pipeline.c2
-rw-r--r--drivers/media/i2c/tvaudio.c3
-rw-r--r--drivers/media/pci/cx18/cx18-driver.c2
-rw-r--r--drivers/media/pci/ivtv/ivtv-driver.c2
-rw-r--r--drivers/media/platform/vivi.c3
-rw-r--r--drivers/memstick/host/jmb38x_ms.c13
-rw-r--r--drivers/memstick/host/r592.c13
-rw-r--r--drivers/message/i2o/driver.c4
-rw-r--r--drivers/misc/sgi-gru/grufault.c5
-rw-r--r--drivers/mtd/mtdcore.c2
-rw-r--r--drivers/mtd/ubi/build.c2
-rw-r--r--drivers/net/rionet.c103
-rw-r--r--drivers/net/wireless/airo.c3
-rw-r--r--drivers/net/wireless/ipw2x00/ipw2200.c2
-rw-r--r--drivers/net/wireless/rt2x00/rt2x00dev.c2
-rw-r--r--drivers/net/wireless/rtlwifi/base.c2
-rw-r--r--drivers/parport/share.c3
-rw-r--r--drivers/pci/hotplug/pciehp_hpc.c4
-rw-r--r--drivers/pci/hotplug/shpchp_core.c3
-rw-r--r--drivers/platform/x86/wmi.c2
-rw-r--r--drivers/pps/clients/pps-gpio.c165
-rw-r--r--drivers/rapidio/Kconfig5
-rw-r--r--drivers/rapidio/Makefile4
-rw-r--r--drivers/rapidio/devices/Kconfig2
-rw-r--r--drivers/rapidio/devices/Makefile7
-rw-r--r--drivers/rapidio/devices/tsi721.c9
-rw-r--r--drivers/rapidio/rio-driver.c18
-rw-r--r--drivers/rapidio/rio-scan.c181
-rw-r--r--drivers/rapidio/rio-sysfs.c31
-rw-r--r--drivers/rapidio/rio.c490
-rw-r--r--drivers/rapidio/rio.h44
-rw-r--r--drivers/rapidio/switches/Kconfig19
-rw-r--r--drivers/rapidio/switches/Makefile1
-rw-r--r--drivers/rapidio/switches/idt_gen2.c98
-rw-r--r--drivers/rapidio/switches/idtcps.c86
-rw-r--r--drivers/rapidio/switches/tsi500.c78
-rw-r--r--drivers/rapidio/switches/tsi568.c71
-rw-r--r--drivers/rapidio/switches/tsi57x.c81
-rw-r--r--drivers/rtc/Kconfig16
-rw-r--r--drivers/rtc/Makefile2
-rw-r--r--drivers/rtc/class.c12
-rw-r--r--drivers/rtc/interface.c26
-rw-r--r--drivers/rtc/rtc-88pm80x.c1
-rw-r--r--drivers/rtc/rtc-88pm860x.c1
-rw-r--r--drivers/rtc/rtc-ab3100.c7
-rw-r--r--drivers/rtc/rtc-ab8500.c65
-rw-r--r--drivers/rtc/rtc-at32ap700x.c22
-rw-r--r--drivers/rtc/rtc-at91rm9200.c4
-rw-r--r--drivers/rtc/rtc-at91sam9.c19
-rw-r--r--drivers/rtc/rtc-au1xxx.c8
-rw-r--r--drivers/rtc/rtc-bfin.c1
-rw-r--r--drivers/rtc/rtc-bq32k.c6
-rw-r--r--drivers/rtc/rtc-bq4802.c8
-rw-r--r--drivers/rtc/rtc-cmos.c41
-rw-r--r--drivers/rtc/rtc-coh901331.c9
-rw-r--r--drivers/rtc/rtc-da9052.c14
-rw-r--r--drivers/rtc/rtc-da9055.c8
-rw-r--r--drivers/rtc/rtc-davinci.c13
-rw-r--r--drivers/rtc/rtc-dm355evm.c7
-rw-r--r--drivers/rtc/rtc-ds1216.c19
-rw-r--r--drivers/rtc/rtc-ds1286.c6
-rw-r--r--drivers/rtc/rtc-ds1302.c15
-rw-r--r--drivers/rtc/rtc-ds1305.c32
-rw-r--r--drivers/rtc/rtc-ds1307.c43
-rw-r--r--drivers/rtc/rtc-ds1374.c11
-rw-r--r--drivers/rtc/rtc-ds1390.c6
-rw-r--r--drivers/rtc/rtc-ds1511.c93
-rw-r--r--drivers/rtc/rtc-ds1672.c6
-rw-r--r--drivers/rtc/rtc-ds3234.c8
-rw-r--r--drivers/rtc/rtc-efi.c6
-rw-r--r--drivers/rtc/rtc-em3027.c6
-rw-r--r--drivers/rtc/rtc-ep93xx.c2
-rw-r--r--drivers/rtc/rtc-fm3130.c8
-rw-r--r--drivers/rtc/rtc-generic.c6
-rw-r--r--drivers/rtc/rtc-hid-sensor-time.c48
-rw-r--r--drivers/rtc/rtc-isl12022.c12
-rw-r--r--drivers/rtc/rtc-jz4740.c68
-rw-r--r--drivers/rtc/rtc-lp8788.c8
-rw-r--r--drivers/rtc/rtc-lpc32xx.c3
-rw-r--r--drivers/rtc/rtc-ls1x.c8
-rw-r--r--drivers/rtc/rtc-m41t80.c2
-rw-r--r--drivers/rtc/rtc-m41t93.c7
-rw-r--r--drivers/rtc/rtc-m41t94.c6
-rw-r--r--drivers/rtc/rtc-m48t35.c12
-rw-r--r--drivers/rtc/rtc-m48t59.c54
-rw-r--r--drivers/rtc/rtc-m48t86.c8
-rw-r--r--drivers/rtc/rtc-max6900.c6
-rw-r--r--drivers/rtc/rtc-max6902.c12
-rw-r--r--drivers/rtc/rtc-max77686.c8
-rw-r--r--drivers/rtc/rtc-max8907.c6
-rw-r--r--drivers/rtc/rtc-max8925.c13
-rw-r--r--drivers/rtc/rtc-max8997.c8
-rw-r--r--drivers/rtc/rtc-max8998.c12
-rw-r--r--drivers/rtc/rtc-mc13xxx.c4
-rw-r--r--drivers/rtc/rtc-mpc5121.c20
-rw-r--r--drivers/rtc/rtc-msm6242.c21
-rw-r--r--drivers/rtc/rtc-mxc.c7
-rw-r--r--drivers/rtc/rtc-nuc900.c8
-rw-r--r--drivers/rtc/rtc-omap.c6
-rw-r--r--drivers/rtc/rtc-palmas.c2
-rw-r--r--drivers/rtc/rtc-pcap.c13
-rw-r--r--drivers/rtc/rtc-pcf2123.c25
-rw-r--r--drivers/rtc/rtc-pcf2127.c241
-rw-r--r--drivers/rtc/rtc-pcf8523.c6
-rw-r--r--drivers/rtc/rtc-pcf8563.c12
-rw-r--r--drivers/rtc/rtc-pcf8583.c15
-rw-r--r--drivers/rtc/rtc-pm8xxx.c29
-rw-r--r--drivers/rtc/rtc-ps3.c6
-rw-r--r--drivers/rtc/rtc-puv3.c1
-rw-r--r--drivers/rtc/rtc-pxa.c43
-rw-r--r--drivers/rtc/rtc-rc5t583.c2
-rw-r--r--drivers/rtc/rtc-rp5c01.c12
-rw-r--r--drivers/rtc/rtc-rs5c313.c24
-rw-r--r--drivers/rtc/rtc-rs5c348.c6
-rw-r--r--drivers/rtc/rtc-rv3029c2.c8
-rw-r--r--drivers/rtc/rtc-rx4581.c6
-rw-r--r--drivers/rtc/rtc-rx8025.c18
-rw-r--r--drivers/rtc/rtc-rx8581.c6
-rw-r--r--drivers/rtc/rtc-s3c.c9
-rw-r--r--drivers/rtc/rtc-sa1100.c8
-rw-r--r--drivers/rtc/rtc-sh.c74
-rw-r--r--drivers/rtc/rtc-sirfsoc.c475
-rw-r--r--drivers/rtc/rtc-snvs.c6
-rw-r--r--drivers/rtc/rtc-spear.c1
-rw-r--r--drivers/rtc/rtc-starfire.c6
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c13
-rw-r--r--drivers/rtc/rtc-sun4v.c6
-rw-r--r--drivers/rtc/rtc-sysfs.c20
-rw-r--r--drivers/rtc/rtc-tile.c11
-rw-r--r--drivers/rtc/rtc-tps80031.c6
-rw-r--r--drivers/rtc/rtc-twl.c40
-rw-r--r--drivers/rtc/rtc-v3020.c18
-rw-r--r--drivers/rtc/rtc-vr41xx.c16
-rw-r--r--drivers/rtc/rtc-vt8500.c2
-rw-r--r--drivers/rtc/rtc-wm831x.c6
-rw-r--r--drivers/rtc/rtc-x1205.c33
-rw-r--r--drivers/s390/net/qeth_l3_sys.c6
-rw-r--r--drivers/scsi/aacraid/commctrl.c3
-rw-r--r--drivers/scsi/aacraid/commsup.c3
-rw-r--r--drivers/scsi/be2iscsi/be_main.c2
-rw-r--r--drivers/scsi/osd/osd_uld.c2
-rw-r--r--drivers/scsi/qla4xxx/ql4_os.c4
-rw-r--r--drivers/scsi/scsi_transport_fc.c6
-rw-r--r--drivers/scsi/sd.c2
-rw-r--r--drivers/spi/spi.c2
-rw-r--r--drivers/staging/android/timed_output.c2
-rw-r--r--drivers/staging/dgrp/dgrp_sysfs.c2
-rw-r--r--drivers/staging/rtl8712/os_intfs.c2
-rw-r--r--drivers/staging/tidspbridge/rmgr/drv_interface.c3
-rw-r--r--drivers/uio/uio.c2
-rw-r--r--drivers/usb/atm/usbatm.c5
-rw-r--r--drivers/uwb/lc-dev.c2
-rw-r--r--drivers/video/backlight/atmel-pwm-bl.c2
-rw-r--r--drivers/video/backlight/backlight.c87
-rw-r--r--drivers/video/backlight/ep93xx_bl.c1
-rw-r--r--drivers/video/backlight/lcd.c72
-rw-r--r--drivers/video/backlight/lp8788_bl.c1
-rw-r--r--drivers/video/backlight/pcf50633-backlight.c2
-rw-r--r--drivers/video/output.c2
-rw-r--r--drivers/virtio/virtio_balloon.c7
-rw-r--r--drivers/w1/slaves/w1_ds2408.c30
-rw-r--r--drivers/xen/balloon.c23
-rw-r--r--drivers/xen/xenbus/xenbus_probe.c2
198 files changed, 2567 insertions, 2091 deletions
diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
index 5c5d1624fa2c..05306a59aedc 100644
--- a/drivers/acpi/sysfs.c
+++ b/drivers/acpi/sysfs.c
@@ -677,10 +677,9 @@ void acpi_irq_stats_init(void)
677 else 677 else
678 sprintf(buffer, "bug%02X", i); 678 sprintf(buffer, "bug%02X", i);
679 679
680 name = kzalloc(strlen(buffer) + 1, GFP_KERNEL); 680 name = kstrdup(buffer, GFP_KERNEL);
681 if (name == NULL) 681 if (name == NULL)
682 goto fail; 682 goto fail;
683 strncpy(name, buffer, strlen(buffer) + 1);
684 683
685 sysfs_attr_init(&counter_attrs[i].attr); 684 sysfs_attr_init(&counter_attrs[i].attr);
686 counter_attrs[i].attr.name = name; 685 counter_attrs[i].attr.name = name;
diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
index d78b204e65c1..ecc1929d7f6a 100644
--- a/drivers/base/attribute_container.c
+++ b/drivers/base/attribute_container.c
@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
167 ic->classdev.parent = get_device(dev); 167 ic->classdev.parent = get_device(dev);
168 ic->classdev.class = cont->class; 168 ic->classdev.class = cont->class;
169 cont->class->dev_release = attribute_container_release; 169 cont->class->dev_release = attribute_container_release;
170 dev_set_name(&ic->classdev, dev_name(dev)); 170 dev_set_name(&ic->classdev, "%s", dev_name(dev));
171 if (fn) 171 if (fn)
172 fn(cont, dev, &ic->classdev); 172 fn(cont, dev, &ic->classdev);
173 else 173 else
diff --git a/drivers/block/aoe/aoe.h b/drivers/block/aoe/aoe.h
index 175649468c95..025c41d3cb33 100644
--- a/drivers/block/aoe/aoe.h
+++ b/drivers/block/aoe/aoe.h
@@ -1,5 +1,5 @@
1/* Copyright (c) 2012 Coraid, Inc. See COPYING for GPL terms. */ 1/* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */
2#define VERSION "81" 2#define VERSION "83"
3#define AOE_MAJOR 152 3#define AOE_MAJOR 152
4#define DEVICE_NAME "aoe" 4#define DEVICE_NAME "aoe"
5 5
@@ -196,9 +196,11 @@ struct ktstate {
196 struct completion rendez; 196 struct completion rendez;
197 struct task_struct *task; 197 struct task_struct *task;
198 wait_queue_head_t *waitq; 198 wait_queue_head_t *waitq;
199 int (*fn) (void); 199 int (*fn) (int);
200 char *name; 200 char name[12];
201 spinlock_t *lock; 201 spinlock_t *lock;
202 int id;
203 int active;
202}; 204};
203 205
204int aoeblk_init(void); 206int aoeblk_init(void);
@@ -222,6 +224,7 @@ int aoecmd_init(void);
222struct sk_buff *aoecmd_ata_id(struct aoedev *); 224struct sk_buff *aoecmd_ata_id(struct aoedev *);
223void aoe_freetframe(struct frame *); 225void aoe_freetframe(struct frame *);
224void aoe_flush_iocq(void); 226void aoe_flush_iocq(void);
227void aoe_flush_iocq_by_index(int);
225void aoe_end_request(struct aoedev *, struct request *, int); 228void aoe_end_request(struct aoedev *, struct request *, int);
226int aoe_ktstart(struct ktstate *k); 229int aoe_ktstart(struct ktstate *k);
227void aoe_ktstop(struct ktstate *k); 230void aoe_ktstop(struct ktstate *k);
diff --git a/drivers/block/aoe/aoecmd.c b/drivers/block/aoe/aoecmd.c
index fc803ecbbce4..99cb944a002d 100644
--- a/drivers/block/aoe/aoecmd.c
+++ b/drivers/block/aoe/aoecmd.c
@@ -1,4 +1,4 @@
1/* Copyright (c) 2012 Coraid, Inc. See COPYING for GPL terms. */ 1/* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */
2/* 2/*
3 * aoecmd.c 3 * aoecmd.c
4 * Filesystem request handling methods 4 * Filesystem request handling methods
@@ -35,14 +35,27 @@ module_param(aoe_maxout, int, 0644);
35MODULE_PARM_DESC(aoe_maxout, 35MODULE_PARM_DESC(aoe_maxout,
36 "Only aoe_maxout outstanding packets for every MAC on eX.Y."); 36 "Only aoe_maxout outstanding packets for every MAC on eX.Y.");
37 37
38static wait_queue_head_t ktiowq; 38/* The number of online cpus during module initialization gives us a
39static struct ktstate kts; 39 * convenient heuristic cap on the parallelism used for ktio threads
40 * doing I/O completion. It is not important that the cap equal the
41 * actual number of running CPUs at any given time, but because of CPU
42 * hotplug, we take care to use ncpus instead of using
43 * num_online_cpus() after module initialization.
44 */
45static int ncpus;
46
47/* mutex lock used for synchronization while thread spawning */
48static DEFINE_MUTEX(ktio_spawn_lock);
49
50static wait_queue_head_t *ktiowq;
51static struct ktstate *kts;
40 52
41/* io completion queue */ 53/* io completion queue */
42static struct { 54struct iocq_ktio {
43 struct list_head head; 55 struct list_head head;
44 spinlock_t lock; 56 spinlock_t lock;
45} iocq; 57};
58static struct iocq_ktio *iocq;
46 59
47static struct page *empty_page; 60static struct page *empty_page;
48 61
@@ -1278,23 +1291,36 @@ out:
1278 * Returns true iff responses needing processing remain. 1291 * Returns true iff responses needing processing remain.
1279 */ 1292 */
1280static int 1293static int
1281ktio(void) 1294ktio(int id)
1282{ 1295{
1283 struct frame *f; 1296 struct frame *f;
1284 struct list_head *pos; 1297 struct list_head *pos;
1285 int i; 1298 int i;
1299 int actual_id;
1286 1300
1287 for (i = 0; ; ++i) { 1301 for (i = 0; ; ++i) {
1288 if (i == MAXIOC) 1302 if (i == MAXIOC)
1289 return 1; 1303 return 1;
1290 if (list_empty(&iocq.head)) 1304 if (list_empty(&iocq[id].head))
1291 return 0; 1305 return 0;
1292 pos = iocq.head.next; 1306 pos = iocq[id].head.next;
1293 list_del(pos); 1307 list_del(pos);
1294 spin_unlock_irq(&iocq.lock);
1295 f = list_entry(pos, struct frame, head); 1308 f = list_entry(pos, struct frame, head);
1309 spin_unlock_irq(&iocq[id].lock);
1296 ktiocomplete(f); 1310 ktiocomplete(f);
1297 spin_lock_irq(&iocq.lock); 1311
1312 /* Figure out if extra threads are required. */
1313 actual_id = f->t->d->aoeminor % ncpus;
1314
1315 if (!kts[actual_id].active) {
1316 BUG_ON(id != 0);
1317 mutex_lock(&ktio_spawn_lock);
1318 if (!kts[actual_id].active
1319 && aoe_ktstart(&kts[actual_id]) == 0)
1320 kts[actual_id].active = 1;
1321 mutex_unlock(&ktio_spawn_lock);
1322 }
1323 spin_lock_irq(&iocq[id].lock);
1298 } 1324 }
1299} 1325}
1300 1326
@@ -1311,7 +1337,7 @@ kthread(void *vp)
1311 complete(&k->rendez); /* tell spawner we're running */ 1337 complete(&k->rendez); /* tell spawner we're running */
1312 do { 1338 do {
1313 spin_lock_irq(k->lock); 1339 spin_lock_irq(k->lock);
1314 more = k->fn(); 1340 more = k->fn(k->id);
1315 if (!more) { 1341 if (!more) {
1316 add_wait_queue(k->waitq, &wait); 1342 add_wait_queue(k->waitq, &wait);
1317 __set_current_state(TASK_INTERRUPTIBLE); 1343 __set_current_state(TASK_INTERRUPTIBLE);
@@ -1340,7 +1366,7 @@ aoe_ktstart(struct ktstate *k)
1340 struct task_struct *task; 1366 struct task_struct *task;
1341 1367
1342 init_completion(&k->rendez); 1368 init_completion(&k->rendez);
1343 task = kthread_run(kthread, k, k->name); 1369 task = kthread_run(kthread, k, "%s", k->name);
1344 if (task == NULL || IS_ERR(task)) 1370 if (task == NULL || IS_ERR(task))
1345 return -ENOMEM; 1371 return -ENOMEM;
1346 k->task = task; 1372 k->task = task;
@@ -1353,13 +1379,24 @@ aoe_ktstart(struct ktstate *k)
1353static void 1379static void
1354ktcomplete(struct frame *f, struct sk_buff *skb) 1380ktcomplete(struct frame *f, struct sk_buff *skb)
1355{ 1381{
1382 int id;
1356 ulong flags; 1383 ulong flags;
1357 1384
1358 f->r_skb = skb; 1385 f->r_skb = skb;
1359 spin_lock_irqsave(&iocq.lock, flags); 1386 id = f->t->d->aoeminor % ncpus;
1360 list_add_tail(&f->head, &iocq.head); 1387 spin_lock_irqsave(&iocq[id].lock, flags);
1361 spin_unlock_irqrestore(&iocq.lock, flags); 1388 if (!kts[id].active) {
1362 wake_up(&ktiowq); 1389 spin_unlock_irqrestore(&iocq[id].lock, flags);
1390 /* The thread with id has not been spawned yet,
1391 * so delegate the work to the main thread and
1392 * try spawning a new thread.
1393 */
1394 id = 0;
1395 spin_lock_irqsave(&iocq[id].lock, flags);
1396 }
1397 list_add_tail(&f->head, &iocq[id].head);
1398 spin_unlock_irqrestore(&iocq[id].lock, flags);
1399 wake_up(&ktiowq[id]);
1363} 1400}
1364 1401
1365struct sk_buff * 1402struct sk_buff *
@@ -1706,6 +1743,17 @@ aoe_failbuf(struct aoedev *d, struct buf *buf)
1706void 1743void
1707aoe_flush_iocq(void) 1744aoe_flush_iocq(void)
1708{ 1745{
1746 int i;
1747
1748 for (i = 0; i < ncpus; i++) {
1749 if (kts[i].active)
1750 aoe_flush_iocq_by_index(i);
1751 }
1752}
1753
1754void
1755aoe_flush_iocq_by_index(int id)
1756{
1709 struct frame *f; 1757 struct frame *f;
1710 struct aoedev *d; 1758 struct aoedev *d;
1711 LIST_HEAD(flist); 1759 LIST_HEAD(flist);
@@ -1713,9 +1761,9 @@ aoe_flush_iocq(void)
1713 struct sk_buff *skb; 1761 struct sk_buff *skb;
1714 ulong flags; 1762 ulong flags;
1715 1763
1716 spin_lock_irqsave(&iocq.lock, flags); 1764 spin_lock_irqsave(&iocq[id].lock, flags);
1717 list_splice_init(&iocq.head, &flist); 1765 list_splice_init(&iocq[id].head, &flist);
1718 spin_unlock_irqrestore(&iocq.lock, flags); 1766 spin_unlock_irqrestore(&iocq[id].lock, flags);
1719 while (!list_empty(&flist)) { 1767 while (!list_empty(&flist)) {
1720 pos = flist.next; 1768 pos = flist.next;
1721 list_del(pos); 1769 list_del(pos);
@@ -1738,6 +1786,8 @@ int __init
1738aoecmd_init(void) 1786aoecmd_init(void)
1739{ 1787{
1740 void *p; 1788 void *p;
1789 int i;
1790 int ret;
1741 1791
1742 /* get_zeroed_page returns page with ref count 1 */ 1792 /* get_zeroed_page returns page with ref count 1 */
1743 p = (void *) get_zeroed_page(GFP_KERNEL | __GFP_REPEAT); 1793 p = (void *) get_zeroed_page(GFP_KERNEL | __GFP_REPEAT);
@@ -1745,22 +1795,72 @@ aoecmd_init(void)
1745 return -ENOMEM; 1795 return -ENOMEM;
1746 empty_page = virt_to_page(p); 1796 empty_page = virt_to_page(p);
1747 1797
1748 INIT_LIST_HEAD(&iocq.head); 1798 ncpus = num_online_cpus();
1749 spin_lock_init(&iocq.lock); 1799
1750 init_waitqueue_head(&ktiowq); 1800 iocq = kcalloc(ncpus, sizeof(struct iocq_ktio), GFP_KERNEL);
1751 kts.name = "aoe_ktio"; 1801 if (!iocq)
1752 kts.fn = ktio; 1802 return -ENOMEM;
1753 kts.waitq = &ktiowq; 1803
1754 kts.lock = &iocq.lock; 1804 kts = kcalloc(ncpus, sizeof(struct ktstate), GFP_KERNEL);
1755 return aoe_ktstart(&kts); 1805 if (!kts) {
1806 ret = -ENOMEM;
1807 goto kts_fail;
1808 }
1809
1810 ktiowq = kcalloc(ncpus, sizeof(wait_queue_head_t), GFP_KERNEL);
1811 if (!ktiowq) {
1812 ret = -ENOMEM;
1813 goto ktiowq_fail;
1814 }
1815
1816 mutex_init(&ktio_spawn_lock);
1817
1818 for (i = 0; i < ncpus; i++) {
1819 INIT_LIST_HEAD(&iocq[i].head);
1820 spin_lock_init(&iocq[i].lock);
1821 init_waitqueue_head(&ktiowq[i]);
1822 snprintf(kts[i].name, sizeof(kts[i].name), "aoe_ktio%d", i);
1823 kts[i].fn = ktio;
1824 kts[i].waitq = &ktiowq[i];
1825 kts[i].lock = &iocq[i].lock;
1826 kts[i].id = i;
1827 kts[i].active = 0;
1828 }
1829 kts[0].active = 1;
1830 if (aoe_ktstart(&kts[0])) {
1831 ret = -ENOMEM;
1832 goto ktstart_fail;
1833 }
1834 return 0;
1835
1836ktstart_fail:
1837 kfree(ktiowq);
1838ktiowq_fail:
1839 kfree(kts);
1840kts_fail:
1841 kfree(iocq);
1842
1843 return ret;
1756} 1844}
1757 1845
1758void 1846void
1759aoecmd_exit(void) 1847aoecmd_exit(void)
1760{ 1848{
1761 aoe_ktstop(&kts); 1849 int i;
1850
1851 for (i = 0; i < ncpus; i++)
1852 if (kts[i].active)
1853 aoe_ktstop(&kts[i]);
1854
1762 aoe_flush_iocq(); 1855 aoe_flush_iocq();
1763 1856
1857 /* Free up the iocq and thread speicific configuration
1858 * allocated during startup.
1859 */
1860 kfree(iocq);
1861 kfree(kts);
1862 kfree(ktiowq);
1863
1764 free_page((unsigned long) page_address(empty_page)); 1864 free_page((unsigned long) page_address(empty_page));
1765 empty_page = NULL; 1865 empty_page = NULL;
1766} 1866}
diff --git a/drivers/block/aoe/aoedev.c b/drivers/block/aoe/aoedev.c
index 98f2965778b9..784c92e038d1 100644
--- a/drivers/block/aoe/aoedev.c
+++ b/drivers/block/aoe/aoedev.c
@@ -1,4 +1,4 @@
1/* Copyright (c) 2012 Coraid, Inc. See COPYING for GPL terms. */ 1/* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */
2/* 2/*
3 * aoedev.c 3 * aoedev.c
4 * AoE device utility functions; maintains device list. 4 * AoE device utility functions; maintains device list.
@@ -518,7 +518,6 @@ void
518aoedev_exit(void) 518aoedev_exit(void)
519{ 519{
520 flush_scheduled_work(); 520 flush_scheduled_work();
521 aoe_flush_iocq();
522 flush(NULL, 0, EXITING); 521 flush(NULL, 0, EXITING);
523} 522}
524 523
diff --git a/drivers/block/aoe/aoenet.c b/drivers/block/aoe/aoenet.c
index 71d3ea8d3006..63773a90581d 100644
--- a/drivers/block/aoe/aoenet.c
+++ b/drivers/block/aoe/aoenet.c
@@ -1,4 +1,4 @@
1/* Copyright (c) 2012 Coraid, Inc. See COPYING for GPL terms. */ 1/* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */
2/* 2/*
3 * aoenet.c 3 * aoenet.c
4 * Ethernet portion of AoE driver 4 * Ethernet portion of AoE driver
@@ -52,7 +52,7 @@ static struct sk_buff_head skbtxq;
52 52
53/* enters with txlock held */ 53/* enters with txlock held */
54static int 54static int
55tx(void) __must_hold(&txlock) 55tx(int id) __must_hold(&txlock)
56{ 56{
57 struct sk_buff *skb; 57 struct sk_buff *skb;
58 struct net_device *ifp; 58 struct net_device *ifp;
@@ -205,7 +205,8 @@ aoenet_init(void)
205 kts.lock = &txlock; 205 kts.lock = &txlock;
206 kts.fn = tx; 206 kts.fn = tx;
207 kts.waitq = &txwq; 207 kts.waitq = &txwq;
208 kts.name = "aoe_tx"; 208 kts.id = 0;
209 snprintf(kts.name, sizeof(kts.name), "aoe_tx%d", kts.id);
209 if (aoe_ktstart(&kts)) 210 if (aoe_ktstart(&kts))
210 return -EAGAIN; 211 return -EAGAIN;
211 dev_add_pack(&aoe_pt); 212 dev_add_pack(&aoe_pt);
diff --git a/drivers/block/mtip32xx/mtip32xx.c b/drivers/block/mtip32xx/mtip32xx.c
index 20dd52a2f92f..952dbfe22126 100644
--- a/drivers/block/mtip32xx/mtip32xx.c
+++ b/drivers/block/mtip32xx/mtip32xx.c
@@ -4087,7 +4087,8 @@ skip_create_disk:
4087start_service_thread: 4087start_service_thread:
4088 sprintf(thd_name, "mtip_svc_thd_%02d", index); 4088 sprintf(thd_name, "mtip_svc_thd_%02d", index);
4089 dd->mtip_svc_handler = kthread_create_on_node(mtip_service_thread, 4089 dd->mtip_svc_handler = kthread_create_on_node(mtip_service_thread,
4090 dd, dd->numa_node, thd_name); 4090 dd, dd->numa_node, "%s",
4091 thd_name);
4091 4092
4092 if (IS_ERR(dd->mtip_svc_handler)) { 4093 if (IS_ERR(dd->mtip_svc_handler)) {
4093 dev_err(&dd->pdev->dev, "service thread failed to start\n"); 4094 dev_err(&dd->pdev->dev, "service thread failed to start\n");
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 037288e7874d..2dc3b5153f0d 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -623,8 +623,10 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
623 if (!nbd->sock) 623 if (!nbd->sock)
624 return -EINVAL; 624 return -EINVAL;
625 625
626 nbd->disconnect = 1;
627
626 nbd_send_req(nbd, &sreq); 628 nbd_send_req(nbd, &sreq);
627 return 0; 629 return 0;
628 } 630 }
629 631
630 case NBD_CLEAR_SOCK: { 632 case NBD_CLEAR_SOCK: {
@@ -654,6 +656,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
654 nbd->sock = SOCKET_I(inode); 656 nbd->sock = SOCKET_I(inode);
655 if (max_part > 0) 657 if (max_part > 0)
656 bdev->bd_invalidated = 1; 658 bdev->bd_invalidated = 1;
659 nbd->disconnect = 0; /* we're connected now */
657 return 0; 660 return 0;
658 } else { 661 } else {
659 fput(file); 662 fput(file);
@@ -714,7 +717,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
714 else 717 else
715 blk_queue_flush(nbd->disk->queue, 0); 718 blk_queue_flush(nbd->disk->queue, 0);
716 719
717 thread = kthread_create(nbd_thread, nbd, nbd->disk->disk_name); 720 thread = kthread_create(nbd_thread, nbd, "%s",
721 nbd->disk->disk_name);
718 if (IS_ERR(thread)) { 722 if (IS_ERR(thread)) {
719 mutex_lock(&nbd->tx_lock); 723 mutex_lock(&nbd->tx_lock);
720 return PTR_ERR(thread); 724 return PTR_ERR(thread);
@@ -742,6 +746,8 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
742 set_capacity(nbd->disk, 0); 746 set_capacity(nbd->disk, 0);
743 if (max_part > 0) 747 if (max_part > 0)
744 ioctl_by_bdev(bdev, BLKRRPART, 0); 748 ioctl_by_bdev(bdev, BLKRRPART, 0);
749 if (nbd->disconnect) /* user requested, ignore socket errors */
750 return 0;
745 return nbd->harderror; 751 return nbd->harderror;
746 } 752 }
747 753
@@ -750,7 +756,6 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
750 * This is for compatibility only. The queue is always cleared 756 * This is for compatibility only. The queue is always cleared
751 * by NBD_DO_IT or NBD_CLEAR_SOCK. 757 * by NBD_DO_IT or NBD_CLEAR_SOCK.
752 */ 758 */
753 BUG_ON(!nbd->sock && !list_empty(&nbd->queue_head));
754 return 0; 759 return 0;
755 760
756 case NBD_PRINT_DEBUG: 761 case NBD_PRINT_DEBUG:
diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 8bfd1bcf95ec..04608a6502d7 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -93,7 +93,7 @@ static void xen_update_blkif_status(struct xen_blkif *blkif)
93 } 93 }
94 invalidate_inode_pages2(blkif->vbd.bdev->bd_inode->i_mapping); 94 invalidate_inode_pages2(blkif->vbd.bdev->bd_inode->i_mapping);
95 95
96 blkif->xenblkd = kthread_run(xen_blkif_schedule, blkif, name); 96 blkif->xenblkd = kthread_run(xen_blkif_schedule, blkif, "%s", name);
97 if (IS_ERR(blkif->xenblkd)) { 97 if (IS_ERR(blkif->xenblkd)) {
98 err = PTR_ERR(blkif->xenblkd); 98 err = PTR_ERR(blkif->xenblkd);
99 blkif->xenblkd = NULL; 99 blkif->xenblkd = NULL;
diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
index d620b4495745..8a3aff724d98 100644
--- a/drivers/cdrom/cdrom.c
+++ b/drivers/cdrom/cdrom.c
@@ -2882,7 +2882,7 @@ static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi,
2882 if (lba < 0) 2882 if (lba < 0)
2883 return -EINVAL; 2883 return -EINVAL;
2884 2884
2885 cgc->buffer = kmalloc(blocksize, GFP_KERNEL); 2885 cgc->buffer = kzalloc(blocksize, GFP_KERNEL);
2886 if (cgc->buffer == NULL) 2886 if (cgc->buffer == NULL)
2887 return -ENOMEM; 2887 return -ENOMEM;
2888 2888
diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
index 4afcb65cc623..5980cb9af857 100644
--- a/drivers/cdrom/gdrom.c
+++ b/drivers/cdrom/gdrom.c
@@ -830,9 +830,9 @@ probe_fail_cdrom_register:
830 del_gendisk(gd.disk); 830 del_gendisk(gd.disk);
831probe_fail_no_disk: 831probe_fail_no_disk:
832 kfree(gd.cd_info); 832 kfree(gd.cd_info);
833probe_fail_no_mem:
833 unregister_blkdev(gdrom_major, GDROM_DEV_NAME); 834 unregister_blkdev(gdrom_major, GDROM_DEV_NAME);
834 gdrom_major = 0; 835 gdrom_major = 0;
835probe_fail_no_mem:
836 pr_warning("Probe failed - error is 0x%X\n", err); 836 pr_warning("Probe failed - error is 0x%X\n", err);
837 return err; 837 return err;
838} 838}
diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 2ca6d7844ad9..f895a8c8a244 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -21,7 +21,6 @@
21#include <linux/ptrace.h> 21#include <linux/ptrace.h>
22#include <linux/device.h> 22#include <linux/device.h>
23#include <linux/highmem.h> 23#include <linux/highmem.h>
24#include <linux/crash_dump.h>
25#include <linux/backing-dev.h> 24#include <linux/backing-dev.h>
26#include <linux/bootmem.h> 25#include <linux/bootmem.h>
27#include <linux/splice.h> 26#include <linux/splice.h>
@@ -357,40 +356,6 @@ static int mmap_kmem(struct file *file, struct vm_area_struct *vma)
357} 356}
358#endif 357#endif
359 358
360#ifdef CONFIG_CRASH_DUMP
361/*
362 * Read memory corresponding to the old kernel.
363 */
364static ssize_t read_oldmem(struct file *file, char __user *buf,
365 size_t count, loff_t *ppos)
366{
367 unsigned long pfn, offset;
368 size_t read = 0, csize;
369 int rc = 0;
370
371 while (count) {
372 pfn = *ppos / PAGE_SIZE;
373 if (pfn > saved_max_pfn)
374 return read;
375
376 offset = (unsigned long)(*ppos % PAGE_SIZE);
377 if (count > PAGE_SIZE - offset)
378 csize = PAGE_SIZE - offset;
379 else
380 csize = count;
381
382 rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
383 if (rc < 0)
384 return rc;
385 buf += csize;
386 *ppos += csize;
387 read += csize;
388 count -= csize;
389 }
390 return read;
391}
392#endif
393
394#ifdef CONFIG_DEVKMEM 359#ifdef CONFIG_DEVKMEM
395/* 360/*
396 * This function reads the *virtual* memory as seen by the kernel. 361 * This function reads the *virtual* memory as seen by the kernel.
@@ -772,7 +737,6 @@ static int open_port(struct inode *inode, struct file *filp)
772#define aio_write_zero aio_write_null 737#define aio_write_zero aio_write_null
773#define open_mem open_port 738#define open_mem open_port
774#define open_kmem open_mem 739#define open_kmem open_mem
775#define open_oldmem open_mem
776 740
777static const struct file_operations mem_fops = { 741static const struct file_operations mem_fops = {
778 .llseek = memory_lseek, 742 .llseek = memory_lseek,
@@ -837,14 +801,6 @@ static const struct file_operations full_fops = {
837 .write = write_full, 801 .write = write_full,
838}; 802};
839 803
840#ifdef CONFIG_CRASH_DUMP
841static const struct file_operations oldmem_fops = {
842 .read = read_oldmem,
843 .open = open_oldmem,
844 .llseek = default_llseek,
845};
846#endif
847
848static const struct memdev { 804static const struct memdev {
849 const char *name; 805 const char *name;
850 umode_t mode; 806 umode_t mode;
@@ -866,9 +822,6 @@ static const struct memdev {
866#ifdef CONFIG_PRINTK 822#ifdef CONFIG_PRINTK
867 [11] = { "kmsg", 0644, &kmsg_fops, NULL }, 823 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
868#endif 824#endif
869#ifdef CONFIG_CRASH_DUMP
870 [12] = { "oldmem", 0, &oldmem_fops, NULL },
871#endif
872}; 825};
873 826
874static int memory_open(struct inode *inode, struct file *filp) 827static int memory_open(struct inode *inode, struct file *filp)
diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 44c407986f64..e94e619fe050 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -486,7 +486,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
486 GFP_KERNEL); 486 GFP_KERNEL);
487 devfreq->last_stat_updated = jiffies; 487 devfreq->last_stat_updated = jiffies;
488 488
489 dev_set_name(&devfreq->dev, dev_name(dev)); 489 dev_set_name(&devfreq->dev, "%s", dev_name(dev));
490 err = device_register(&devfreq->dev); 490 err = device_register(&devfreq->dev);
491 if (err) { 491 if (err) {
492 put_device(&devfreq->dev); 492 put_device(&devfreq->dev);
diff --git a/drivers/dma/dmaengine.c b/drivers/dma/dmaengine.c
index 93f7992bee5c..9e56745f87bf 100644
--- a/drivers/dma/dmaengine.c
+++ b/drivers/dma/dmaengine.c
@@ -663,11 +663,6 @@ static bool device_has_all_tx_types(struct dma_device *device)
663 return false; 663 return false;
664 #endif 664 #endif
665 665
666 #if defined(CONFIG_ASYNC_MEMSET) || defined(CONFIG_ASYNC_MEMSET_MODULE)
667 if (!dma_has_cap(DMA_MEMSET, device->cap_mask))
668 return false;
669 #endif
670
671 #if defined(CONFIG_ASYNC_XOR) || defined(CONFIG_ASYNC_XOR_MODULE) 666 #if defined(CONFIG_ASYNC_XOR) || defined(CONFIG_ASYNC_XOR_MODULE)
672 if (!dma_has_cap(DMA_XOR, device->cap_mask)) 667 if (!dma_has_cap(DMA_XOR, device->cap_mask))
673 return false; 668 return false;
@@ -729,8 +724,6 @@ int dma_async_device_register(struct dma_device *device)
729 !device->device_prep_dma_pq); 724 !device->device_prep_dma_pq);
730 BUG_ON(dma_has_cap(DMA_PQ_VAL, device->cap_mask) && 725 BUG_ON(dma_has_cap(DMA_PQ_VAL, device->cap_mask) &&
731 !device->device_prep_dma_pq_val); 726 !device->device_prep_dma_pq_val);
732 BUG_ON(dma_has_cap(DMA_MEMSET, device->cap_mask) &&
733 !device->device_prep_dma_memset);
734 BUG_ON(dma_has_cap(DMA_INTERRUPT, device->cap_mask) && 727 BUG_ON(dma_has_cap(DMA_INTERRUPT, device->cap_mask) &&
735 !device->device_prep_dma_interrupt); 728 !device->device_prep_dma_interrupt);
736 BUG_ON(dma_has_cap(DMA_SG, device->cap_mask) && 729 BUG_ON(dma_has_cap(DMA_SG, device->cap_mask) &&
diff --git a/drivers/dma/ioat/dma.c b/drivers/dma/ioat/dma.c
index 17a2393b3e25..5ff6fc1819dc 100644
--- a/drivers/dma/ioat/dma.c
+++ b/drivers/dma/ioat/dma.c
@@ -1105,12 +1105,11 @@ static ssize_t cap_show(struct dma_chan *c, char *page)
1105{ 1105{
1106 struct dma_device *dma = c->device; 1106 struct dma_device *dma = c->device;
1107 1107
1108 return sprintf(page, "copy%s%s%s%s%s%s\n", 1108 return sprintf(page, "copy%s%s%s%s%s\n",
1109 dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "", 1109 dma_has_cap(DMA_PQ, dma->cap_mask) ? " pq" : "",
1110 dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "", 1110 dma_has_cap(DMA_PQ_VAL, dma->cap_mask) ? " pq_val" : "",
1111 dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "", 1111 dma_has_cap(DMA_XOR, dma->cap_mask) ? " xor" : "",
1112 dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "", 1112 dma_has_cap(DMA_XOR_VAL, dma->cap_mask) ? " xor_val" : "",
1113 dma_has_cap(DMA_MEMSET, dma->cap_mask) ? " fill" : "",
1114 dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : ""); 1113 dma_has_cap(DMA_INTERRUPT, dma->cap_mask) ? " intr" : "");
1115 1114
1116} 1115}
diff --git a/drivers/dma/ioat/dma_v2.h b/drivers/dma/ioat/dma_v2.h
index 29bf9448035d..212d584fe427 100644
--- a/drivers/dma/ioat/dma_v2.h
+++ b/drivers/dma/ioat/dma_v2.h
@@ -123,7 +123,6 @@ static inline u16 ioat2_xferlen_to_descs(struct ioat2_dma_chan *ioat, size_t len
123struct ioat_ring_ent { 123struct ioat_ring_ent {
124 union { 124 union {
125 struct ioat_dma_descriptor *hw; 125 struct ioat_dma_descriptor *hw;
126 struct ioat_fill_descriptor *fill;
127 struct ioat_xor_descriptor *xor; 126 struct ioat_xor_descriptor *xor;
128 struct ioat_xor_ext_descriptor *xor_ex; 127 struct ioat_xor_ext_descriptor *xor_ex;
129 struct ioat_pq_descriptor *pq; 128 struct ioat_pq_descriptor *pq;
diff --git a/drivers/dma/ioat/dma_v3.c b/drivers/dma/ioat/dma_v3.c
index ca6ea9b3551b..b642e035579b 100644
--- a/drivers/dma/ioat/dma_v3.c
+++ b/drivers/dma/ioat/dma_v3.c
@@ -311,14 +311,6 @@ static void ioat3_dma_unmap(struct ioat2_dma_chan *ioat,
311 if (!desc->hw->ctl_f.null) /* skip 'interrupt' ops */ 311 if (!desc->hw->ctl_f.null) /* skip 'interrupt' ops */
312 ioat_dma_unmap(chan, flags, len, desc->hw); 312 ioat_dma_unmap(chan, flags, len, desc->hw);
313 break; 313 break;
314 case IOAT_OP_FILL: {
315 struct ioat_fill_descriptor *hw = desc->fill;
316
317 if (!(flags & DMA_COMPL_SKIP_DEST_UNMAP))
318 ioat_unmap(pdev, hw->dst_addr - offset, len,
319 PCI_DMA_FROMDEVICE, flags, 1);
320 break;
321 }
322 case IOAT_OP_XOR_VAL: 314 case IOAT_OP_XOR_VAL:
323 case IOAT_OP_XOR: { 315 case IOAT_OP_XOR: {
324 struct ioat_xor_descriptor *xor = desc->xor; 316 struct ioat_xor_descriptor *xor = desc->xor;
@@ -824,51 +816,6 @@ ioat3_tx_status(struct dma_chan *c, dma_cookie_t cookie,
824} 816}
825 817
826static struct dma_async_tx_descriptor * 818static struct dma_async_tx_descriptor *
827ioat3_prep_memset_lock(struct dma_chan *c, dma_addr_t dest, int value,
828 size_t len, unsigned long flags)
829{
830 struct ioat2_dma_chan *ioat = to_ioat2_chan(c);
831 struct ioat_ring_ent *desc;
832 size_t total_len = len;
833 struct ioat_fill_descriptor *fill;
834 u64 src_data = (0x0101010101010101ULL) * (value & 0xff);
835 int num_descs, idx, i;
836
837 num_descs = ioat2_xferlen_to_descs(ioat, len);
838 if (likely(num_descs) && ioat2_check_space_lock(ioat, num_descs) == 0)
839 idx = ioat->head;
840 else
841 return NULL;
842 i = 0;
843 do {
844 size_t xfer_size = min_t(size_t, len, 1 << ioat->xfercap_log);
845
846 desc = ioat2_get_ring_ent(ioat, idx + i);
847 fill = desc->fill;
848
849 fill->size = xfer_size;
850 fill->src_data = src_data;
851 fill->dst_addr = dest;
852 fill->ctl = 0;
853 fill->ctl_f.op = IOAT_OP_FILL;
854
855 len -= xfer_size;
856 dest += xfer_size;
857 dump_desc_dbg(ioat, desc);
858 } while (++i < num_descs);
859
860 desc->txd.flags = flags;
861 desc->len = total_len;
862 fill->ctl_f.int_en = !!(flags & DMA_PREP_INTERRUPT);
863 fill->ctl_f.fence = !!(flags & DMA_PREP_FENCE);
864 fill->ctl_f.compl_write = 1;
865 dump_desc_dbg(ioat, desc);
866
867 /* we leave the channel locked to ensure in order submission */
868 return &desc->txd;
869}
870
871static struct dma_async_tx_descriptor *
872__ioat3_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result, 819__ioat3_prep_xor_lock(struct dma_chan *c, enum sum_check_flags *result,
873 dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt, 820 dma_addr_t dest, dma_addr_t *src, unsigned int src_cnt,
874 size_t len, unsigned long flags) 821 size_t len, unsigned long flags)
@@ -1431,7 +1378,7 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
1431 struct page *xor_srcs[IOAT_NUM_SRC_TEST]; 1378 struct page *xor_srcs[IOAT_NUM_SRC_TEST];
1432 struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1]; 1379 struct page *xor_val_srcs[IOAT_NUM_SRC_TEST + 1];
1433 dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1]; 1380 dma_addr_t dma_srcs[IOAT_NUM_SRC_TEST + 1];
1434 dma_addr_t dma_addr, dest_dma; 1381 dma_addr_t dest_dma;
1435 struct dma_async_tx_descriptor *tx; 1382 struct dma_async_tx_descriptor *tx;
1436 struct dma_chan *dma_chan; 1383 struct dma_chan *dma_chan;
1437 dma_cookie_t cookie; 1384 dma_cookie_t cookie;
@@ -1598,56 +1545,6 @@ static int ioat_xor_val_self_test(struct ioatdma_device *device)
1598 goto free_resources; 1545 goto free_resources;
1599 } 1546 }
1600 1547
1601 /* skip memset if the capability is not present */
1602 if (!dma_has_cap(DMA_MEMSET, dma_chan->device->cap_mask))
1603 goto free_resources;
1604
1605 /* test memset */
1606 op = IOAT_OP_FILL;
1607
1608 dma_addr = dma_map_page(dev, dest, 0,
1609 PAGE_SIZE, DMA_FROM_DEVICE);
1610 tx = dma->device_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE,
1611 DMA_PREP_INTERRUPT |
1612 DMA_COMPL_SKIP_SRC_UNMAP |
1613 DMA_COMPL_SKIP_DEST_UNMAP);
1614 if (!tx) {
1615 dev_err(dev, "Self-test memset prep failed\n");
1616 err = -ENODEV;
1617 goto dma_unmap;
1618 }
1619
1620 async_tx_ack(tx);
1621 init_completion(&cmp);
1622 tx->callback = ioat3_dma_test_callback;
1623 tx->callback_param = &cmp;
1624 cookie = tx->tx_submit(tx);
1625 if (cookie < 0) {
1626 dev_err(dev, "Self-test memset setup failed\n");
1627 err = -ENODEV;
1628 goto dma_unmap;
1629 }
1630 dma->device_issue_pending(dma_chan);
1631
1632 tmo = wait_for_completion_timeout(&cmp, msecs_to_jiffies(3000));
1633
1634 if (dma->device_tx_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
1635 dev_err(dev, "Self-test memset timed out\n");
1636 err = -ENODEV;
1637 goto dma_unmap;
1638 }
1639
1640 dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE);
1641
1642 for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) {
1643 u32 *ptr = page_address(dest);
1644 if (ptr[i]) {
1645 dev_err(dev, "Self-test memset failed compare\n");
1646 err = -ENODEV;
1647 goto free_resources;
1648 }
1649 }
1650
1651 /* test for non-zero parity sum */ 1548 /* test for non-zero parity sum */
1652 op = IOAT_OP_XOR_VAL; 1549 op = IOAT_OP_XOR_VAL;
1653 1550
@@ -1706,8 +1603,7 @@ dma_unmap:
1706 for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++) 1603 for (i = 0; i < IOAT_NUM_SRC_TEST + 1; i++)
1707 dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE, 1604 dma_unmap_page(dev, dma_srcs[i], PAGE_SIZE,
1708 DMA_TO_DEVICE); 1605 DMA_TO_DEVICE);
1709 } else if (op == IOAT_OP_FILL) 1606 }
1710 dma_unmap_page(dev, dma_addr, PAGE_SIZE, DMA_FROM_DEVICE);
1711free_resources: 1607free_resources:
1712 dma->device_free_chan_resources(dma_chan); 1608 dma->device_free_chan_resources(dma_chan);
1713out: 1609out:
@@ -1944,12 +1840,6 @@ int ioat3_dma_probe(struct ioatdma_device *device, int dca)
1944 } 1840 }
1945 } 1841 }
1946 1842
1947 if (is_raid_device && (device->cap & IOAT_CAP_FILL_BLOCK)) {
1948 dma_cap_set(DMA_MEMSET, dma->cap_mask);
1949 dma->device_prep_dma_memset = ioat3_prep_memset_lock;
1950 }
1951
1952
1953 dma->device_tx_status = ioat3_tx_status; 1843 dma->device_tx_status = ioat3_tx_status;
1954 device->cleanup_fn = ioat3_cleanup_event; 1844 device->cleanup_fn = ioat3_cleanup_event;
1955 device->timer_fn = ioat3_timer_event; 1845 device->timer_fn = ioat3_timer_event;
diff --git a/drivers/dma/ioat/hw.h b/drivers/dma/ioat/hw.h
index 5ee57d402a6e..62f83e983d8d 100644
--- a/drivers/dma/ioat/hw.h
+++ b/drivers/dma/ioat/hw.h
@@ -100,33 +100,6 @@ struct ioat_dma_descriptor {
100 uint64_t user2; 100 uint64_t user2;
101}; 101};
102 102
103struct ioat_fill_descriptor {
104 uint32_t size;
105 union {
106 uint32_t ctl;
107 struct {
108 unsigned int int_en:1;
109 unsigned int rsvd:1;
110 unsigned int dest_snoop_dis:1;
111 unsigned int compl_write:1;
112 unsigned int fence:1;
113 unsigned int rsvd2:2;
114 unsigned int dest_brk:1;
115 unsigned int bundle:1;
116 unsigned int rsvd4:15;
117 #define IOAT_OP_FILL 0x01
118 unsigned int op:8;
119 } ctl_f;
120 };
121 uint64_t src_data;
122 uint64_t dst_addr;
123 uint64_t next;
124 uint64_t rsv1;
125 uint64_t next_dst_addr;
126 uint64_t user1;
127 uint64_t user2;
128};
129
130struct ioat_xor_descriptor { 103struct ioat_xor_descriptor {
131 uint32_t size; 104 uint32_t size;
132 union { 105 union {
diff --git a/drivers/dma/iop-adma.c b/drivers/dma/iop-adma.c
index 7dafb9f3785f..c9cc08c2dbba 100644
--- a/drivers/dma/iop-adma.c
+++ b/drivers/dma/iop-adma.c
@@ -633,39 +633,6 @@ iop_adma_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dma_dest,
633} 633}
634 634
635static struct dma_async_tx_descriptor * 635static struct dma_async_tx_descriptor *
636iop_adma_prep_dma_memset(struct dma_chan *chan, dma_addr_t dma_dest,
637 int value, size_t len, unsigned long flags)
638{
639 struct iop_adma_chan *iop_chan = to_iop_adma_chan(chan);
640 struct iop_adma_desc_slot *sw_desc, *grp_start;
641 int slot_cnt, slots_per_op;
642
643 if (unlikely(!len))
644 return NULL;
645 BUG_ON(len > IOP_ADMA_MAX_BYTE_COUNT);
646
647 dev_dbg(iop_chan->device->common.dev, "%s len: %u\n",
648 __func__, len);
649
650 spin_lock_bh(&iop_chan->lock);
651 slot_cnt = iop_chan_memset_slot_count(len, &slots_per_op);
652 sw_desc = iop_adma_alloc_slots(iop_chan, slot_cnt, slots_per_op);
653 if (sw_desc) {
654 grp_start = sw_desc->group_head;
655 iop_desc_init_memset(grp_start, flags);
656 iop_desc_set_byte_count(grp_start, iop_chan, len);
657 iop_desc_set_block_fill_val(grp_start, value);
658 iop_desc_set_dest_addr(grp_start, iop_chan, dma_dest);
659 sw_desc->unmap_src_cnt = 1;
660 sw_desc->unmap_len = len;
661 sw_desc->async_tx.flags = flags;
662 }
663 spin_unlock_bh(&iop_chan->lock);
664
665 return sw_desc ? &sw_desc->async_tx : NULL;
666}
667
668static struct dma_async_tx_descriptor *
669iop_adma_prep_dma_xor(struct dma_chan *chan, dma_addr_t dma_dest, 636iop_adma_prep_dma_xor(struct dma_chan *chan, dma_addr_t dma_dest,
670 dma_addr_t *dma_src, unsigned int src_cnt, size_t len, 637 dma_addr_t *dma_src, unsigned int src_cnt, size_t len,
671 unsigned long flags) 638 unsigned long flags)
@@ -1176,33 +1143,6 @@ iop_adma_xor_val_self_test(struct iop_adma_device *device)
1176 goto free_resources; 1143 goto free_resources;
1177 } 1144 }
1178 1145
1179 /* test memset */
1180 dma_addr = dma_map_page(dma_chan->device->dev, dest, 0,
1181 PAGE_SIZE, DMA_FROM_DEVICE);
1182 tx = iop_adma_prep_dma_memset(dma_chan, dma_addr, 0, PAGE_SIZE,
1183 DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
1184
1185 cookie = iop_adma_tx_submit(tx);
1186 iop_adma_issue_pending(dma_chan);
1187 msleep(8);
1188
1189 if (iop_adma_status(dma_chan, cookie, NULL) != DMA_SUCCESS) {
1190 dev_err(dma_chan->device->dev,
1191 "Self-test memset timed out, disabling\n");
1192 err = -ENODEV;
1193 goto free_resources;
1194 }
1195
1196 for (i = 0; i < PAGE_SIZE/sizeof(u32); i++) {
1197 u32 *ptr = page_address(dest);
1198 if (ptr[i]) {
1199 dev_err(dma_chan->device->dev,
1200 "Self-test memset failed compare, disabling\n");
1201 err = -ENODEV;
1202 goto free_resources;
1203 }
1204 }
1205
1206 /* test for non-zero parity sum */ 1146 /* test for non-zero parity sum */
1207 zero_sum_result = 0; 1147 zero_sum_result = 0;
1208 for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++) 1148 for (i = 0; i < IOP_ADMA_NUM_SRC_TEST + 1; i++)
@@ -1487,8 +1427,6 @@ static int iop_adma_probe(struct platform_device *pdev)
1487 /* set prep routines based on capability */ 1427 /* set prep routines based on capability */
1488 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) 1428 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
1489 dma_dev->device_prep_dma_memcpy = iop_adma_prep_dma_memcpy; 1429 dma_dev->device_prep_dma_memcpy = iop_adma_prep_dma_memcpy;
1490 if (dma_has_cap(DMA_MEMSET, dma_dev->cap_mask))
1491 dma_dev->device_prep_dma_memset = iop_adma_prep_dma_memset;
1492 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { 1430 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
1493 dma_dev->max_xor = iop_adma_get_max_xor(); 1431 dma_dev->max_xor = iop_adma_get_max_xor();
1494 dma_dev->device_prep_dma_xor = iop_adma_prep_dma_xor; 1432 dma_dev->device_prep_dma_xor = iop_adma_prep_dma_xor;
@@ -1556,8 +1494,7 @@ static int iop_adma_probe(struct platform_device *pdev)
1556 goto err_free_iop_chan; 1494 goto err_free_iop_chan;
1557 } 1495 }
1558 1496
1559 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask) || 1497 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
1560 dma_has_cap(DMA_MEMSET, dma_dev->cap_mask)) {
1561 ret = iop_adma_xor_val_self_test(adev); 1498 ret = iop_adma_xor_val_self_test(adev);
1562 dev_dbg(&pdev->dev, "xor self test returned %d\n", ret); 1499 dev_dbg(&pdev->dev, "xor self test returned %d\n", ret);
1563 if (ret) 1500 if (ret)
@@ -1584,7 +1521,6 @@ static int iop_adma_probe(struct platform_device *pdev)
1584 dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask) ? "pq_val " : "", 1521 dma_has_cap(DMA_PQ_VAL, dma_dev->cap_mask) ? "pq_val " : "",
1585 dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "", 1522 dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "",
1586 dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask) ? "xor_val " : "", 1523 dma_has_cap(DMA_XOR_VAL, dma_dev->cap_mask) ? "xor_val " : "",
1587 dma_has_cap(DMA_MEMSET, dma_dev->cap_mask) ? "fill " : "",
1588 dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "", 1524 dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "",
1589 dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : ""); 1525 dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
1590 1526
diff --git a/drivers/dma/mv_xor.c b/drivers/dma/mv_xor.c
index d64ae14f2706..200f1a3c9a44 100644
--- a/drivers/dma/mv_xor.c
+++ b/drivers/dma/mv_xor.c
@@ -89,11 +89,6 @@ static void mv_desc_clear_next_desc(struct mv_xor_desc_slot *desc)
89 hw_desc->phy_next_desc = 0; 89 hw_desc->phy_next_desc = 0;
90} 90}
91 91
92static void mv_desc_set_block_fill_val(struct mv_xor_desc_slot *desc, u32 val)
93{
94 desc->value = val;
95}
96
97static void mv_desc_set_dest_addr(struct mv_xor_desc_slot *desc, 92static void mv_desc_set_dest_addr(struct mv_xor_desc_slot *desc,
98 dma_addr_t addr) 93 dma_addr_t addr)
99{ 94{
@@ -128,22 +123,6 @@ static void mv_chan_set_next_descriptor(struct mv_xor_chan *chan,
128 __raw_writel(next_desc_addr, XOR_NEXT_DESC(chan)); 123 __raw_writel(next_desc_addr, XOR_NEXT_DESC(chan));
129} 124}
130 125
131static void mv_chan_set_dest_pointer(struct mv_xor_chan *chan, u32 desc_addr)
132{
133 __raw_writel(desc_addr, XOR_DEST_POINTER(chan));
134}
135
136static void mv_chan_set_block_size(struct mv_xor_chan *chan, u32 block_size)
137{
138 __raw_writel(block_size, XOR_BLOCK_SIZE(chan));
139}
140
141static void mv_chan_set_value(struct mv_xor_chan *chan, u32 value)
142{
143 __raw_writel(value, XOR_INIT_VALUE_LOW(chan));
144 __raw_writel(value, XOR_INIT_VALUE_HIGH(chan));
145}
146
147static void mv_chan_unmask_interrupts(struct mv_xor_chan *chan) 126static void mv_chan_unmask_interrupts(struct mv_xor_chan *chan)
148{ 127{
149 u32 val = __raw_readl(XOR_INTR_MASK(chan)); 128 u32 val = __raw_readl(XOR_INTR_MASK(chan));
@@ -186,8 +165,6 @@ static int mv_can_chain(struct mv_xor_desc_slot *desc)
186 165
187 if (chain_old_tail->type != desc->type) 166 if (chain_old_tail->type != desc->type)
188 return 0; 167 return 0;
189 if (desc->type == DMA_MEMSET)
190 return 0;
191 168
192 return 1; 169 return 1;
193} 170}
@@ -205,9 +182,6 @@ static void mv_set_mode(struct mv_xor_chan *chan,
205 case DMA_MEMCPY: 182 case DMA_MEMCPY:
206 op_mode = XOR_OPERATION_MODE_MEMCPY; 183 op_mode = XOR_OPERATION_MODE_MEMCPY;
207 break; 184 break;
208 case DMA_MEMSET:
209 op_mode = XOR_OPERATION_MODE_MEMSET;
210 break;
211 default: 185 default:
212 dev_err(mv_chan_to_devp(chan), 186 dev_err(mv_chan_to_devp(chan),
213 "error: unsupported operation %d\n", 187 "error: unsupported operation %d\n",
@@ -274,18 +248,9 @@ static void mv_xor_start_new_chain(struct mv_xor_chan *mv_chan,
274 if (sw_desc->type != mv_chan->current_type) 248 if (sw_desc->type != mv_chan->current_type)
275 mv_set_mode(mv_chan, sw_desc->type); 249 mv_set_mode(mv_chan, sw_desc->type);
276 250
277 if (sw_desc->type == DMA_MEMSET) { 251 /* set the hardware chain */
278 /* for memset requests we need to program the engine, no 252 mv_chan_set_next_descriptor(mv_chan, sw_desc->async_tx.phys);
279 * descriptors used. 253
280 */
281 struct mv_xor_desc *hw_desc = sw_desc->hw_desc;
282 mv_chan_set_dest_pointer(mv_chan, hw_desc->phy_dest_addr);
283 mv_chan_set_block_size(mv_chan, sw_desc->unmap_len);
284 mv_chan_set_value(mv_chan, sw_desc->value);
285 } else {
286 /* set the hardware chain */
287 mv_chan_set_next_descriptor(mv_chan, sw_desc->async_tx.phys);
288 }
289 mv_chan->pending += sw_desc->slot_cnt; 254 mv_chan->pending += sw_desc->slot_cnt;
290 mv_xor_issue_pending(&mv_chan->dmachan); 255 mv_xor_issue_pending(&mv_chan->dmachan);
291} 256}
@@ -688,43 +653,6 @@ mv_xor_prep_dma_memcpy(struct dma_chan *chan, dma_addr_t dest, dma_addr_t src,
688} 653}
689 654
690static struct dma_async_tx_descriptor * 655static struct dma_async_tx_descriptor *
691mv_xor_prep_dma_memset(struct dma_chan *chan, dma_addr_t dest, int value,
692 size_t len, unsigned long flags)
693{
694 struct mv_xor_chan *mv_chan = to_mv_xor_chan(chan);
695 struct mv_xor_desc_slot *sw_desc, *grp_start;
696 int slot_cnt;
697
698 dev_dbg(mv_chan_to_devp(mv_chan),
699 "%s dest: %x len: %u flags: %ld\n",
700 __func__, dest, len, flags);
701 if (unlikely(len < MV_XOR_MIN_BYTE_COUNT))
702 return NULL;
703
704 BUG_ON(len > MV_XOR_MAX_BYTE_COUNT);
705
706 spin_lock_bh(&mv_chan->lock);
707 slot_cnt = mv_chan_memset_slot_count(len);
708 sw_desc = mv_xor_alloc_slots(mv_chan, slot_cnt, 1);
709 if (sw_desc) {
710 sw_desc->type = DMA_MEMSET;
711 sw_desc->async_tx.flags = flags;
712 grp_start = sw_desc->group_head;
713 mv_desc_init(grp_start, flags);
714 mv_desc_set_byte_count(grp_start, len);
715 mv_desc_set_dest_addr(sw_desc->group_head, dest);
716 mv_desc_set_block_fill_val(grp_start, value);
717 sw_desc->unmap_src_cnt = 1;
718 sw_desc->unmap_len = len;
719 }
720 spin_unlock_bh(&mv_chan->lock);
721 dev_dbg(mv_chan_to_devp(mv_chan),
722 "%s sw_desc %p async_tx %p \n",
723 __func__, sw_desc, &sw_desc->async_tx);
724 return sw_desc ? &sw_desc->async_tx : NULL;
725}
726
727static struct dma_async_tx_descriptor *
728mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src, 656mv_xor_prep_dma_xor(struct dma_chan *chan, dma_addr_t dest, dma_addr_t *src,
729 unsigned int src_cnt, size_t len, unsigned long flags) 657 unsigned int src_cnt, size_t len, unsigned long flags)
730{ 658{
@@ -1137,8 +1065,6 @@ mv_xor_channel_add(struct mv_xor_device *xordev,
1137 /* set prep routines based on capability */ 1065 /* set prep routines based on capability */
1138 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask)) 1066 if (dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask))
1139 dma_dev->device_prep_dma_memcpy = mv_xor_prep_dma_memcpy; 1067 dma_dev->device_prep_dma_memcpy = mv_xor_prep_dma_memcpy;
1140 if (dma_has_cap(DMA_MEMSET, dma_dev->cap_mask))
1141 dma_dev->device_prep_dma_memset = mv_xor_prep_dma_memset;
1142 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) { 1068 if (dma_has_cap(DMA_XOR, dma_dev->cap_mask)) {
1143 dma_dev->max_xor = 8; 1069 dma_dev->max_xor = 8;
1144 dma_dev->device_prep_dma_xor = mv_xor_prep_dma_xor; 1070 dma_dev->device_prep_dma_xor = mv_xor_prep_dma_xor;
@@ -1187,9 +1113,8 @@ mv_xor_channel_add(struct mv_xor_device *xordev,
1187 goto err_free_irq; 1113 goto err_free_irq;
1188 } 1114 }
1189 1115
1190 dev_info(&pdev->dev, "Marvell XOR: ( %s%s%s%s)\n", 1116 dev_info(&pdev->dev, "Marvell XOR: ( %s%s%s)\n",
1191 dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "", 1117 dma_has_cap(DMA_XOR, dma_dev->cap_mask) ? "xor " : "",
1192 dma_has_cap(DMA_MEMSET, dma_dev->cap_mask) ? "fill " : "",
1193 dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "", 1118 dma_has_cap(DMA_MEMCPY, dma_dev->cap_mask) ? "cpy " : "",
1194 dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : ""); 1119 dma_has_cap(DMA_INTERRUPT, dma_dev->cap_mask) ? "intr " : "");
1195 1120
@@ -1298,8 +1223,6 @@ static int mv_xor_probe(struct platform_device *pdev)
1298 dma_cap_set(DMA_MEMCPY, cap_mask); 1223 dma_cap_set(DMA_MEMCPY, cap_mask);
1299 if (of_property_read_bool(np, "dmacap,xor")) 1224 if (of_property_read_bool(np, "dmacap,xor"))
1300 dma_cap_set(DMA_XOR, cap_mask); 1225 dma_cap_set(DMA_XOR, cap_mask);
1301 if (of_property_read_bool(np, "dmacap,memset"))
1302 dma_cap_set(DMA_MEMSET, cap_mask);
1303 if (of_property_read_bool(np, "dmacap,interrupt")) 1226 if (of_property_read_bool(np, "dmacap,interrupt"))
1304 dma_cap_set(DMA_INTERRUPT, cap_mask); 1227 dma_cap_set(DMA_INTERRUPT, cap_mask);
1305 1228
diff --git a/drivers/dma/mv_xor.h b/drivers/dma/mv_xor.h
index c632a4761fcf..c619359cb7fe 100644
--- a/drivers/dma/mv_xor.h
+++ b/drivers/dma/mv_xor.h
@@ -31,7 +31,6 @@
31 31
32#define XOR_OPERATION_MODE_XOR 0 32#define XOR_OPERATION_MODE_XOR 0
33#define XOR_OPERATION_MODE_MEMCPY 2 33#define XOR_OPERATION_MODE_MEMCPY 2
34#define XOR_OPERATION_MODE_MEMSET 4
35 34
36#define XOR_CURR_DESC(chan) (chan->mmr_base + 0x210 + (chan->idx * 4)) 35#define XOR_CURR_DESC(chan) (chan->mmr_base + 0x210 + (chan->idx * 4))
37#define XOR_NEXT_DESC(chan) (chan->mmr_base + 0x200 + (chan->idx * 4)) 36#define XOR_NEXT_DESC(chan) (chan->mmr_base + 0x200 + (chan->idx * 4))
diff --git a/drivers/dma/pl330.c b/drivers/dma/pl330.c
index a17553f7c028..7ec82f0667eb 100644
--- a/drivers/dma/pl330.c
+++ b/drivers/dma/pl330.c
@@ -2485,10 +2485,10 @@ static void pl330_free_chan_resources(struct dma_chan *chan)
2485 struct dma_pl330_chan *pch = to_pchan(chan); 2485 struct dma_pl330_chan *pch = to_pchan(chan);
2486 unsigned long flags; 2486 unsigned long flags;
2487 2487
2488 spin_lock_irqsave(&pch->lock, flags);
2489
2490 tasklet_kill(&pch->task); 2488 tasklet_kill(&pch->task);
2491 2489
2490 spin_lock_irqsave(&pch->lock, flags);
2491
2492 pl330_release_channel(pch->pl330_chid); 2492 pl330_release_channel(pch->pl330_chid);
2493 pch->pl330_chid = NULL; 2493 pch->pl330_chid = NULL;
2494 2494
diff --git a/drivers/dma/ppc4xx/adma.c b/drivers/dma/ppc4xx/adma.c
index 5d3d95569a1e..1e220f8dfd8c 100644
--- a/drivers/dma/ppc4xx/adma.c
+++ b/drivers/dma/ppc4xx/adma.c
@@ -2323,47 +2323,6 @@ static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_memcpy(
2323} 2323}
2324 2324
2325/** 2325/**
2326 * ppc440spe_adma_prep_dma_memset - prepare CDB for a MEMSET operation
2327 */
2328static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_memset(
2329 struct dma_chan *chan, dma_addr_t dma_dest, int value,
2330 size_t len, unsigned long flags)
2331{
2332 struct ppc440spe_adma_chan *ppc440spe_chan;
2333 struct ppc440spe_adma_desc_slot *sw_desc, *group_start;
2334 int slot_cnt, slots_per_op;
2335
2336 ppc440spe_chan = to_ppc440spe_adma_chan(chan);
2337
2338 if (unlikely(!len))
2339 return NULL;
2340
2341 BUG_ON(len > PPC440SPE_ADMA_DMA_MAX_BYTE_COUNT);
2342
2343 spin_lock_bh(&ppc440spe_chan->lock);
2344
2345 dev_dbg(ppc440spe_chan->device->common.dev,
2346 "ppc440spe adma%d: %s cal: %u len: %u int_en %d\n",
2347 ppc440spe_chan->device->id, __func__, value, len,
2348 flags & DMA_PREP_INTERRUPT ? 1 : 0);
2349
2350 slot_cnt = slots_per_op = 1;
2351 sw_desc = ppc440spe_adma_alloc_slots(ppc440spe_chan, slot_cnt,
2352 slots_per_op);
2353 if (sw_desc) {
2354 group_start = sw_desc->group_head;
2355 ppc440spe_desc_init_memset(group_start, value, flags);
2356 ppc440spe_adma_set_dest(group_start, dma_dest, 0);
2357 ppc440spe_desc_set_byte_count(group_start, ppc440spe_chan, len);
2358 sw_desc->unmap_len = len;
2359 sw_desc->async_tx.flags = flags;
2360 }
2361 spin_unlock_bh(&ppc440spe_chan->lock);
2362
2363 return sw_desc ? &sw_desc->async_tx : NULL;
2364}
2365
2366/**
2367 * ppc440spe_adma_prep_dma_xor - prepare CDB for a XOR operation 2326 * ppc440spe_adma_prep_dma_xor - prepare CDB for a XOR operation
2368 */ 2327 */
2369static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_xor( 2328static struct dma_async_tx_descriptor *ppc440spe_adma_prep_dma_xor(
@@ -4125,7 +4084,6 @@ static void ppc440spe_adma_init_capabilities(struct ppc440spe_adma_device *adev)
4125 case PPC440SPE_DMA1_ID: 4084 case PPC440SPE_DMA1_ID:
4126 dma_cap_set(DMA_MEMCPY, adev->common.cap_mask); 4085 dma_cap_set(DMA_MEMCPY, adev->common.cap_mask);
4127 dma_cap_set(DMA_INTERRUPT, adev->common.cap_mask); 4086 dma_cap_set(DMA_INTERRUPT, adev->common.cap_mask);
4128 dma_cap_set(DMA_MEMSET, adev->common.cap_mask);
4129 dma_cap_set(DMA_PQ, adev->common.cap_mask); 4087 dma_cap_set(DMA_PQ, adev->common.cap_mask);
4130 dma_cap_set(DMA_PQ_VAL, adev->common.cap_mask); 4088 dma_cap_set(DMA_PQ_VAL, adev->common.cap_mask);
4131 dma_cap_set(DMA_XOR_VAL, adev->common.cap_mask); 4089 dma_cap_set(DMA_XOR_VAL, adev->common.cap_mask);
@@ -4151,10 +4109,6 @@ static void ppc440spe_adma_init_capabilities(struct ppc440spe_adma_device *adev)
4151 adev->common.device_prep_dma_memcpy = 4109 adev->common.device_prep_dma_memcpy =
4152 ppc440spe_adma_prep_dma_memcpy; 4110 ppc440spe_adma_prep_dma_memcpy;
4153 } 4111 }
4154 if (dma_has_cap(DMA_MEMSET, adev->common.cap_mask)) {
4155 adev->common.device_prep_dma_memset =
4156 ppc440spe_adma_prep_dma_memset;
4157 }
4158 if (dma_has_cap(DMA_XOR, adev->common.cap_mask)) { 4112 if (dma_has_cap(DMA_XOR, adev->common.cap_mask)) {
4159 adev->common.max_xor = XOR_MAX_OPS; 4113 adev->common.max_xor = XOR_MAX_OPS;
4160 adev->common.device_prep_dma_xor = 4114 adev->common.device_prep_dma_xor =
@@ -4217,7 +4171,6 @@ static void ppc440spe_adma_init_capabilities(struct ppc440spe_adma_device *adev)
4217 dma_has_cap(DMA_XOR, adev->common.cap_mask) ? "xor " : "", 4171 dma_has_cap(DMA_XOR, adev->common.cap_mask) ? "xor " : "",
4218 dma_has_cap(DMA_XOR_VAL, adev->common.cap_mask) ? "xor_val " : "", 4172 dma_has_cap(DMA_XOR_VAL, adev->common.cap_mask) ? "xor_val " : "",
4219 dma_has_cap(DMA_MEMCPY, adev->common.cap_mask) ? "memcpy " : "", 4173 dma_has_cap(DMA_MEMCPY, adev->common.cap_mask) ? "memcpy " : "",
4220 dma_has_cap(DMA_MEMSET, adev->common.cap_mask) ? "memset " : "",
4221 dma_has_cap(DMA_INTERRUPT, adev->common.cap_mask) ? "intr " : ""); 4174 dma_has_cap(DMA_INTERRUPT, adev->common.cap_mask) ? "intr " : "");
4222} 4175}
4223 4176
diff --git a/drivers/extcon/extcon-class.c b/drivers/extcon/extcon-class.c
index 8c69803558fe..18ccadef43fd 100644
--- a/drivers/extcon/extcon-class.c
+++ b/drivers/extcon/extcon-class.c
@@ -602,7 +602,7 @@ int extcon_dev_register(struct extcon_dev *edev, struct device *dev)
602 edev->dev->class = extcon_class; 602 edev->dev->class = extcon_class;
603 edev->dev->release = extcon_dev_release; 603 edev->dev->release = extcon_dev_release;
604 604
605 dev_set_name(edev->dev, edev->name ? edev->name : dev_name(dev)); 605 dev_set_name(edev->dev, "%s", edev->name ? edev->name : dev_name(dev));
606 606
607 if (edev->max_supported) { 607 if (edev->max_supported) {
608 char buf[10]; 608 char buf[10];
diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
index b95159b33c39..eb760a218da4 100644
--- a/drivers/firmware/dmi_scan.c
+++ b/drivers/firmware/dmi_scan.c
@@ -551,9 +551,15 @@ static bool dmi_matches(const struct dmi_system_id *dmi)
551 int s = dmi->matches[i].slot; 551 int s = dmi->matches[i].slot;
552 if (s == DMI_NONE) 552 if (s == DMI_NONE)
553 break; 553 break;
554 if (dmi_ident[s] 554 if (dmi_ident[s]) {
555 && strstr(dmi_ident[s], dmi->matches[i].substr)) 555 if (!dmi->matches[i].exact_match &&
556 continue; 556 strstr(dmi_ident[s], dmi->matches[i].substr))
557 continue;
558 else if (dmi->matches[i].exact_match &&
559 !strcmp(dmi_ident[s], dmi->matches[i].substr))
560 continue;
561 }
562
557 /* No match */ 563 /* No match */
558 return false; 564 return false;
559 } 565 }
diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c
index 29412cc89c7a..817f936e2666 100644
--- a/drivers/gpu/drm/i915/intel_lvds.c
+++ b/drivers/gpu/drm/i915/intel_lvds.c
@@ -869,6 +869,22 @@ static const struct dmi_system_id intel_no_lvds[] = {
869 DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"), 869 DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
870 }, 870 },
871 }, 871 },
872 {
873 .callback = intel_no_lvds_dmi_callback,
874 .ident = "Intel D510MO",
875 .matches = {
876 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
877 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
878 },
879 },
880 {
881 .callback = intel_no_lvds_dmi_callback,
882 .ident = "Intel D525MW",
883 .matches = {
884 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
885 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
886 },
887 },
872 888
873 { } /* terminating entry */ 889 { } /* terminating entry */
874}; 890};
diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
index 5a82b6b75849..af85299f2126 100644
--- a/drivers/gpu/drm/radeon/mkregtable.c
+++ b/drivers/gpu/drm/radeon/mkregtable.c
@@ -373,19 +373,6 @@ static inline void list_splice_tail_init(struct list_head *list,
373 pos = pos->next) 373 pos = pos->next)
374 374
375/** 375/**
376 * __list_for_each - iterate over a list
377 * @pos: the &struct list_head to use as a loop cursor.
378 * @head: the head for your list.
379 *
380 * This variant differs from list_for_each() in that it's the
381 * simplest possible list iteration code, no prefetching is done.
382 * Use this for code that knows the list to be very short (empty
383 * or 1 entry) most of the time.
384 */
385#define __list_for_each(pos, head) \
386 for (pos = (head)->next; pos != (head); pos = pos->next)
387
388/**
389 * list_for_each_prev - iterate over a list backwards 376 * list_for_each_prev - iterate over a list backwards
390 * @pos: the &struct list_head to use as a loop cursor. 377 * @pos: the &struct list_head to use as a loop cursor.
391 * @head: the head for your list. 378 * @head: the head for your list.
diff --git a/drivers/hsi/hsi.c b/drivers/hsi/hsi.c
index 833dd1afbf46..66d44581e1b1 100644
--- a/drivers/hsi/hsi.c
+++ b/drivers/hsi/hsi.c
@@ -75,7 +75,7 @@ static void hsi_new_client(struct hsi_port *port, struct hsi_board_info *info)
75 cl->device.bus = &hsi_bus_type; 75 cl->device.bus = &hsi_bus_type;
76 cl->device.parent = &port->device; 76 cl->device.parent = &port->device;
77 cl->device.release = hsi_client_release; 77 cl->device.release = hsi_client_release;
78 dev_set_name(&cl->device, info->name); 78 dev_set_name(&cl->device, "%s", info->name);
79 cl->device.platform_data = info->platform_data; 79 cl->device.platform_data = info->platform_data;
80 if (info->archdata) 80 if (info->archdata)
81 cl->device.archdata = *info->archdata; 81 cl->device.archdata = *info->archdata;
diff --git a/drivers/hwmon/adt7470.c b/drivers/hwmon/adt7470.c
index b83bf4bb95eb..0f34bca9f5e5 100644
--- a/drivers/hwmon/adt7470.c
+++ b/drivers/hwmon/adt7470.c
@@ -1285,7 +1285,7 @@ static int adt7470_probe(struct i2c_client *client,
1285 } 1285 }
1286 1286
1287 init_completion(&data->auto_update_stop); 1287 init_completion(&data->auto_update_stop);
1288 data->auto_update = kthread_run(adt7470_update_thread, client, 1288 data->auto_update = kthread_run(adt7470_update_thread, client, "%s",
1289 dev_name(data->hwmon_dev)); 1289 dev_name(data->hwmon_dev));
1290 if (IS_ERR(data->auto_update)) { 1290 if (IS_ERR(data->auto_update)) {
1291 err = PTR_ERR(data->auto_update); 1291 err = PTR_ERR(data->auto_update);
diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
index 2ff620444930..0b510bafd90e 100644
--- a/drivers/ide/ide-cd.c
+++ b/drivers/ide/ide-cd.c
@@ -1756,7 +1756,7 @@ static int ide_cd_probe(ide_drive_t *drive)
1756 1756
1757 info->dev.parent = &drive->gendev; 1757 info->dev.parent = &drive->gendev;
1758 info->dev.release = ide_cd_release; 1758 info->dev.release = ide_cd_release;
1759 dev_set_name(&info->dev, dev_name(&drive->gendev)); 1759 dev_set_name(&info->dev, "%s", dev_name(&drive->gendev));
1760 1760
1761 if (device_register(&info->dev)) 1761 if (device_register(&info->dev))
1762 goto out_free_disk; 1762 goto out_free_disk;
diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c
index de86631e767d..838996a0039e 100644
--- a/drivers/ide/ide-gd.c
+++ b/drivers/ide/ide-gd.c
@@ -392,7 +392,7 @@ static int ide_gd_probe(ide_drive_t *drive)
392 392
393 idkp->dev.parent = &drive->gendev; 393 idkp->dev.parent = &drive->gendev;
394 idkp->dev.release = ide_disk_release; 394 idkp->dev.release = ide_disk_release;
395 dev_set_name(&idkp->dev, dev_name(&drive->gendev)); 395 dev_set_name(&idkp->dev, "%s", dev_name(&drive->gendev));
396 396
397 if (device_register(&idkp->dev)) 397 if (device_register(&idkp->dev))
398 goto out_free_disk; 398 goto out_free_disk;
diff --git a/drivers/ide/ide-probe.c b/drivers/ide/ide-probe.c
index 068cef0a987a..2a744a91370e 100644
--- a/drivers/ide/ide-probe.c
+++ b/drivers/ide/ide-probe.c
@@ -545,7 +545,7 @@ static int ide_register_port(ide_hwif_t *hwif)
545 int ret; 545 int ret;
546 546
547 /* register with global device tree */ 547 /* register with global device tree */
548 dev_set_name(&hwif->gendev, hwif->name); 548 dev_set_name(&hwif->gendev, "%s", hwif->name);
549 dev_set_drvdata(&hwif->gendev, hwif); 549 dev_set_drvdata(&hwif->gendev, hwif);
550 if (hwif->gendev.parent == NULL) 550 if (hwif->gendev.parent == NULL)
551 hwif->gendev.parent = hwif->dev; 551 hwif->gendev.parent = hwif->dev;
@@ -559,7 +559,7 @@ static int ide_register_port(ide_hwif_t *hwif)
559 } 559 }
560 560
561 hwif->portdev = device_create(ide_port_class, &hwif->gendev, 561 hwif->portdev = device_create(ide_port_class, &hwif->gendev,
562 MKDEV(0, 0), hwif, hwif->name); 562 MKDEV(0, 0), hwif, "%s", hwif->name);
563 if (IS_ERR(hwif->portdev)) { 563 if (IS_ERR(hwif->portdev)) {
564 ret = PTR_ERR(hwif->portdev); 564 ret = PTR_ERR(hwif->portdev);
565 device_unregister(&hwif->gendev); 565 device_unregister(&hwif->gendev);
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index c6c574bd5f59..1793aea4a7d2 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -1985,7 +1985,7 @@ static int ide_tape_probe(ide_drive_t *drive)
1985 1985
1986 tape->dev.parent = &drive->gendev; 1986 tape->dev.parent = &drive->gendev;
1987 tape->dev.release = ide_tape_release; 1987 tape->dev.release = ide_tape_release;
1988 dev_set_name(&tape->dev, dev_name(&drive->gendev)); 1988 dev_set_name(&tape->dev, "%s", dev_name(&drive->gendev));
1989 1989
1990 if (device_register(&tape->dev)) 1990 if (device_register(&tape->dev))
1991 goto out_free_disk; 1991 goto out_free_disk;
diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c
index 246fdc151652..99904f7d59e3 100644
--- a/drivers/infiniband/core/sysfs.c
+++ b/drivers/infiniband/core/sysfs.c
@@ -813,7 +813,7 @@ int ib_device_register_sysfs(struct ib_device *device,
813 813
814 class_dev->class = &ib_class; 814 class_dev->class = &ib_class;
815 class_dev->parent = device->dma_device; 815 class_dev->parent = device->dma_device;
816 dev_set_name(class_dev, device->name); 816 dev_set_name(class_dev, "%s", device->name);
817 dev_set_drvdata(class_dev, device); 817 dev_set_drvdata(class_dev, device);
818 818
819 INIT_LIST_HEAD(&device->port_list); 819 INIT_LIST_HEAD(&device->port_list);
diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c
index b56c9428f3c5..9dd0bc89c3aa 100644
--- a/drivers/infiniband/hw/qib/qib_file_ops.c
+++ b/drivers/infiniband/hw/qib/qib_file_ops.c
@@ -2208,7 +2208,7 @@ int qib_cdev_init(int minor, const char *name,
2208 goto err_cdev; 2208 goto err_cdev;
2209 } 2209 }
2210 2210
2211 device = device_create(qib_class, NULL, dev, NULL, name); 2211 device = device_create(qib_class, NULL, dev, NULL, "%s", name);
2212 if (!IS_ERR(device)) 2212 if (!IS_ERR(device))
2213 goto done; 2213 goto done;
2214 ret = PTR_ERR(device); 2214 ret = PTR_ERR(device);
diff --git a/drivers/isdn/mISDN/dsp_pipeline.c b/drivers/isdn/mISDN/dsp_pipeline.c
index 88305c9cbff5..8b1a66c6ca8a 100644
--- a/drivers/isdn/mISDN/dsp_pipeline.c
+++ b/drivers/isdn/mISDN/dsp_pipeline.c
@@ -102,7 +102,7 @@ int mISDN_dsp_element_register(struct mISDN_dsp_element *elem)
102 entry->dev.class = elements_class; 102 entry->dev.class = elements_class;
103 entry->dev.release = mISDN_dsp_dev_release; 103 entry->dev.release = mISDN_dsp_dev_release;
104 dev_set_drvdata(&entry->dev, elem); 104 dev_set_drvdata(&entry->dev, elem);
105 dev_set_name(&entry->dev, elem->name); 105 dev_set_name(&entry->dev, "%s", elem->name);
106 ret = device_register(&entry->dev); 106 ret = device_register(&entry->dev);
107 if (ret) { 107 if (ret) {
108 printk(KERN_ERR "%s: failed to register %s\n", 108 printk(KERN_ERR "%s: failed to register %s\n",
diff --git a/drivers/media/i2c/tvaudio.c b/drivers/media/i2c/tvaudio.c
index b72a59d3216a..e0634c8b7e0b 100644
--- a/drivers/media/i2c/tvaudio.c
+++ b/drivers/media/i2c/tvaudio.c
@@ -2020,7 +2020,8 @@ static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *
2020 /* start async thread */ 2020 /* start async thread */
2021 chip->wt.function = chip_thread_wake; 2021 chip->wt.function = chip_thread_wake;
2022 chip->wt.data = (unsigned long)chip; 2022 chip->wt.data = (unsigned long)chip;
2023 chip->thread = kthread_run(chip_thread, chip, client->name); 2023 chip->thread = kthread_run(chip_thread, chip, "%s",
2024 client->name);
2024 if (IS_ERR(chip->thread)) { 2025 if (IS_ERR(chip->thread)) {
2025 v4l2_warn(sd, "failed to create kthread\n"); 2026 v4l2_warn(sd, "failed to create kthread\n");
2026 chip->thread = NULL; 2027 chip->thread = NULL;
diff --git a/drivers/media/pci/cx18/cx18-driver.c b/drivers/media/pci/cx18/cx18-driver.c
index 67b61cf3e03a..004d8ace5019 100644
--- a/drivers/media/pci/cx18/cx18-driver.c
+++ b/drivers/media/pci/cx18/cx18-driver.c
@@ -695,7 +695,7 @@ static int cx18_create_in_workq(struct cx18 *cx)
695{ 695{
696 snprintf(cx->in_workq_name, sizeof(cx->in_workq_name), "%s-in", 696 snprintf(cx->in_workq_name, sizeof(cx->in_workq_name), "%s-in",
697 cx->v4l2_dev.name); 697 cx->v4l2_dev.name);
698 cx->in_work_queue = alloc_ordered_workqueue(cx->in_workq_name, 0); 698 cx->in_work_queue = alloc_ordered_workqueue("%s", 0, cx->in_workq_name);
699 if (cx->in_work_queue == NULL) { 699 if (cx->in_work_queue == NULL) {
700 CX18_ERR("Unable to create incoming mailbox handler thread\n"); 700 CX18_ERR("Unable to create incoming mailbox handler thread\n");
701 return -ENOMEM; 701 return -ENOMEM;
diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
index 07b8460953b6..b809bc868a9f 100644
--- a/drivers/media/pci/ivtv/ivtv-driver.c
+++ b/drivers/media/pci/ivtv/ivtv-driver.c
@@ -753,7 +753,7 @@ static int ivtv_init_struct1(struct ivtv *itv)
753 753
754 init_kthread_worker(&itv->irq_worker); 754 init_kthread_worker(&itv->irq_worker);
755 itv->irq_worker_task = kthread_run(kthread_worker_fn, &itv->irq_worker, 755 itv->irq_worker_task = kthread_run(kthread_worker_fn, &itv->irq_worker,
756 itv->v4l2_dev.name); 756 "%s", itv->v4l2_dev.name);
757 if (IS_ERR(itv->irq_worker_task)) { 757 if (IS_ERR(itv->irq_worker_task)) {
758 IVTV_ERR("Could not create ivtv task\n"); 758 IVTV_ERR("Could not create ivtv task\n");
759 return -1; 759 return -1;
diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
index 85bc314382d3..1d3f11965196 100644
--- a/drivers/media/platform/vivi.c
+++ b/drivers/media/platform/vivi.c
@@ -768,7 +768,8 @@ static int vivi_start_generating(struct vivi_dev *dev)
768 768
769 dma_q->frame = 0; 769 dma_q->frame = 0;
770 dma_q->ini_jiffies = jiffies; 770 dma_q->ini_jiffies = jiffies;
771 dma_q->kthread = kthread_run(vivi_thread, dev, dev->v4l2_dev.name); 771 dma_q->kthread = kthread_run(vivi_thread, dev, "%s",
772 dev->v4l2_dev.name);
772 773
773 if (IS_ERR(dma_q->kthread)) { 774 if (IS_ERR(dma_q->kthread)) {
774 v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n"); 775 v4l2_err(&dev->v4l2_dev, "kernel_thread() failed\n");
diff --git a/drivers/memstick/host/jmb38x_ms.c b/drivers/memstick/host/jmb38x_ms.c
index c37d3756d8d2..aeabaa5aedf7 100644
--- a/drivers/memstick/host/jmb38x_ms.c
+++ b/drivers/memstick/host/jmb38x_ms.c
@@ -1046,20 +1046,9 @@ static struct pci_driver jmb38x_ms_driver = {
1046 .resume = jmb38x_ms_resume 1046 .resume = jmb38x_ms_resume
1047}; 1047};
1048 1048
1049static int __init jmb38x_ms_init(void) 1049module_pci_driver(jmb38x_ms_driver);
1050{
1051 return pci_register_driver(&jmb38x_ms_driver);
1052}
1053
1054static void __exit jmb38x_ms_exit(void)
1055{
1056 pci_unregister_driver(&jmb38x_ms_driver);
1057}
1058 1050
1059MODULE_AUTHOR("Alex Dubov"); 1051MODULE_AUTHOR("Alex Dubov");
1060MODULE_DESCRIPTION("JMicron jmb38x MemoryStick driver"); 1052MODULE_DESCRIPTION("JMicron jmb38x MemoryStick driver");
1061MODULE_LICENSE("GPL"); 1053MODULE_LICENSE("GPL");
1062MODULE_DEVICE_TABLE(pci, jmb38x_ms_id_tbl); 1054MODULE_DEVICE_TABLE(pci, jmb38x_ms_id_tbl);
1063
1064module_init(jmb38x_ms_init);
1065module_exit(jmb38x_ms_exit);
diff --git a/drivers/memstick/host/r592.c b/drivers/memstick/host/r592.c
index 9718661c1fb6..1b6e91345222 100644
--- a/drivers/memstick/host/r592.c
+++ b/drivers/memstick/host/r592.c
@@ -884,18 +884,7 @@ static struct pci_driver r852_pci_driver = {
884 .driver.pm = &r592_pm_ops, 884 .driver.pm = &r592_pm_ops,
885}; 885};
886 886
887static __init int r592_module_init(void) 887module_pci_driver(r852_pci_driver);
888{
889 return pci_register_driver(&r852_pci_driver);
890}
891
892static void __exit r592_module_exit(void)
893{
894 pci_unregister_driver(&r852_pci_driver);
895}
896
897module_init(r592_module_init);
898module_exit(r592_module_exit);
899 888
900module_param_named(enable_dma, r592_enable_dma, bool, S_IRUGO); 889module_param_named(enable_dma, r592_enable_dma, bool, S_IRUGO);
901MODULE_PARM_DESC(enable_dma, "Enable usage of the DMA (default)"); 890MODULE_PARM_DESC(enable_dma, "Enable usage of the DMA (default)");
diff --git a/drivers/message/i2o/driver.c b/drivers/message/i2o/driver.c
index 8a5b2d8f4daf..813eaa33fa14 100644
--- a/drivers/message/i2o/driver.c
+++ b/drivers/message/i2o/driver.c
@@ -84,8 +84,8 @@ int i2o_driver_register(struct i2o_driver *drv)
84 osm_debug("Register driver %s\n", drv->name); 84 osm_debug("Register driver %s\n", drv->name);
85 85
86 if (drv->event) { 86 if (drv->event) {
87 drv->event_queue = alloc_workqueue(drv->name, 87 drv->event_queue = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1,
88 WQ_MEM_RECLAIM, 1); 88 drv->name);
89 if (!drv->event_queue) { 89 if (!drv->event_queue) {
90 osm_err("Could not initialize event queue for driver " 90 osm_err("Could not initialize event queue for driver "
91 "%s\n", drv->name); 91 "%s\n", drv->name);
diff --git a/drivers/misc/sgi-gru/grufault.c b/drivers/misc/sgi-gru/grufault.c
index c4acac74725c..f74fc0ca2ef9 100644
--- a/drivers/misc/sgi-gru/grufault.c
+++ b/drivers/misc/sgi-gru/grufault.c
@@ -876,8 +876,9 @@ int gru_set_context_option(unsigned long arg)
876 switch (req.op) { 876 switch (req.op) {
877 case sco_blade_chiplet: 877 case sco_blade_chiplet:
878 /* Select blade/chiplet for GRU context */ 878 /* Select blade/chiplet for GRU context */
879 if (req.val1 < -1 || req.val1 >= GRU_MAX_BLADES || !gru_base[req.val1] || 879 if (req.val0 < -1 || req.val0 >= GRU_CHIPLETS_PER_HUB ||
880 req.val0 < -1 || req.val0 >= GRU_CHIPLETS_PER_HUB) { 880 req.val1 < -1 || req.val1 >= GRU_MAX_BLADES ||
881 (req.val1 >= 0 && !gru_base[req.val1])) {
881 ret = -EINVAL; 882 ret = -EINVAL;
882 } else { 883 } else {
883 gts->ts_user_blade_id = req.val1; 884 gts->ts_user_blade_id = req.val1;
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c400c57c394a..048c823f5c51 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -1151,7 +1151,7 @@ static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name)
1151 1151
1152 ret = bdi_init(bdi); 1152 ret = bdi_init(bdi);
1153 if (!ret) 1153 if (!ret)
1154 ret = bdi_register(bdi, NULL, name); 1154 ret = bdi_register(bdi, NULL, "%s", name);
1155 1155
1156 if (ret) 1156 if (ret)
1157 bdi_destroy(bdi); 1157 bdi_destroy(bdi);
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index a56133585e92..0aaece9107c7 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -1005,7 +1005,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
1005 if (err) 1005 if (err)
1006 goto out_uif; 1006 goto out_uif;
1007 1007
1008 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); 1008 ubi->bgt_thread = kthread_create(ubi_thread, ubi, "%s", ubi->bgt_name);
1009 if (IS_ERR(ubi->bgt_thread)) { 1009 if (IS_ERR(ubi->bgt_thread)) {
1010 err = PTR_ERR(ubi->bgt_thread); 1010 err = PTR_ERR(ubi->bgt_thread);
1011 ubi_err("cannot spawn \"%s\", error %d", ubi->bgt_name, 1011 ubi_err("cannot spawn \"%s\", error %d", ubi->bgt_name,
diff --git a/drivers/net/rionet.c b/drivers/net/rionet.c
index f433b594388e..6d1f6ed3113f 100644
--- a/drivers/net/rionet.c
+++ b/drivers/net/rionet.c
@@ -208,6 +208,17 @@ static int rionet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
208 if (nets[rnet->mport->id].active[destid]) 208 if (nets[rnet->mport->id].active[destid])
209 rionet_queue_tx_msg(skb, ndev, 209 rionet_queue_tx_msg(skb, ndev,
210 nets[rnet->mport->id].active[destid]); 210 nets[rnet->mport->id].active[destid]);
211 else {
212 /*
213 * If the target device was removed from the list of
214 * active peers but we still have TX packets targeting
215 * it just report sending a packet to the target
216 * (without actual packet transfer).
217 */
218 dev_kfree_skb_any(skb);
219 ndev->stats.tx_packets++;
220 ndev->stats.tx_bytes += skb->len;
221 }
211 } 222 }
212 223
213 spin_unlock_irqrestore(&rnet->tx_lock, flags); 224 spin_unlock_irqrestore(&rnet->tx_lock, flags);
@@ -385,24 +396,28 @@ static int rionet_close(struct net_device *ndev)
385 return 0; 396 return 0;
386} 397}
387 398
388static void rionet_remove(struct rio_dev *rdev) 399static int rionet_remove_dev(struct device *dev, struct subsys_interface *sif)
389{ 400{
390 struct net_device *ndev = rio_get_drvdata(rdev); 401 struct rio_dev *rdev = to_rio_dev(dev);
391 unsigned char netid = rdev->net->hport->id; 402 unsigned char netid = rdev->net->hport->id;
392 struct rionet_peer *peer, *tmp; 403 struct rionet_peer *peer, *tmp;
393 404
394 unregister_netdev(ndev); 405 if (dev_rionet_capable(rdev)) {
395 406 list_for_each_entry_safe(peer, tmp, &nets[netid].peers, node) {
396 free_pages((unsigned long)nets[netid].active, get_order(sizeof(void *) * 407 if (peer->rdev == rdev) {
397 RIO_MAX_ROUTE_ENTRIES(rdev->net->hport->sys_size))); 408 if (nets[netid].active[rdev->destid]) {
398 nets[netid].active = NULL; 409 nets[netid].active[rdev->destid] = NULL;
410 nets[netid].nact--;
411 }
399 412
400 list_for_each_entry_safe(peer, tmp, &nets[netid].peers, node) { 413 list_del(&peer->node);
401 list_del(&peer->node); 414 kfree(peer);
402 kfree(peer); 415 break;
416 }
417 }
403 } 418 }
404 419
405 free_netdev(ndev); 420 return 0;
406} 421}
407 422
408static void rionet_get_drvinfo(struct net_device *ndev, 423static void rionet_get_drvinfo(struct net_device *ndev,
@@ -503,12 +518,13 @@ static int rionet_setup_netdev(struct rio_mport *mport, struct net_device *ndev)
503 518
504static unsigned long net_table[RIONET_MAX_NETS/sizeof(unsigned long) + 1]; 519static unsigned long net_table[RIONET_MAX_NETS/sizeof(unsigned long) + 1];
505 520
506static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id) 521static int rionet_add_dev(struct device *dev, struct subsys_interface *sif)
507{ 522{
508 int rc = -ENODEV; 523 int rc = -ENODEV;
509 u32 lsrc_ops, ldst_ops; 524 u32 lsrc_ops, ldst_ops;
510 struct rionet_peer *peer; 525 struct rionet_peer *peer;
511 struct net_device *ndev = NULL; 526 struct net_device *ndev = NULL;
527 struct rio_dev *rdev = to_rio_dev(dev);
512 unsigned char netid = rdev->net->hport->id; 528 unsigned char netid = rdev->net->hport->id;
513 int oldnet; 529 int oldnet;
514 530
@@ -518,8 +534,9 @@ static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id)
518 oldnet = test_and_set_bit(netid, net_table); 534 oldnet = test_and_set_bit(netid, net_table);
519 535
520 /* 536 /*
521 * First time through, make sure local device is rionet 537 * If first time through this net, make sure local device is rionet
522 * capable, setup netdev (will be skipped on later probes) 538 * capable and setup netdev (this step will be skipped in later probes
539 * on the same net).
523 */ 540 */
524 if (!oldnet) { 541 if (!oldnet) {
525 rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR, 542 rio_local_read_config_32(rdev->net->hport, RIO_SRC_OPS_CAR,
@@ -541,6 +558,12 @@ static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id)
541 } 558 }
542 nets[netid].ndev = ndev; 559 nets[netid].ndev = ndev;
543 rc = rionet_setup_netdev(rdev->net->hport, ndev); 560 rc = rionet_setup_netdev(rdev->net->hport, ndev);
561 if (rc) {
562 printk(KERN_ERR "%s: failed to setup netdev (rc=%d)\n",
563 DRV_NAME, rc);
564 goto out;
565 }
566
544 INIT_LIST_HEAD(&nets[netid].peers); 567 INIT_LIST_HEAD(&nets[netid].peers);
545 nets[netid].nact = 0; 568 nets[netid].nact = 0;
546 } else if (nets[netid].ndev == NULL) 569 } else if (nets[netid].ndev == NULL)
@@ -559,31 +582,61 @@ static int rionet_probe(struct rio_dev *rdev, const struct rio_device_id *id)
559 list_add_tail(&peer->node, &nets[netid].peers); 582 list_add_tail(&peer->node, &nets[netid].peers);
560 } 583 }
561 584
562 rio_set_drvdata(rdev, nets[netid].ndev); 585 return 0;
563 586out:
564 out:
565 return rc; 587 return rc;
566} 588}
567 589
590#ifdef MODULE
568static struct rio_device_id rionet_id_table[] = { 591static struct rio_device_id rionet_id_table[] = {
569 {RIO_DEVICE(RIO_ANY_ID, RIO_ANY_ID)} 592 {RIO_DEVICE(RIO_ANY_ID, RIO_ANY_ID)},
593 { 0, } /* terminate list */
570}; 594};
571 595
572static struct rio_driver rionet_driver = { 596MODULE_DEVICE_TABLE(rapidio, rionet_id_table);
573 .name = "rionet", 597#endif
574 .id_table = rionet_id_table, 598
575 .probe = rionet_probe, 599static struct subsys_interface rionet_interface = {
576 .remove = rionet_remove, 600 .name = "rionet",
601 .subsys = &rio_bus_type,
602 .add_dev = rionet_add_dev,
603 .remove_dev = rionet_remove_dev,
577}; 604};
578 605
579static int __init rionet_init(void) 606static int __init rionet_init(void)
580{ 607{
581 return rio_register_driver(&rionet_driver); 608 return subsys_interface_register(&rionet_interface);
582} 609}
583 610
584static void __exit rionet_exit(void) 611static void __exit rionet_exit(void)
585{ 612{
586 rio_unregister_driver(&rionet_driver); 613 struct rionet_private *rnet;
614 struct net_device *ndev;
615 struct rionet_peer *peer, *tmp;
616 int i;
617
618 for (i = 0; i < RIONET_MAX_NETS; i++) {
619 if (nets[i].ndev != NULL) {
620 ndev = nets[i].ndev;
621 rnet = netdev_priv(ndev);
622 unregister_netdev(ndev);
623
624 list_for_each_entry_safe(peer,
625 tmp, &nets[i].peers, node) {
626 list_del(&peer->node);
627 kfree(peer);
628 }
629
630 free_pages((unsigned long)nets[i].active,
631 get_order(sizeof(void *) *
632 RIO_MAX_ROUTE_ENTRIES(rnet->mport->sys_size)));
633 nets[i].active = NULL;
634
635 free_netdev(ndev);
636 }
637 }
638
639 subsys_interface_unregister(&rionet_interface);
587} 640}
588 641
589late_initcall(rionet_init); 642late_initcall(rionet_init);
diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
index 6125adb520a3..d0adbaf86186 100644
--- a/drivers/net/wireless/airo.c
+++ b/drivers/net/wireless/airo.c
@@ -1893,7 +1893,8 @@ static int airo_open(struct net_device *dev) {
1893 1893
1894 if (ai->wifidev != dev) { 1894 if (ai->wifidev != dev) {
1895 clear_bit(JOB_DIE, &ai->jobs); 1895 clear_bit(JOB_DIE, &ai->jobs);
1896 ai->airo_thread_task = kthread_run(airo_thread, dev, dev->name); 1896 ai->airo_thread_task = kthread_run(airo_thread, dev, "%s",
1897 dev->name);
1897 if (IS_ERR(ai->airo_thread_task)) 1898 if (IS_ERR(ai->airo_thread_task))
1898 return (int)PTR_ERR(ai->airo_thread_task); 1899 return (int)PTR_ERR(ai->airo_thread_task);
1899 1900
diff --git a/drivers/net/wireless/ipw2x00/ipw2200.c b/drivers/net/wireless/ipw2x00/ipw2200.c
index d96257b79a84..4ed5e45ca1e2 100644
--- a/drivers/net/wireless/ipw2x00/ipw2200.c
+++ b/drivers/net/wireless/ipw2x00/ipw2200.c
@@ -8256,7 +8256,7 @@ static int is_duplicate_packet(struct ipw_priv *priv,
8256 u8 *mac = header->addr2; 8256 u8 *mac = header->addr2;
8257 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE; 8257 int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
8258 8258
8259 __list_for_each(p, &priv->ibss_mac_hash[index]) { 8259 list_for_each(p, &priv->ibss_mac_hash[index]) {
8260 entry = 8260 entry =
8261 list_entry(p, struct ipw_ibss_seq, list); 8261 list_entry(p, struct ipw_ibss_seq, list);
8262 if (!memcmp(entry->mac, mac, ETH_ALEN)) 8262 if (!memcmp(entry->mac, mac, ETH_ALEN))
diff --git a/drivers/net/wireless/rt2x00/rt2x00dev.c b/drivers/net/wireless/rt2x00/rt2x00dev.c
index 90dc14336980..c8b9ef0c21f8 100644
--- a/drivers/net/wireless/rt2x00/rt2x00dev.c
+++ b/drivers/net/wireless/rt2x00/rt2x00dev.c
@@ -1321,7 +1321,7 @@ int rt2x00lib_probe_dev(struct rt2x00_dev *rt2x00dev)
1321 * Initialize work. 1321 * Initialize work.
1322 */ 1322 */
1323 rt2x00dev->workqueue = 1323 rt2x00dev->workqueue =
1324 alloc_ordered_workqueue(wiphy_name(rt2x00dev->hw->wiphy), 0); 1324 alloc_ordered_workqueue("%s", 0, wiphy_name(rt2x00dev->hw->wiphy));
1325 if (!rt2x00dev->workqueue) { 1325 if (!rt2x00dev->workqueue) {
1326 retval = -ENOMEM; 1326 retval = -ENOMEM;
1327 goto exit; 1327 goto exit;
diff --git a/drivers/net/wireless/rtlwifi/base.c b/drivers/net/wireless/rtlwifi/base.c
index af59dd5718e1..a5f223145b0f 100644
--- a/drivers/net/wireless/rtlwifi/base.c
+++ b/drivers/net/wireless/rtlwifi/base.c
@@ -380,7 +380,7 @@ static void _rtl_init_deferred_work(struct ieee80211_hw *hw)
380 380
381 /* <2> work queue */ 381 /* <2> work queue */
382 rtlpriv->works.hw = hw; 382 rtlpriv->works.hw = hw;
383 rtlpriv->works.rtl_wq = alloc_workqueue(rtlpriv->cfg->name, 0, 0); 383 rtlpriv->works.rtl_wq = alloc_workqueue("%s", 0, 0, rtlpriv->cfg->name);
384 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq, 384 INIT_DELAYED_WORK(&rtlpriv->works.watchdog_wq,
385 (void *)rtl_watchdog_wq_callback); 385 (void *)rtl_watchdog_wq_callback);
386 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq, 386 INIT_DELAYED_WORK(&rtlpriv->works.ips_nic_off_wq,
diff --git a/drivers/parport/share.c b/drivers/parport/share.c
index a848e02e6be3..6a83ee1e9178 100644
--- a/drivers/parport/share.c
+++ b/drivers/parport/share.c
@@ -282,14 +282,13 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma,
282 int device; 282 int device;
283 char *name; 283 char *name;
284 284
285 tmp = kmalloc(sizeof(struct parport), GFP_KERNEL); 285 tmp = kzalloc(sizeof(struct parport), GFP_KERNEL);
286 if (!tmp) { 286 if (!tmp) {
287 printk(KERN_WARNING "parport: memory squeeze\n"); 287 printk(KERN_WARNING "parport: memory squeeze\n");
288 return NULL; 288 return NULL;
289 } 289 }
290 290
291 /* Init our structure */ 291 /* Init our structure */
292 memset(tmp, 0, sizeof(struct parport));
293 tmp->base = base; 292 tmp->base = base;
294 tmp->irq = irq; 293 tmp->irq = irq;
295 tmp->dma = dma; 294 tmp->dma = dma;
diff --git a/drivers/pci/hotplug/pciehp_hpc.c b/drivers/pci/hotplug/pciehp_hpc.c
index 5127f3f41821..b2255736ac81 100644
--- a/drivers/pci/hotplug/pciehp_hpc.c
+++ b/drivers/pci/hotplug/pciehp_hpc.c
@@ -773,14 +773,12 @@ static void pcie_shutdown_notification(struct controller *ctrl)
773static int pcie_init_slot(struct controller *ctrl) 773static int pcie_init_slot(struct controller *ctrl)
774{ 774{
775 struct slot *slot; 775 struct slot *slot;
776 char name[32];
777 776
778 slot = kzalloc(sizeof(*slot), GFP_KERNEL); 777 slot = kzalloc(sizeof(*slot), GFP_KERNEL);
779 if (!slot) 778 if (!slot)
780 return -ENOMEM; 779 return -ENOMEM;
781 780
782 snprintf(name, sizeof(name), "pciehp-%u", PSN(ctrl)); 781 slot->wq = alloc_workqueue("pciehp-%u", 0, 0, PSN(ctrl));
783 slot->wq = alloc_workqueue(name, 0, 0);
784 if (!slot->wq) 782 if (!slot->wq)
785 goto abort; 783 goto abort;
786 784
diff --git a/drivers/pci/hotplug/shpchp_core.c b/drivers/pci/hotplug/shpchp_core.c
index 3100c52c837c..d3f757df691c 100644
--- a/drivers/pci/hotplug/shpchp_core.c
+++ b/drivers/pci/hotplug/shpchp_core.c
@@ -128,8 +128,7 @@ static int init_slots(struct controller *ctrl)
128 slot->hpc_ops = ctrl->hpc_ops; 128 slot->hpc_ops = ctrl->hpc_ops;
129 slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i); 129 slot->number = ctrl->first_slot + (ctrl->slot_num_inc * i);
130 130
131 snprintf(name, sizeof(name), "shpchp-%d", slot->number); 131 slot->wq = alloc_workqueue("shpchp-%d", 0, 0, slot->number);
132 slot->wq = alloc_workqueue(name, 0, 0);
133 if (!slot->wq) { 132 if (!slot->wq) {
134 retval = -ENOMEM; 133 retval = -ENOMEM;
135 goto error_info; 134 goto error_info;
diff --git a/drivers/platform/x86/wmi.c b/drivers/platform/x86/wmi.c
index e4ac38aca580..b13344c59808 100644
--- a/drivers/platform/x86/wmi.c
+++ b/drivers/platform/x86/wmi.c
@@ -743,7 +743,7 @@ static int wmi_create_device(const struct guid_block *gblock,
743 wblock->dev.class = &wmi_class; 743 wblock->dev.class = &wmi_class;
744 744
745 wmi_gtoa(gblock->guid, guid_string); 745 wmi_gtoa(gblock->guid, guid_string);
746 dev_set_name(&wblock->dev, guid_string); 746 dev_set_name(&wblock->dev, "%s", guid_string);
747 747
748 dev_set_drvdata(&wblock->dev, wblock); 748 dev_set_drvdata(&wblock->dev, wblock);
749 749
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index d3db26e46489..eae0eda9ff39 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -33,13 +33,17 @@
33#include <linux/pps-gpio.h> 33#include <linux/pps-gpio.h>
34#include <linux/gpio.h> 34#include <linux/gpio.h>
35#include <linux/list.h> 35#include <linux/list.h>
36#include <linux/of_device.h>
37#include <linux/of_gpio.h>
36 38
37/* Info for each registered platform device */ 39/* Info for each registered platform device */
38struct pps_gpio_device_data { 40struct pps_gpio_device_data {
39 int irq; /* IRQ used as PPS source */ 41 int irq; /* IRQ used as PPS source */
40 struct pps_device *pps; /* PPS source device */ 42 struct pps_device *pps; /* PPS source device */
41 struct pps_source_info info; /* PPS source information */ 43 struct pps_source_info info; /* PPS source information */
42 const struct pps_gpio_platform_data *pdata; 44 bool assert_falling_edge;
45 bool capture_clear;
46 unsigned int gpio_pin;
43}; 47};
44 48
45/* 49/*
@@ -57,46 +61,25 @@ static irqreturn_t pps_gpio_irq_handler(int irq, void *data)
57 61
58 info = data; 62 info = data;
59 63
60 rising_edge = gpio_get_value(info->pdata->gpio_pin); 64 rising_edge = gpio_get_value(info->gpio_pin);
61 if ((rising_edge && !info->pdata->assert_falling_edge) || 65 if ((rising_edge && !info->assert_falling_edge) ||
62 (!rising_edge && info->pdata->assert_falling_edge)) 66 (!rising_edge && info->assert_falling_edge))
63 pps_event(info->pps, &ts, PPS_CAPTUREASSERT, NULL); 67 pps_event(info->pps, &ts, PPS_CAPTUREASSERT, NULL);
64 else if (info->pdata->capture_clear && 68 else if (info->capture_clear &&
65 ((rising_edge && info->pdata->assert_falling_edge) || 69 ((rising_edge && info->assert_falling_edge) ||
66 (!rising_edge && !info->pdata->assert_falling_edge))) 70 (!rising_edge && !info->assert_falling_edge)))
67 pps_event(info->pps, &ts, PPS_CAPTURECLEAR, NULL); 71 pps_event(info->pps, &ts, PPS_CAPTURECLEAR, NULL);
68 72
69 return IRQ_HANDLED; 73 return IRQ_HANDLED;
70} 74}
71 75
72static int pps_gpio_setup(struct platform_device *pdev)
73{
74 int ret;
75 const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
76
77 ret = gpio_request(pdata->gpio_pin, pdata->gpio_label);
78 if (ret) {
79 pr_warning("failed to request GPIO %u\n", pdata->gpio_pin);
80 return -EINVAL;
81 }
82
83 ret = gpio_direction_input(pdata->gpio_pin);
84 if (ret) {
85 pr_warning("failed to set pin direction\n");
86 gpio_free(pdata->gpio_pin);
87 return -EINVAL;
88 }
89
90 return 0;
91}
92
93static unsigned long 76static unsigned long
94get_irqf_trigger_flags(const struct pps_gpio_platform_data *pdata) 77get_irqf_trigger_flags(const struct pps_gpio_device_data *data)
95{ 78{
96 unsigned long flags = pdata->assert_falling_edge ? 79 unsigned long flags = data->assert_falling_edge ?
97 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING; 80 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING;
98 81
99 if (pdata->capture_clear) { 82 if (data->capture_clear) {
100 flags |= ((flags & IRQF_TRIGGER_RISING) ? 83 flags |= ((flags & IRQF_TRIGGER_RISING) ?
101 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING); 84 IRQF_TRIGGER_FALLING : IRQF_TRIGGER_RISING);
102 } 85 }
@@ -107,38 +90,63 @@ get_irqf_trigger_flags(const struct pps_gpio_platform_data *pdata)
107static int pps_gpio_probe(struct platform_device *pdev) 90static int pps_gpio_probe(struct platform_device *pdev)
108{ 91{
109 struct pps_gpio_device_data *data; 92 struct pps_gpio_device_data *data;
110 int irq; 93 const char *gpio_label;
111 int ret; 94 int ret;
112 int err;
113 int pps_default_params; 95 int pps_default_params;
114 const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data; 96 const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
97 struct device_node *np = pdev->dev.of_node;
115 98
99 /* allocate space for device info */
100 data = devm_kzalloc(&pdev->dev, sizeof(struct pps_gpio_device_data),
101 GFP_KERNEL);
102 if (!data)
103 return -ENOMEM;
104
105 if (pdata) {
106 data->gpio_pin = pdata->gpio_pin;
107 gpio_label = pdata->gpio_label;
108
109 data->assert_falling_edge = pdata->assert_falling_edge;
110 data->capture_clear = pdata->capture_clear;
111 } else {
112 ret = of_get_gpio(np, 0);
113 if (ret < 0) {
114 dev_err(&pdev->dev, "failed to get GPIO from device tree\n");
115 return ret;
116 }
117 data->gpio_pin = ret;
118 gpio_label = PPS_GPIO_NAME;
119
120 if (of_get_property(np, "assert-falling-edge", NULL))
121 data->assert_falling_edge = true;
122 }
116 123
117 /* GPIO setup */ 124 /* GPIO setup */
118 ret = pps_gpio_setup(pdev); 125 ret = devm_gpio_request(&pdev->dev, data->gpio_pin, gpio_label);
119 if (ret) 126 if (ret) {
120 return -EINVAL; 127 dev_err(&pdev->dev, "failed to request GPIO %u\n",
128 data->gpio_pin);
129 return ret;
130 }
121 131
122 /* IRQ setup */ 132 ret = gpio_direction_input(data->gpio_pin);
123 irq = gpio_to_irq(pdata->gpio_pin); 133 if (ret) {
124 if (irq < 0) { 134 dev_err(&pdev->dev, "failed to set pin direction\n");
125 pr_err("failed to map GPIO to IRQ: %d\n", irq); 135 return -EINVAL;
126 err = -EINVAL;
127 goto return_error;
128 } 136 }
129 137
130 /* allocate space for device info */ 138 /* IRQ setup */
131 data = devm_kzalloc(&pdev->dev, sizeof(struct pps_gpio_device_data), 139 ret = gpio_to_irq(data->gpio_pin);
132 GFP_KERNEL); 140 if (ret < 0) {
133 if (data == NULL) { 141 dev_err(&pdev->dev, "failed to map GPIO to IRQ: %d\n", ret);
134 err = -ENOMEM; 142 return -EINVAL;
135 goto return_error;
136 } 143 }
144 data->irq = ret;
137 145
138 /* initialize PPS specific parts of the bookkeeping data structure. */ 146 /* initialize PPS specific parts of the bookkeeping data structure. */
139 data->info.mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT | 147 data->info.mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT |
140 PPS_ECHOASSERT | PPS_CANWAIT | PPS_TSFMT_TSPEC; 148 PPS_ECHOASSERT | PPS_CANWAIT | PPS_TSFMT_TSPEC;
141 if (pdata->capture_clear) 149 if (data->capture_clear)
142 data->info.mode |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR | 150 data->info.mode |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR |
143 PPS_ECHOCLEAR; 151 PPS_ECHOCLEAR;
144 data->info.owner = THIS_MODULE; 152 data->info.owner = THIS_MODULE;
@@ -147,77 +155,58 @@ static int pps_gpio_probe(struct platform_device *pdev)
147 155
148 /* register PPS source */ 156 /* register PPS source */
149 pps_default_params = PPS_CAPTUREASSERT | PPS_OFFSETASSERT; 157 pps_default_params = PPS_CAPTUREASSERT | PPS_OFFSETASSERT;
150 if (pdata->capture_clear) 158 if (data->capture_clear)
151 pps_default_params |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR; 159 pps_default_params |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR;
152 data->pps = pps_register_source(&data->info, pps_default_params); 160 data->pps = pps_register_source(&data->info, pps_default_params);
153 if (data->pps == NULL) { 161 if (data->pps == NULL) {
154 pr_err("failed to register IRQ %d as PPS source\n", irq); 162 dev_err(&pdev->dev, "failed to register IRQ %d as PPS source\n",
155 err = -EINVAL; 163 data->irq);
156 goto return_error; 164 return -EINVAL;
157 } 165 }
158 166
159 data->irq = irq;
160 data->pdata = pdata;
161
162 /* register IRQ interrupt handler */ 167 /* register IRQ interrupt handler */
163 ret = request_irq(irq, pps_gpio_irq_handler, 168 ret = devm_request_irq(&pdev->dev, data->irq, pps_gpio_irq_handler,
164 get_irqf_trigger_flags(pdata), data->info.name, data); 169 get_irqf_trigger_flags(data), data->info.name, data);
165 if (ret) { 170 if (ret) {
166 pps_unregister_source(data->pps); 171 pps_unregister_source(data->pps);
167 pr_err("failed to acquire IRQ %d\n", irq); 172 dev_err(&pdev->dev, "failed to acquire IRQ %d\n", data->irq);
168 err = -EINVAL; 173 return -EINVAL;
169 goto return_error;
170 } 174 }
171 175
172 platform_set_drvdata(pdev, data); 176 platform_set_drvdata(pdev, data);
173 dev_info(data->pps->dev, "Registered IRQ %d as PPS source\n", irq); 177 dev_info(data->pps->dev, "Registered IRQ %d as PPS source\n",
178 data->irq);
174 179
175 return 0; 180 return 0;
176
177return_error:
178 gpio_free(pdata->gpio_pin);
179 return err;
180} 181}
181 182
182static int pps_gpio_remove(struct platform_device *pdev) 183static int pps_gpio_remove(struct platform_device *pdev)
183{ 184{
184 struct pps_gpio_device_data *data = platform_get_drvdata(pdev); 185 struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
185 const struct pps_gpio_platform_data *pdata = data->pdata;
186 186
187 platform_set_drvdata(pdev, NULL); 187 platform_set_drvdata(pdev, NULL);
188 free_irq(data->irq, data);
189 gpio_free(pdata->gpio_pin);
190 pps_unregister_source(data->pps); 188 pps_unregister_source(data->pps);
191 pr_info("removed IRQ %d as PPS source\n", data->irq); 189 dev_info(&pdev->dev, "removed IRQ %d as PPS source\n", data->irq);
192 return 0; 190 return 0;
193} 191}
194 192
193static const struct of_device_id pps_gpio_dt_ids[] = {
194 { .compatible = "pps-gpio", },
195 { /* sentinel */ }
196};
197MODULE_DEVICE_TABLE(of, pps_gpio_dt_ids);
198
195static struct platform_driver pps_gpio_driver = { 199static struct platform_driver pps_gpio_driver = {
196 .probe = pps_gpio_probe, 200 .probe = pps_gpio_probe,
197 .remove = pps_gpio_remove, 201 .remove = pps_gpio_remove,
198 .driver = { 202 .driver = {
199 .name = PPS_GPIO_NAME, 203 .name = PPS_GPIO_NAME,
200 .owner = THIS_MODULE 204 .owner = THIS_MODULE,
205 .of_match_table = of_match_ptr(pps_gpio_dt_ids),
201 }, 206 },
202}; 207};
203 208
204static int __init pps_gpio_init(void) 209module_platform_driver(pps_gpio_driver);
205{
206 int ret = platform_driver_register(&pps_gpio_driver);
207 if (ret < 0)
208 pr_err("failed to register platform driver\n");
209 return ret;
210}
211
212static void __exit pps_gpio_exit(void)
213{
214 platform_driver_unregister(&pps_gpio_driver);
215 pr_debug("unregistered platform driver\n");
216}
217
218module_init(pps_gpio_init);
219module_exit(pps_gpio_exit);
220
221MODULE_AUTHOR("Ricardo Martins <rasm@fe.up.pt>"); 210MODULE_AUTHOR("Ricardo Martins <rasm@fe.up.pt>");
222MODULE_AUTHOR("James Nuss <jamesnuss@nanometrics.ca>"); 211MODULE_AUTHOR("James Nuss <jamesnuss@nanometrics.ca>");
223MODULE_DESCRIPTION("Use GPIO pin as PPS source"); 212MODULE_DESCRIPTION("Use GPIO pin as PPS source");
diff --git a/drivers/rapidio/Kconfig b/drivers/rapidio/Kconfig
index 5ab056494bbe..3e3be57e9a1a 100644
--- a/drivers/rapidio/Kconfig
+++ b/drivers/rapidio/Kconfig
@@ -67,4 +67,9 @@ config RAPIDIO_ENUM_BASIC
67 67
68endchoice 68endchoice
69 69
70menu "RapidIO Switch drivers"
71 depends on RAPIDIO
72
70source "drivers/rapidio/switches/Kconfig" 73source "drivers/rapidio/switches/Kconfig"
74
75endmenu
diff --git a/drivers/rapidio/Makefile b/drivers/rapidio/Makefile
index 3036702ffe8b..6271ada6993f 100644
--- a/drivers/rapidio/Makefile
+++ b/drivers/rapidio/Makefile
@@ -1,7 +1,9 @@
1# 1#
2# Makefile for RapidIO interconnect services 2# Makefile for RapidIO interconnect services
3# 3#
4obj-y += rio.o rio-access.o rio-driver.o rio-sysfs.o 4obj-$(CONFIG_RAPIDIO) += rapidio.o
5rapidio-y := rio.o rio-access.o rio-driver.o rio-sysfs.o
6
5obj-$(CONFIG_RAPIDIO_ENUM_BASIC) += rio-scan.o 7obj-$(CONFIG_RAPIDIO_ENUM_BASIC) += rio-scan.o
6 8
7obj-$(CONFIG_RAPIDIO) += switches/ 9obj-$(CONFIG_RAPIDIO) += switches/
diff --git a/drivers/rapidio/devices/Kconfig b/drivers/rapidio/devices/Kconfig
index 12a9d7f7040b..c4cb0877592b 100644
--- a/drivers/rapidio/devices/Kconfig
+++ b/drivers/rapidio/devices/Kconfig
@@ -3,7 +3,7 @@
3# 3#
4 4
5config RAPIDIO_TSI721 5config RAPIDIO_TSI721
6 bool "IDT Tsi721 PCI Express SRIO Controller support" 6 tristate "IDT Tsi721 PCI Express SRIO Controller support"
7 depends on RAPIDIO && PCIEPORTBUS 7 depends on RAPIDIO && PCIEPORTBUS
8 default "n" 8 default "n"
9 ---help--- 9 ---help---
diff --git a/drivers/rapidio/devices/Makefile b/drivers/rapidio/devices/Makefile
index 7b62860f34f8..9432c494cf57 100644
--- a/drivers/rapidio/devices/Makefile
+++ b/drivers/rapidio/devices/Makefile
@@ -2,7 +2,6 @@
2# Makefile for RapidIO devices 2# Makefile for RapidIO devices
3# 3#
4 4
5obj-$(CONFIG_RAPIDIO_TSI721) += tsi721.o 5obj-$(CONFIG_RAPIDIO_TSI721) += tsi721_mport.o
6ifeq ($(CONFIG_RAPIDIO_DMA_ENGINE),y) 6tsi721_mport-y := tsi721.o
7obj-$(CONFIG_RAPIDIO_TSI721) += tsi721_dma.o 7tsi721_mport-$(CONFIG_RAPIDIO_DMA_ENGINE) += tsi721_dma.o
8endif
diff --git a/drivers/rapidio/devices/tsi721.c b/drivers/rapidio/devices/tsi721.c
index a8b2c23a7ef4..ff7cbf2d28e3 100644
--- a/drivers/rapidio/devices/tsi721.c
+++ b/drivers/rapidio/devices/tsi721.c
@@ -2515,9 +2515,8 @@ static int __init tsi721_init(void)
2515 return pci_register_driver(&tsi721_driver); 2515 return pci_register_driver(&tsi721_driver);
2516} 2516}
2517 2517
2518static void __exit tsi721_exit(void)
2519{
2520 pci_unregister_driver(&tsi721_driver);
2521}
2522
2523device_initcall(tsi721_init); 2518device_initcall(tsi721_init);
2519
2520MODULE_DESCRIPTION("IDT Tsi721 PCIExpress-to-SRIO bridge driver");
2521MODULE_AUTHOR("Integrated Device Technology, Inc.");
2522MODULE_LICENSE("GPL");
diff --git a/drivers/rapidio/rio-driver.c b/drivers/rapidio/rio-driver.c
index a0c875563d76..3e9b6a78ad18 100644
--- a/drivers/rapidio/rio-driver.c
+++ b/drivers/rapidio/rio-driver.c
@@ -199,6 +199,23 @@ static int rio_match_bus(struct device *dev, struct device_driver *drv)
199 out:return 0; 199 out:return 0;
200} 200}
201 201
202static int rio_uevent(struct device *dev, struct kobj_uevent_env *env)
203{
204 struct rio_dev *rdev;
205
206 if (!dev)
207 return -ENODEV;
208
209 rdev = to_rio_dev(dev);
210 if (!rdev)
211 return -ENODEV;
212
213 if (add_uevent_var(env, "MODALIAS=rapidio:v%04Xd%04Xav%04Xad%04X",
214 rdev->vid, rdev->did, rdev->asm_vid, rdev->asm_did))
215 return -ENOMEM;
216 return 0;
217}
218
202struct device rio_bus = { 219struct device rio_bus = {
203 .init_name = "rapidio", 220 .init_name = "rapidio",
204}; 221};
@@ -210,6 +227,7 @@ struct bus_type rio_bus_type = {
210 .bus_attrs = rio_bus_attrs, 227 .bus_attrs = rio_bus_attrs,
211 .probe = rio_device_probe, 228 .probe = rio_device_probe,
212 .remove = rio_device_remove, 229 .remove = rio_device_remove,
230 .uevent = rio_uevent,
213}; 231};
214 232
215/** 233/**
diff --git a/drivers/rapidio/rio-scan.c b/drivers/rapidio/rio-scan.c
index 4c15dbf81087..d3a6539a77cc 100644
--- a/drivers/rapidio/rio-scan.c
+++ b/drivers/rapidio/rio-scan.c
@@ -406,6 +406,7 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
406 rio_mport_write_config_32(port, destid, hopcount, 406 rio_mport_write_config_32(port, destid, hopcount,
407 RIO_COMPONENT_TAG_CSR, next_comptag); 407 RIO_COMPONENT_TAG_CSR, next_comptag);
408 rdev->comp_tag = next_comptag++; 408 rdev->comp_tag = next_comptag++;
409 rdev->do_enum = true;
409 } else { 410 } else {
410 rio_mport_read_config_32(port, destid, hopcount, 411 rio_mport_read_config_32(port, destid, hopcount,
411 RIO_COMPONENT_TAG_CSR, 412 RIO_COMPONENT_TAG_CSR,
@@ -432,8 +433,8 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
432 /* If a PE has both switch and other functions, show it as a switch */ 433 /* If a PE has both switch and other functions, show it as a switch */
433 if (rio_is_switch(rdev)) { 434 if (rio_is_switch(rdev)) {
434 rswitch = rdev->rswitch; 435 rswitch = rdev->rswitch;
435 rswitch->switchid = rdev->comp_tag & RIO_CTAG_UDEVID;
436 rswitch->port_ok = 0; 436 rswitch->port_ok = 0;
437 spin_lock_init(&rswitch->lock);
437 rswitch->route_table = kzalloc(sizeof(u8)* 438 rswitch->route_table = kzalloc(sizeof(u8)*
438 RIO_MAX_ROUTE_ENTRIES(port->sys_size), 439 RIO_MAX_ROUTE_ENTRIES(port->sys_size),
439 GFP_KERNEL); 440 GFP_KERNEL);
@@ -444,12 +445,10 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
444 rdid++) 445 rdid++)
445 rswitch->route_table[rdid] = RIO_INVALID_ROUTE; 446 rswitch->route_table[rdid] = RIO_INVALID_ROUTE;
446 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id, 447 dev_set_name(&rdev->dev, "%02x:s:%04x", rdev->net->id,
447 rswitch->switchid); 448 rdev->comp_tag & RIO_CTAG_UDEVID);
448 rio_switch_init(rdev, do_enum);
449 449
450 if (do_enum && rswitch->clr_table) 450 if (do_enum)
451 rswitch->clr_table(port, destid, hopcount, 451 rio_route_clr_table(rdev, RIO_GLOBAL_TABLE, 0);
452 RIO_GLOBAL_TABLE);
453 452
454 list_add_tail(&rswitch->node, &net->switches); 453 list_add_tail(&rswitch->node, &net->switches);
455 454
@@ -459,7 +458,7 @@ static struct rio_dev *rio_setup_device(struct rio_net *net,
459 rio_enable_rx_tx_port(port, 0, destid, hopcount, 0); 458 rio_enable_rx_tx_port(port, 0, destid, hopcount, 0);
460 459
461 dev_set_name(&rdev->dev, "%02x:e:%04x", rdev->net->id, 460 dev_set_name(&rdev->dev, "%02x:e:%04x", rdev->net->id,
462 rdev->destid); 461 rdev->comp_tag & RIO_CTAG_UDEVID);
463 } 462 }
464 463
465 rio_attach_device(rdev); 464 rio_attach_device(rdev);
@@ -533,156 +532,6 @@ rio_sport_is_active(struct rio_mport *port, u16 destid, u8 hopcount, int sport)
533} 532}
534 533
535/** 534/**
536 * rio_lock_device - Acquires host device lock for specified device
537 * @port: Master port to send transaction
538 * @destid: Destination ID for device/switch
539 * @hopcount: Hopcount to reach switch
540 * @wait_ms: Max wait time in msec (0 = no timeout)
541 *
542 * Attepts to acquire host device lock for specified device
543 * Returns 0 if device lock acquired or EINVAL if timeout expires.
544 */
545static int
546rio_lock_device(struct rio_mport *port, u16 destid, u8 hopcount, int wait_ms)
547{
548 u32 result;
549 int tcnt = 0;
550
551 /* Attempt to acquire device lock */
552 rio_mport_write_config_32(port, destid, hopcount,
553 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
554 rio_mport_read_config_32(port, destid, hopcount,
555 RIO_HOST_DID_LOCK_CSR, &result);
556
557 while (result != port->host_deviceid) {
558 if (wait_ms != 0 && tcnt == wait_ms) {
559 pr_debug("RIO: timeout when locking device %x:%x\n",
560 destid, hopcount);
561 return -EINVAL;
562 }
563
564 /* Delay a bit */
565 mdelay(1);
566 tcnt++;
567 /* Try to acquire device lock again */
568 rio_mport_write_config_32(port, destid,
569 hopcount,
570 RIO_HOST_DID_LOCK_CSR,
571 port->host_deviceid);
572 rio_mport_read_config_32(port, destid,
573 hopcount,
574 RIO_HOST_DID_LOCK_CSR, &result);
575 }
576
577 return 0;
578}
579
580/**
581 * rio_unlock_device - Releases host device lock for specified device
582 * @port: Master port to send transaction
583 * @destid: Destination ID for device/switch
584 * @hopcount: Hopcount to reach switch
585 *
586 * Returns 0 if device lock released or EINVAL if fails.
587 */
588static int
589rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
590{
591 u32 result;
592
593 /* Release device lock */
594 rio_mport_write_config_32(port, destid,
595 hopcount,
596 RIO_HOST_DID_LOCK_CSR,
597 port->host_deviceid);
598 rio_mport_read_config_32(port, destid, hopcount,
599 RIO_HOST_DID_LOCK_CSR, &result);
600 if ((result & 0xffff) != 0xffff) {
601 pr_debug("RIO: badness when releasing device lock %x:%x\n",
602 destid, hopcount);
603 return -EINVAL;
604 }
605
606 return 0;
607}
608
609/**
610 * rio_route_add_entry- Add a route entry to a switch routing table
611 * @rdev: RIO device
612 * @table: Routing table ID
613 * @route_destid: Destination ID to be routed
614 * @route_port: Port number to be routed
615 * @lock: lock switch device flag
616 *
617 * Calls the switch specific add_entry() method to add a route entry
618 * on a switch. The route table can be specified using the @table
619 * argument if a switch has per port routing tables or the normal
620 * use is to specific all tables (or the global table) by passing
621 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
622 * on failure.
623 */
624static int
625rio_route_add_entry(struct rio_dev *rdev,
626 u16 table, u16 route_destid, u8 route_port, int lock)
627{
628 int rc;
629
630 if (lock) {
631 rc = rio_lock_device(rdev->net->hport, rdev->destid,
632 rdev->hopcount, 1000);
633 if (rc)
634 return rc;
635 }
636
637 rc = rdev->rswitch->add_entry(rdev->net->hport, rdev->destid,
638 rdev->hopcount, table,
639 route_destid, route_port);
640 if (lock)
641 rio_unlock_device(rdev->net->hport, rdev->destid,
642 rdev->hopcount);
643
644 return rc;
645}
646
647/**
648 * rio_route_get_entry- Read a route entry in a switch routing table
649 * @rdev: RIO device
650 * @table: Routing table ID
651 * @route_destid: Destination ID to be routed
652 * @route_port: Pointer to read port number into
653 * @lock: lock switch device flag
654 *
655 * Calls the switch specific get_entry() method to read a route entry
656 * in a switch. The route table can be specified using the @table
657 * argument if a switch has per port routing tables or the normal
658 * use is to specific all tables (or the global table) by passing
659 * %RIO_GLOBAL_TABLE in @table. Returns %0 on success or %-EINVAL
660 * on failure.
661 */
662static int
663rio_route_get_entry(struct rio_dev *rdev, u16 table,
664 u16 route_destid, u8 *route_port, int lock)
665{
666 int rc;
667
668 if (lock) {
669 rc = rio_lock_device(rdev->net->hport, rdev->destid,
670 rdev->hopcount, 1000);
671 if (rc)
672 return rc;
673 }
674
675 rc = rdev->rswitch->get_entry(rdev->net->hport, rdev->destid,
676 rdev->hopcount, table,
677 route_destid, route_port);
678 if (lock)
679 rio_unlock_device(rdev->net->hport, rdev->destid,
680 rdev->hopcount);
681
682 return rc;
683}
684
685/**
686 * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device 535 * rio_get_host_deviceid_lock- Reads the Host Device ID Lock CSR on a device
687 * @port: Master port to send transaction 536 * @port: Master port to send transaction
688 * @hopcount: Number of hops to the device 537 * @hopcount: Number of hops to the device
@@ -1094,12 +943,9 @@ static void rio_update_route_tables(struct rio_net *net)
1094 943
1095 sport = RIO_GET_PORT_NUM(swrdev->swpinfo); 944 sport = RIO_GET_PORT_NUM(swrdev->swpinfo);
1096 945
1097 if (rswitch->add_entry) { 946 rio_route_add_entry(swrdev, RIO_GLOBAL_TABLE,
1098 rio_route_add_entry(swrdev, 947 destid, sport, 0);
1099 RIO_GLOBAL_TABLE, destid, 948 rswitch->route_table[destid] = sport;
1100 sport, 0);
1101 rswitch->route_table[destid] = sport;
1102 }
1103 } 949 }
1104 } 950 }
1105 } 951 }
@@ -1115,8 +961,8 @@ static void rio_update_route_tables(struct rio_net *net)
1115static void rio_init_em(struct rio_dev *rdev) 961static void rio_init_em(struct rio_dev *rdev)
1116{ 962{
1117 if (rio_is_switch(rdev) && (rdev->em_efptr) && 963 if (rio_is_switch(rdev) && (rdev->em_efptr) &&
1118 (rdev->rswitch->em_init)) { 964 rdev->rswitch->ops && rdev->rswitch->ops->em_init) {
1119 rdev->rswitch->em_init(rdev); 965 rdev->rswitch->ops->em_init(rdev);
1120 } 966 }
1121} 967}
1122 968
@@ -1141,7 +987,7 @@ static void rio_pw_enable(struct rio_mport *port, int enable)
1141 * link, then start recursive peer enumeration. Returns %0 if 987 * link, then start recursive peer enumeration. Returns %0 if
1142 * enumeration succeeds or %-EBUSY if enumeration fails. 988 * enumeration succeeds or %-EBUSY if enumeration fails.
1143 */ 989 */
1144int rio_enum_mport(struct rio_mport *mport, u32 flags) 990static int rio_enum_mport(struct rio_mport *mport, u32 flags)
1145{ 991{
1146 struct rio_net *net = NULL; 992 struct rio_net *net = NULL;
1147 int rc = 0; 993 int rc = 0;
@@ -1256,7 +1102,7 @@ static void rio_build_route_tables(struct rio_net *net)
1256 * peer discovery. Returns %0 if discovery succeeds or %-EBUSY 1102 * peer discovery. Returns %0 if discovery succeeds or %-EBUSY
1257 * on failure. 1103 * on failure.
1258 */ 1104 */
1259int rio_disc_mport(struct rio_mport *mport, u32 flags) 1105static int rio_disc_mport(struct rio_mport *mport, u32 flags)
1260{ 1106{
1261 struct rio_net *net = NULL; 1107 struct rio_net *net = NULL;
1262 unsigned long to_end; 1108 unsigned long to_end;
@@ -1315,6 +1161,7 @@ bail:
1315} 1161}
1316 1162
1317static struct rio_scan rio_scan_ops = { 1163static struct rio_scan rio_scan_ops = {
1164 .owner = THIS_MODULE,
1318 .enumerate = rio_enum_mport, 1165 .enumerate = rio_enum_mport,
1319 .discover = rio_disc_mport, 1166 .discover = rio_disc_mport,
1320}; 1167};
diff --git a/drivers/rapidio/rio-sysfs.c b/drivers/rapidio/rio-sysfs.c
index 66d4acd5e18f..9331be646dc3 100644
--- a/drivers/rapidio/rio-sysfs.c
+++ b/drivers/rapidio/rio-sysfs.c
@@ -84,6 +84,15 @@ static ssize_t lnext_show(struct device *dev,
84 return str - buf; 84 return str - buf;
85} 85}
86 86
87static ssize_t modalias_show(struct device *dev,
88 struct device_attribute *attr, char *buf)
89{
90 struct rio_dev *rdev = to_rio_dev(dev);
91
92 return sprintf(buf, "rapidio:v%04Xd%04Xav%04Xad%04X\n",
93 rdev->vid, rdev->did, rdev->asm_vid, rdev->asm_did);
94}
95
87struct device_attribute rio_dev_attrs[] = { 96struct device_attribute rio_dev_attrs[] = {
88 __ATTR_RO(did), 97 __ATTR_RO(did),
89 __ATTR_RO(vid), 98 __ATTR_RO(vid),
@@ -93,6 +102,7 @@ struct device_attribute rio_dev_attrs[] = {
93 __ATTR_RO(asm_rev), 102 __ATTR_RO(asm_rev),
94 __ATTR_RO(lprev), 103 __ATTR_RO(lprev),
95 __ATTR_RO(destid), 104 __ATTR_RO(destid),
105 __ATTR_RO(modalias),
96 __ATTR_NULL, 106 __ATTR_NULL,
97}; 107};
98 108
@@ -257,8 +267,6 @@ int rio_create_sysfs_dev_files(struct rio_dev *rdev)
257 err |= device_create_file(&rdev->dev, &dev_attr_routes); 267 err |= device_create_file(&rdev->dev, &dev_attr_routes);
258 err |= device_create_file(&rdev->dev, &dev_attr_lnext); 268 err |= device_create_file(&rdev->dev, &dev_attr_lnext);
259 err |= device_create_file(&rdev->dev, &dev_attr_hopcount); 269 err |= device_create_file(&rdev->dev, &dev_attr_hopcount);
260 if (!err && rdev->rswitch->sw_sysfs)
261 err = rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_CREATE);
262 } 270 }
263 271
264 if (err) 272 if (err)
@@ -281,8 +289,6 @@ void rio_remove_sysfs_dev_files(struct rio_dev *rdev)
281 device_remove_file(&rdev->dev, &dev_attr_routes); 289 device_remove_file(&rdev->dev, &dev_attr_routes);
282 device_remove_file(&rdev->dev, &dev_attr_lnext); 290 device_remove_file(&rdev->dev, &dev_attr_lnext);
283 device_remove_file(&rdev->dev, &dev_attr_hopcount); 291 device_remove_file(&rdev->dev, &dev_attr_hopcount);
284 if (rdev->rswitch->sw_sysfs)
285 rdev->rswitch->sw_sysfs(rdev, RIO_SW_SYSFS_REMOVE);
286 } 292 }
287} 293}
288 294
@@ -290,7 +296,6 @@ static ssize_t bus_scan_store(struct bus_type *bus, const char *buf,
290 size_t count) 296 size_t count)
291{ 297{
292 long val; 298 long val;
293 struct rio_mport *port = NULL;
294 int rc; 299 int rc;
295 300
296 if (kstrtol(buf, 0, &val) < 0) 301 if (kstrtol(buf, 0, &val) < 0)
@@ -304,21 +309,7 @@ static ssize_t bus_scan_store(struct bus_type *bus, const char *buf,
304 if (val < 0 || val >= RIO_MAX_MPORTS) 309 if (val < 0 || val >= RIO_MAX_MPORTS)
305 return -EINVAL; 310 return -EINVAL;
306 311
307 port = rio_find_mport((int)val); 312 rc = rio_mport_scan((int)val);
308
309 if (!port) {
310 pr_debug("RIO: %s: mport_%d not available\n",
311 __func__, (int)val);
312 return -EINVAL;
313 }
314
315 if (!port->nscan)
316 return -EINVAL;
317
318 if (port->host_deviceid >= 0)
319 rc = port->nscan->enumerate(port, 0);
320 else
321 rc = port->nscan->discover(port, RIO_SCAN_ENUM_NO_WAIT);
322exit: 313exit:
323 if (!rc) 314 if (!rc)
324 rc = count; 315 rc = count;
diff --git a/drivers/rapidio/rio.c b/drivers/rapidio/rio.c
index cb1c08996fbb..f4f30af2df68 100644
--- a/drivers/rapidio/rio.c
+++ b/drivers/rapidio/rio.c
@@ -5,9 +5,8 @@
5 * Copyright 2005 MontaVista Software, Inc. 5 * Copyright 2005 MontaVista Software, Inc.
6 * Matt Porter <mporter@kernel.crashing.org> 6 * Matt Porter <mporter@kernel.crashing.org>
7 * 7 *
8 * Copyright 2009 Integrated Device Technology, Inc. 8 * Copyright 2009 - 2013 Integrated Device Technology, Inc.
9 * Alex Bounine <alexandre.bounine@idt.com> 9 * Alex Bounine <alexandre.bounine@idt.com>
10 * - Added Port-Write/Error Management initialization and handling
11 * 10 *
12 * This program is free software; you can redistribute it and/or modify it 11 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the 12 * under the terms of the GNU General Public License as published by the
@@ -31,10 +30,22 @@
31 30
32#include "rio.h" 31#include "rio.h"
33 32
33MODULE_DESCRIPTION("RapidIO Subsystem Core");
34MODULE_AUTHOR("Matt Porter <mporter@kernel.crashing.org>");
35MODULE_AUTHOR("Alexandre Bounine <alexandre.bounine@idt.com>");
36MODULE_LICENSE("GPL");
37
38static int hdid[RIO_MAX_MPORTS];
39static int ids_num;
40module_param_array(hdid, int, &ids_num, 0);
41MODULE_PARM_DESC(hdid,
42 "Destination ID assignment to local RapidIO controllers");
43
34static LIST_HEAD(rio_devices); 44static LIST_HEAD(rio_devices);
35static DEFINE_SPINLOCK(rio_global_list_lock); 45static DEFINE_SPINLOCK(rio_global_list_lock);
36 46
37static LIST_HEAD(rio_mports); 47static LIST_HEAD(rio_mports);
48static LIST_HEAD(rio_scans);
38static DEFINE_MUTEX(rio_mport_list_lock); 49static DEFINE_MUTEX(rio_mport_list_lock);
39static unsigned char next_portid; 50static unsigned char next_portid;
40static DEFINE_SPINLOCK(rio_mmap_lock); 51static DEFINE_SPINLOCK(rio_mmap_lock);
@@ -580,44 +591,6 @@ int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock)
580EXPORT_SYMBOL_GPL(rio_set_port_lockout); 591EXPORT_SYMBOL_GPL(rio_set_port_lockout);
581 592
582/** 593/**
583 * rio_switch_init - Sets switch operations for a particular vendor switch
584 * @rdev: RIO device
585 * @do_enum: Enumeration/Discovery mode flag
586 *
587 * Searches the RIO switch ops table for known switch types. If the vid
588 * and did match a switch table entry, then call switch initialization
589 * routine to setup switch-specific routines.
590 */
591void rio_switch_init(struct rio_dev *rdev, int do_enum)
592{
593 struct rio_switch_ops *cur = __start_rio_switch_ops;
594 struct rio_switch_ops *end = __end_rio_switch_ops;
595
596 while (cur < end) {
597 if ((cur->vid == rdev->vid) && (cur->did == rdev->did)) {
598 pr_debug("RIO: calling init routine for %s\n",
599 rio_name(rdev));
600 cur->init_hook(rdev, do_enum);
601 break;
602 }
603 cur++;
604 }
605
606 if ((cur >= end) && (rdev->pef & RIO_PEF_STD_RT)) {
607 pr_debug("RIO: adding STD routing ops for %s\n",
608 rio_name(rdev));
609 rdev->rswitch->add_entry = rio_std_route_add_entry;
610 rdev->rswitch->get_entry = rio_std_route_get_entry;
611 rdev->rswitch->clr_table = rio_std_route_clr_table;
612 }
613
614 if (!rdev->rswitch->add_entry || !rdev->rswitch->get_entry)
615 printk(KERN_ERR "RIO: missing routing ops for %s\n",
616 rio_name(rdev));
617}
618EXPORT_SYMBOL_GPL(rio_switch_init);
619
620/**
621 * rio_enable_rx_tx_port - enable input receiver and output transmitter of 594 * rio_enable_rx_tx_port - enable input receiver and output transmitter of
622 * given port 595 * given port
623 * @port: Master port associated with the RIO network 596 * @port: Master port associated with the RIO network
@@ -970,8 +943,8 @@ int rio_inb_pwrite_handler(union rio_pw_msg *pw_msg)
970 /* 943 /*
971 * Process the port-write notification from switch 944 * Process the port-write notification from switch
972 */ 945 */
973 if (rdev->rswitch->em_handle) 946 if (rdev->rswitch->ops && rdev->rswitch->ops->em_handle)
974 rdev->rswitch->em_handle(rdev, portnum); 947 rdev->rswitch->ops->em_handle(rdev, portnum);
975 948
976 rio_read_config_32(rdev, 949 rio_read_config_32(rdev,
977 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum), 950 rdev->phys_efptr + RIO_PORT_N_ERR_STS_CSR(portnum),
@@ -1207,8 +1180,9 @@ struct rio_dev *rio_get_device(u16 vid, u16 did, struct rio_dev *from)
1207 * @route_destid: destID entry in the RT 1180 * @route_destid: destID entry in the RT
1208 * @route_port: destination port for specified destID 1181 * @route_port: destination port for specified destID
1209 */ 1182 */
1210int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount, 1183static int
1211 u16 table, u16 route_destid, u8 route_port) 1184rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1185 u16 table, u16 route_destid, u8 route_port)
1212{ 1186{
1213 if (table == RIO_GLOBAL_TABLE) { 1187 if (table == RIO_GLOBAL_TABLE) {
1214 rio_mport_write_config_32(mport, destid, hopcount, 1188 rio_mport_write_config_32(mport, destid, hopcount,
@@ -1234,8 +1208,9 @@ int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1234 * @route_destid: destID entry in the RT 1208 * @route_destid: destID entry in the RT
1235 * @route_port: returned destination port for specified destID 1209 * @route_port: returned destination port for specified destID
1236 */ 1210 */
1237int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount, 1211static int
1238 u16 table, u16 route_destid, u8 *route_port) 1212rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1213 u16 table, u16 route_destid, u8 *route_port)
1239{ 1214{
1240 u32 result; 1215 u32 result;
1241 1216
@@ -1259,8 +1234,9 @@ int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount,
1259 * @hopcount: Number of switch hops to the device 1234 * @hopcount: Number of switch hops to the device
1260 * @table: routing table ID (global or port-specific) 1235 * @table: routing table ID (global or port-specific)
1261 */ 1236 */
1262int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount, 1237static int
1263 u16 table) 1238rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
1239 u16 table)
1264{ 1240{
1265 u32 max_destid = 0xff; 1241 u32 max_destid = 0xff;
1266 u32 i, pef, id_inc = 1, ext_cfg = 0; 1242 u32 i, pef, id_inc = 1, ext_cfg = 0;
@@ -1301,6 +1277,234 @@ int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, u8 hopcount,
1301 return 0; 1277 return 0;
1302} 1278}
1303 1279
1280/**
1281 * rio_lock_device - Acquires host device lock for specified device
1282 * @port: Master port to send transaction
1283 * @destid: Destination ID for device/switch
1284 * @hopcount: Hopcount to reach switch
1285 * @wait_ms: Max wait time in msec (0 = no timeout)
1286 *
1287 * Attepts to acquire host device lock for specified device
1288 * Returns 0 if device lock acquired or EINVAL if timeout expires.
1289 */
1290int rio_lock_device(struct rio_mport *port, u16 destid,
1291 u8 hopcount, int wait_ms)
1292{
1293 u32 result;
1294 int tcnt = 0;
1295
1296 /* Attempt to acquire device lock */
1297 rio_mport_write_config_32(port, destid, hopcount,
1298 RIO_HOST_DID_LOCK_CSR, port->host_deviceid);
1299 rio_mport_read_config_32(port, destid, hopcount,
1300 RIO_HOST_DID_LOCK_CSR, &result);
1301
1302 while (result != port->host_deviceid) {
1303 if (wait_ms != 0 && tcnt == wait_ms) {
1304 pr_debug("RIO: timeout when locking device %x:%x\n",
1305 destid, hopcount);
1306 return -EINVAL;
1307 }
1308
1309 /* Delay a bit */
1310 mdelay(1);
1311 tcnt++;
1312 /* Try to acquire device lock again */
1313 rio_mport_write_config_32(port, destid,
1314 hopcount,
1315 RIO_HOST_DID_LOCK_CSR,
1316 port->host_deviceid);
1317 rio_mport_read_config_32(port, destid,
1318 hopcount,
1319 RIO_HOST_DID_LOCK_CSR, &result);
1320 }
1321
1322 return 0;
1323}
1324EXPORT_SYMBOL_GPL(rio_lock_device);
1325
1326/**
1327 * rio_unlock_device - Releases host device lock for specified device
1328 * @port: Master port to send transaction
1329 * @destid: Destination ID for device/switch
1330 * @hopcount: Hopcount to reach switch
1331 *
1332 * Returns 0 if device lock released or EINVAL if fails.
1333 */
1334int rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount)
1335{
1336 u32 result;
1337
1338 /* Release device lock */
1339 rio_mport_write_config_32(port, destid,
1340 hopcount,
1341 RIO_HOST_DID_LOCK_CSR,
1342 port->host_deviceid);
1343 rio_mport_read_config_32(port, destid, hopcount,
1344 RIO_HOST_DID_LOCK_CSR, &result);
1345 if ((result & 0xffff) != 0xffff) {
1346 pr_debug("RIO: badness when releasing device lock %x:%x\n",
1347 destid, hopcount);
1348 return -EINVAL;
1349 }
1350
1351 return 0;
1352}
1353EXPORT_SYMBOL_GPL(rio_unlock_device);
1354
1355/**
1356 * rio_route_add_entry- Add a route entry to a switch routing table
1357 * @rdev: RIO device
1358 * @table: Routing table ID
1359 * @route_destid: Destination ID to be routed
1360 * @route_port: Port number to be routed
1361 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1362 *
1363 * If available calls the switch specific add_entry() method to add a route
1364 * entry into a switch routing table. Otherwise uses standard RT update method
1365 * as defined by RapidIO specification. A specific routing table can be selected
1366 * using the @table argument if a switch has per port routing tables or
1367 * the standard (or global) table may be used by passing
1368 * %RIO_GLOBAL_TABLE in @table.
1369 *
1370 * Returns %0 on success or %-EINVAL on failure.
1371 */
1372int rio_route_add_entry(struct rio_dev *rdev,
1373 u16 table, u16 route_destid, u8 route_port, int lock)
1374{
1375 int rc = -EINVAL;
1376 struct rio_switch_ops *ops = rdev->rswitch->ops;
1377
1378 if (lock) {
1379 rc = rio_lock_device(rdev->net->hport, rdev->destid,
1380 rdev->hopcount, 1000);
1381 if (rc)
1382 return rc;
1383 }
1384
1385 spin_lock(&rdev->rswitch->lock);
1386
1387 if (ops == NULL || ops->add_entry == NULL) {
1388 rc = rio_std_route_add_entry(rdev->net->hport, rdev->destid,
1389 rdev->hopcount, table,
1390 route_destid, route_port);
1391 } else if (try_module_get(ops->owner)) {
1392 rc = ops->add_entry(rdev->net->hport, rdev->destid,
1393 rdev->hopcount, table, route_destid,
1394 route_port);
1395 module_put(ops->owner);
1396 }
1397
1398 spin_unlock(&rdev->rswitch->lock);
1399
1400 if (lock)
1401 rio_unlock_device(rdev->net->hport, rdev->destid,
1402 rdev->hopcount);
1403
1404 return rc;
1405}
1406EXPORT_SYMBOL_GPL(rio_route_add_entry);
1407
1408/**
1409 * rio_route_get_entry- Read an entry from a switch routing table
1410 * @rdev: RIO device
1411 * @table: Routing table ID
1412 * @route_destid: Destination ID to be routed
1413 * @route_port: Pointer to read port number into
1414 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1415 *
1416 * If available calls the switch specific get_entry() method to fetch a route
1417 * entry from a switch routing table. Otherwise uses standard RT read method
1418 * as defined by RapidIO specification. A specific routing table can be selected
1419 * using the @table argument if a switch has per port routing tables or
1420 * the standard (or global) table may be used by passing
1421 * %RIO_GLOBAL_TABLE in @table.
1422 *
1423 * Returns %0 on success or %-EINVAL on failure.
1424 */
1425int rio_route_get_entry(struct rio_dev *rdev, u16 table,
1426 u16 route_destid, u8 *route_port, int lock)
1427{
1428 int rc = -EINVAL;
1429 struct rio_switch_ops *ops = rdev->rswitch->ops;
1430
1431 if (lock) {
1432 rc = rio_lock_device(rdev->net->hport, rdev->destid,
1433 rdev->hopcount, 1000);
1434 if (rc)
1435 return rc;
1436 }
1437
1438 spin_lock(&rdev->rswitch->lock);
1439
1440 if (ops == NULL || ops->get_entry == NULL) {
1441 rc = rio_std_route_get_entry(rdev->net->hport, rdev->destid,
1442 rdev->hopcount, table,
1443 route_destid, route_port);
1444 } else if (try_module_get(ops->owner)) {
1445 rc = ops->get_entry(rdev->net->hport, rdev->destid,
1446 rdev->hopcount, table, route_destid,
1447 route_port);
1448 module_put(ops->owner);
1449 }
1450
1451 spin_unlock(&rdev->rswitch->lock);
1452
1453 if (lock)
1454 rio_unlock_device(rdev->net->hport, rdev->destid,
1455 rdev->hopcount);
1456 return rc;
1457}
1458EXPORT_SYMBOL_GPL(rio_route_get_entry);
1459
1460/**
1461 * rio_route_clr_table - Clear a switch routing table
1462 * @rdev: RIO device
1463 * @table: Routing table ID
1464 * @lock: apply a hardware lock on switch device flag (1=lock, 0=no_lock)
1465 *
1466 * If available calls the switch specific clr_table() method to clear a switch
1467 * routing table. Otherwise uses standard RT write method as defined by RapidIO
1468 * specification. A specific routing table can be selected using the @table
1469 * argument if a switch has per port routing tables or the standard (or global)
1470 * table may be used by passing %RIO_GLOBAL_TABLE in @table.
1471 *
1472 * Returns %0 on success or %-EINVAL on failure.
1473 */
1474int rio_route_clr_table(struct rio_dev *rdev, u16 table, int lock)
1475{
1476 int rc = -EINVAL;
1477 struct rio_switch_ops *ops = rdev->rswitch->ops;
1478
1479 if (lock) {
1480 rc = rio_lock_device(rdev->net->hport, rdev->destid,
1481 rdev->hopcount, 1000);
1482 if (rc)
1483 return rc;
1484 }
1485
1486 spin_lock(&rdev->rswitch->lock);
1487
1488 if (ops == NULL || ops->clr_table == NULL) {
1489 rc = rio_std_route_clr_table(rdev->net->hport, rdev->destid,
1490 rdev->hopcount, table);
1491 } else if (try_module_get(ops->owner)) {
1492 rc = ops->clr_table(rdev->net->hport, rdev->destid,
1493 rdev->hopcount, table);
1494
1495 module_put(ops->owner);
1496 }
1497
1498 spin_unlock(&rdev->rswitch->lock);
1499
1500 if (lock)
1501 rio_unlock_device(rdev->net->hport, rdev->destid,
1502 rdev->hopcount);
1503
1504 return rc;
1505}
1506EXPORT_SYMBOL_GPL(rio_route_clr_table);
1507
1304#ifdef CONFIG_RAPIDIO_DMA_ENGINE 1508#ifdef CONFIG_RAPIDIO_DMA_ENGINE
1305 1509
1306static bool rio_chan_filter(struct dma_chan *chan, void *arg) 1510static bool rio_chan_filter(struct dma_chan *chan, void *arg)
@@ -1410,34 +1614,73 @@ found:
1410 * rio_register_scan - enumeration/discovery method registration interface 1614 * rio_register_scan - enumeration/discovery method registration interface
1411 * @mport_id: mport device ID for which fabric scan routine has to be set 1615 * @mport_id: mport device ID for which fabric scan routine has to be set
1412 * (RIO_MPORT_ANY = set for all available mports) 1616 * (RIO_MPORT_ANY = set for all available mports)
1413 * @scan_ops: enumeration/discovery control structure 1617 * @scan_ops: enumeration/discovery operations structure
1618 *
1619 * Registers enumeration/discovery operations with RapidIO subsystem and
1620 * attaches it to the specified mport device (or all available mports
1621 * if RIO_MPORT_ANY is specified).
1414 * 1622 *
1415 * Assigns enumeration or discovery method to the specified mport device (or all
1416 * available mports if RIO_MPORT_ANY is specified).
1417 * Returns error if the mport already has an enumerator attached to it. 1623 * Returns error if the mport already has an enumerator attached to it.
1418 * In case of RIO_MPORT_ANY ignores ports with valid scan routines and returns 1624 * In case of RIO_MPORT_ANY skips mports with valid scan routines (no error).
1419 * an error if was unable to find at least one available mport.
1420 */ 1625 */
1421int rio_register_scan(int mport_id, struct rio_scan *scan_ops) 1626int rio_register_scan(int mport_id, struct rio_scan *scan_ops)
1422{ 1627{
1423 struct rio_mport *port; 1628 struct rio_mport *port;
1424 int rc = -EBUSY; 1629 struct rio_scan_node *scan;
1630 int rc = 0;
1425 1631
1426 mutex_lock(&rio_mport_list_lock); 1632 pr_debug("RIO: %s for mport_id=%d\n", __func__, mport_id);
1427 list_for_each_entry(port, &rio_mports, node) {
1428 if (port->id == mport_id || mport_id == RIO_MPORT_ANY) {
1429 if (port->nscan && mport_id == RIO_MPORT_ANY)
1430 continue;
1431 else if (port->nscan)
1432 break;
1433 1633
1434 port->nscan = scan_ops; 1634 if ((mport_id != RIO_MPORT_ANY && mport_id >= RIO_MAX_MPORTS) ||
1435 rc = 0; 1635 !scan_ops)
1636 return -EINVAL;
1436 1637
1437 if (mport_id != RIO_MPORT_ANY) 1638 mutex_lock(&rio_mport_list_lock);
1438 break; 1639
1640 /*
1641 * Check if there is another enumerator already registered for
1642 * the same mport ID (including RIO_MPORT_ANY). Multiple enumerators
1643 * for the same mport ID are not supported.
1644 */
1645 list_for_each_entry(scan, &rio_scans, node) {
1646 if (scan->mport_id == mport_id) {
1647 rc = -EBUSY;
1648 goto err_out;
1439 } 1649 }
1440 } 1650 }
1651
1652 /*
1653 * Allocate and initialize new scan registration node.
1654 */
1655 scan = kzalloc(sizeof(*scan), GFP_KERNEL);
1656 if (!scan) {
1657 rc = -ENOMEM;
1658 goto err_out;
1659 }
1660
1661 scan->mport_id = mport_id;
1662 scan->ops = scan_ops;
1663
1664 /*
1665 * Traverse the list of registered mports to attach this new scan.
1666 *
1667 * The new scan with matching mport ID overrides any previously attached
1668 * scan assuming that old scan (if any) is the default one (based on the
1669 * enumerator registration check above).
1670 * If the new scan is the global one, it will be attached only to mports
1671 * that do not have their own individual operations already attached.
1672 */
1673 list_for_each_entry(port, &rio_mports, node) {
1674 if (port->id == mport_id) {
1675 port->nscan = scan_ops;
1676 break;
1677 } else if (mport_id == RIO_MPORT_ANY && !port->nscan)
1678 port->nscan = scan_ops;
1679 }
1680
1681 list_add_tail(&scan->node, &rio_scans);
1682
1683err_out:
1441 mutex_unlock(&rio_mport_list_lock); 1684 mutex_unlock(&rio_mport_list_lock);
1442 1685
1443 return rc; 1686 return rc;
@@ -1447,30 +1690,81 @@ EXPORT_SYMBOL_GPL(rio_register_scan);
1447/** 1690/**
1448 * rio_unregister_scan - removes enumeration/discovery method from mport 1691 * rio_unregister_scan - removes enumeration/discovery method from mport
1449 * @mport_id: mport device ID for which fabric scan routine has to be 1692 * @mport_id: mport device ID for which fabric scan routine has to be
1450 * unregistered (RIO_MPORT_ANY = set for all available mports) 1693 * unregistered (RIO_MPORT_ANY = apply to all mports that use
1694 * the specified scan_ops)
1695 * @scan_ops: enumeration/discovery operations structure
1451 * 1696 *
1452 * Removes enumeration or discovery method assigned to the specified mport 1697 * Removes enumeration or discovery method assigned to the specified mport
1453 * device (or all available mports if RIO_MPORT_ANY is specified). 1698 * device. If RIO_MPORT_ANY is specified, removes the specified operations from
1699 * all mports that have them attached.
1454 */ 1700 */
1455int rio_unregister_scan(int mport_id) 1701int rio_unregister_scan(int mport_id, struct rio_scan *scan_ops)
1456{ 1702{
1457 struct rio_mport *port; 1703 struct rio_mport *port;
1704 struct rio_scan_node *scan;
1705
1706 pr_debug("RIO: %s for mport_id=%d\n", __func__, mport_id);
1707
1708 if (mport_id != RIO_MPORT_ANY && mport_id >= RIO_MAX_MPORTS)
1709 return -EINVAL;
1458 1710
1459 mutex_lock(&rio_mport_list_lock); 1711 mutex_lock(&rio_mport_list_lock);
1460 list_for_each_entry(port, &rio_mports, node) { 1712
1461 if (port->id == mport_id || mport_id == RIO_MPORT_ANY) { 1713 list_for_each_entry(port, &rio_mports, node)
1462 if (port->nscan) 1714 if (port->id == mport_id ||
1463 port->nscan = NULL; 1715 (mport_id == RIO_MPORT_ANY && port->nscan == scan_ops))
1464 if (mport_id != RIO_MPORT_ANY) 1716 port->nscan = NULL;
1465 break; 1717
1718 list_for_each_entry(scan, &rio_scans, node)
1719 if (scan->mport_id == mport_id) {
1720 list_del(&scan->node);
1721 kfree(scan);
1466 } 1722 }
1467 } 1723
1468 mutex_unlock(&rio_mport_list_lock); 1724 mutex_unlock(&rio_mport_list_lock);
1469 1725
1470 return 0; 1726 return 0;
1471} 1727}
1472EXPORT_SYMBOL_GPL(rio_unregister_scan); 1728EXPORT_SYMBOL_GPL(rio_unregister_scan);
1473 1729
1730/**
1731 * rio_mport_scan - execute enumeration/discovery on the specified mport
1732 * @mport_id: number (ID) of mport device
1733 */
1734int rio_mport_scan(int mport_id)
1735{
1736 struct rio_mport *port = NULL;
1737 int rc;
1738
1739 mutex_lock(&rio_mport_list_lock);
1740 list_for_each_entry(port, &rio_mports, node) {
1741 if (port->id == mport_id)
1742 goto found;
1743 }
1744 mutex_unlock(&rio_mport_list_lock);
1745 return -ENODEV;
1746found:
1747 if (!port->nscan) {
1748 mutex_unlock(&rio_mport_list_lock);
1749 return -EINVAL;
1750 }
1751
1752 if (!try_module_get(port->nscan->owner)) {
1753 mutex_unlock(&rio_mport_list_lock);
1754 return -ENODEV;
1755 }
1756
1757 mutex_unlock(&rio_mport_list_lock);
1758
1759 if (port->host_deviceid >= 0)
1760 rc = port->nscan->enumerate(port, 0);
1761 else
1762 rc = port->nscan->discover(port, RIO_SCAN_ENUM_NO_WAIT);
1763
1764 module_put(port->nscan->owner);
1765 return rc;
1766}
1767
1474static void rio_fixup_device(struct rio_dev *dev) 1768static void rio_fixup_device(struct rio_dev *dev)
1475{ 1769{
1476} 1770}
@@ -1499,7 +1793,10 @@ static void disc_work_handler(struct work_struct *_work)
1499 work = container_of(_work, struct rio_disc_work, work); 1793 work = container_of(_work, struct rio_disc_work, work);
1500 pr_debug("RIO: discovery work for mport %d %s\n", 1794 pr_debug("RIO: discovery work for mport %d %s\n",
1501 work->mport->id, work->mport->name); 1795 work->mport->id, work->mport->name);
1502 work->mport->nscan->discover(work->mport, 0); 1796 if (try_module_get(work->mport->nscan->owner)) {
1797 work->mport->nscan->discover(work->mport, 0);
1798 module_put(work->mport->nscan->owner);
1799 }
1503} 1800}
1504 1801
1505int rio_init_mports(void) 1802int rio_init_mports(void)
@@ -1518,8 +1815,10 @@ int rio_init_mports(void)
1518 mutex_lock(&rio_mport_list_lock); 1815 mutex_lock(&rio_mport_list_lock);
1519 list_for_each_entry(port, &rio_mports, node) { 1816 list_for_each_entry(port, &rio_mports, node) {
1520 if (port->host_deviceid >= 0) { 1817 if (port->host_deviceid >= 0) {
1521 if (port->nscan) 1818 if (port->nscan && try_module_get(port->nscan->owner)) {
1522 port->nscan->enumerate(port, 0); 1819 port->nscan->enumerate(port, 0);
1820 module_put(port->nscan->owner);
1821 }
1523 } else 1822 } else
1524 n++; 1823 n++;
1525 } 1824 }
@@ -1533,7 +1832,7 @@ int rio_init_mports(void)
1533 * for each of them. If the code below fails to allocate needed 1832 * for each of them. If the code below fails to allocate needed
1534 * resources, exit without error to keep results of enumeration 1833 * resources, exit without error to keep results of enumeration
1535 * process (if any). 1834 * process (if any).
1536 * TODO: Implement restart of dicovery process for all or 1835 * TODO: Implement restart of discovery process for all or
1537 * individual discovering mports. 1836 * individual discovering mports.
1538 */ 1837 */
1539 rio_wq = alloc_workqueue("riodisc", 0, 0); 1838 rio_wq = alloc_workqueue("riodisc", 0, 0);
@@ -1559,9 +1858,9 @@ int rio_init_mports(void)
1559 n++; 1858 n++;
1560 } 1859 }
1561 } 1860 }
1562 mutex_unlock(&rio_mport_list_lock);
1563 1861
1564 flush_workqueue(rio_wq); 1862 flush_workqueue(rio_wq);
1863 mutex_unlock(&rio_mport_list_lock);
1565 pr_debug("RIO: destroy discovery workqueue\n"); 1864 pr_debug("RIO: destroy discovery workqueue\n");
1566 destroy_workqueue(rio_wq); 1865 destroy_workqueue(rio_wq);
1567 kfree(work); 1866 kfree(work);
@@ -1572,26 +1871,18 @@ no_disc:
1572 return 0; 1871 return 0;
1573} 1872}
1574 1873
1575static int hdids[RIO_MAX_MPORTS + 1];
1576
1577static int rio_get_hdid(int index) 1874static int rio_get_hdid(int index)
1578{ 1875{
1579 if (!hdids[0] || hdids[0] <= index || index >= RIO_MAX_MPORTS) 1876 if (ids_num == 0 || ids_num <= index || index >= RIO_MAX_MPORTS)
1580 return -1; 1877 return -1;
1581 1878
1582 return hdids[index + 1]; 1879 return hdid[index];
1583}
1584
1585static int rio_hdid_setup(char *str)
1586{
1587 (void)get_options(str, ARRAY_SIZE(hdids), hdids);
1588 return 1;
1589} 1880}
1590 1881
1591__setup("riohdid=", rio_hdid_setup);
1592
1593int rio_register_mport(struct rio_mport *port) 1882int rio_register_mport(struct rio_mport *port)
1594{ 1883{
1884 struct rio_scan_node *scan = NULL;
1885
1595 if (next_portid >= RIO_MAX_MPORTS) { 1886 if (next_portid >= RIO_MAX_MPORTS) {
1596 pr_err("RIO: reached specified max number of mports\n"); 1887 pr_err("RIO: reached specified max number of mports\n");
1597 return 1; 1888 return 1;
@@ -1600,11 +1891,28 @@ int rio_register_mport(struct rio_mport *port)
1600 port->id = next_portid++; 1891 port->id = next_portid++;
1601 port->host_deviceid = rio_get_hdid(port->id); 1892 port->host_deviceid = rio_get_hdid(port->id);
1602 port->nscan = NULL; 1893 port->nscan = NULL;
1894
1603 mutex_lock(&rio_mport_list_lock); 1895 mutex_lock(&rio_mport_list_lock);
1604 list_add_tail(&port->node, &rio_mports); 1896 list_add_tail(&port->node, &rio_mports);
1897
1898 /*
1899 * Check if there are any registered enumeration/discovery operations
1900 * that have to be attached to the added mport.
1901 */
1902 list_for_each_entry(scan, &rio_scans, node) {
1903 if (port->id == scan->mport_id ||
1904 scan->mport_id == RIO_MPORT_ANY) {
1905 port->nscan = scan->ops;
1906 if (port->id == scan->mport_id)
1907 break;
1908 }
1909 }
1605 mutex_unlock(&rio_mport_list_lock); 1910 mutex_unlock(&rio_mport_list_lock);
1911
1912 pr_debug("RIO: %s %s id=%d\n", __func__, port->name, port->id);
1606 return 0; 1913 return 0;
1607} 1914}
1915EXPORT_SYMBOL_GPL(rio_register_mport);
1608 1916
1609EXPORT_SYMBOL_GPL(rio_local_get_device_id); 1917EXPORT_SYMBOL_GPL(rio_local_get_device_id);
1610EXPORT_SYMBOL_GPL(rio_get_device); 1918EXPORT_SYMBOL_GPL(rio_get_device);
diff --git a/drivers/rapidio/rio.h b/drivers/rapidio/rio.h
index c14f864dea5c..085215cd8502 100644
--- a/drivers/rapidio/rio.h
+++ b/drivers/rapidio/rio.h
@@ -28,52 +28,28 @@ extern u32 rio_mport_get_efb(struct rio_mport *port, int local, u16 destid,
28extern int rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid, 28extern int rio_mport_chk_dev_access(struct rio_mport *mport, u16 destid,
29 u8 hopcount); 29 u8 hopcount);
30extern int rio_create_sysfs_dev_files(struct rio_dev *rdev); 30extern int rio_create_sysfs_dev_files(struct rio_dev *rdev);
31extern int rio_std_route_add_entry(struct rio_mport *mport, u16 destid, 31extern int rio_lock_device(struct rio_mport *port, u16 destid,
32 u8 hopcount, u16 table, u16 route_destid, 32 u8 hopcount, int wait_ms);
33 u8 route_port); 33extern int rio_unlock_device(struct rio_mport *port, u16 destid, u8 hopcount);
34extern int rio_std_route_get_entry(struct rio_mport *mport, u16 destid, 34extern int rio_route_add_entry(struct rio_dev *rdev,
35 u8 hopcount, u16 table, u16 route_destid, 35 u16 table, u16 route_destid, u8 route_port, int lock);
36 u8 *route_port); 36extern int rio_route_get_entry(struct rio_dev *rdev, u16 table,
37extern int rio_std_route_clr_table(struct rio_mport *mport, u16 destid, 37 u16 route_destid, u8 *route_port, int lock);
38 u8 hopcount, u16 table); 38extern int rio_route_clr_table(struct rio_dev *rdev, u16 table, int lock);
39extern int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock); 39extern int rio_set_port_lockout(struct rio_dev *rdev, u32 pnum, int lock);
40extern struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from); 40extern struct rio_dev *rio_get_comptag(u32 comp_tag, struct rio_dev *from);
41extern int rio_add_device(struct rio_dev *rdev); 41extern int rio_add_device(struct rio_dev *rdev);
42extern void rio_switch_init(struct rio_dev *rdev, int do_enum);
43extern int rio_enable_rx_tx_port(struct rio_mport *port, int local, u16 destid, 42extern int rio_enable_rx_tx_port(struct rio_mport *port, int local, u16 destid,
44 u8 hopcount, u8 port_num); 43 u8 hopcount, u8 port_num);
45extern int rio_register_scan(int mport_id, struct rio_scan *scan_ops); 44extern int rio_register_scan(int mport_id, struct rio_scan *scan_ops);
46extern int rio_unregister_scan(int mport_id); 45extern int rio_unregister_scan(int mport_id, struct rio_scan *scan_ops);
47extern void rio_attach_device(struct rio_dev *rdev); 46extern void rio_attach_device(struct rio_dev *rdev);
48extern struct rio_mport *rio_find_mport(int mport_id); 47extern struct rio_mport *rio_find_mport(int mport_id);
48extern int rio_mport_scan(int mport_id);
49 49
50/* Structures internal to the RIO core code */ 50/* Structures internal to the RIO core code */
51extern struct device_attribute rio_dev_attrs[]; 51extern struct device_attribute rio_dev_attrs[];
52extern struct bus_attribute rio_bus_attrs[]; 52extern struct bus_attribute rio_bus_attrs[];
53 53
54extern struct rio_switch_ops __start_rio_switch_ops[];
55extern struct rio_switch_ops __end_rio_switch_ops[];
56
57/* Helpers internal to the RIO core code */
58#define DECLARE_RIO_SWITCH_SECTION(section, name, vid, did, init_hook) \
59 static const struct rio_switch_ops __rio_switch_##name __used \
60 __section(section) = { vid, did, init_hook };
61
62/**
63 * DECLARE_RIO_SWITCH_INIT - Registers switch initialization routine
64 * @vid: RIO vendor ID
65 * @did: RIO device ID
66 * @init_hook: Callback that performs switch-specific initialization
67 *
68 * Manipulating switch route tables and error management in RIO
69 * is switch specific. This registers a switch by vendor and device ID with
70 * initialization callback for setting up switch operations and (if required)
71 * hardware initialization. A &struct rio_switch_ops is initialized with
72 * pointer to the init routine and placed into a RIO-specific kernel section.
73 */
74#define DECLARE_RIO_SWITCH_INIT(vid, did, init_hook) \
75 DECLARE_RIO_SWITCH_SECTION(.rio_switch_ops, vid##did, \
76 vid, did, init_hook)
77
78#define RIO_GET_DID(size, x) (size ? (x & 0xffff) : ((x & 0x00ff0000) >> 16)) 54#define RIO_GET_DID(size, x) (size ? (x & 0xffff) : ((x & 0x00ff0000) >> 16))
79#define RIO_SET_DID(size, x) (size ? (x & 0xffff) : ((x & 0x000000ff) << 16)) 55#define RIO_SET_DID(size, x) (size ? (x & 0xffff) : ((x & 0x000000ff) << 16))
diff --git a/drivers/rapidio/switches/Kconfig b/drivers/rapidio/switches/Kconfig
index f47fee5d4563..345841562f95 100644
--- a/drivers/rapidio/switches/Kconfig
+++ b/drivers/rapidio/switches/Kconfig
@@ -2,34 +2,23 @@
2# RapidIO switches configuration 2# RapidIO switches configuration
3# 3#
4config RAPIDIO_TSI57X 4config RAPIDIO_TSI57X
5 bool "IDT Tsi57x SRIO switches support" 5 tristate "IDT Tsi57x SRIO switches support"
6 depends on RAPIDIO
7 ---help--- 6 ---help---
8 Includes support for IDT Tsi57x family of serial RapidIO switches. 7 Includes support for IDT Tsi57x family of serial RapidIO switches.
9 8
10config RAPIDIO_CPS_XX 9config RAPIDIO_CPS_XX
11 bool "IDT CPS-xx SRIO switches support" 10 tristate "IDT CPS-xx SRIO switches support"
12 depends on RAPIDIO
13 ---help--- 11 ---help---
14 Includes support for IDT CPS-16/12/10/8 serial RapidIO switches. 12 Includes support for IDT CPS-16/12/10/8 serial RapidIO switches.
15 13
16config RAPIDIO_TSI568 14config RAPIDIO_TSI568
17 bool "Tsi568 SRIO switch support" 15 tristate "Tsi568 SRIO switch support"
18 depends on RAPIDIO
19 default n 16 default n
20 ---help--- 17 ---help---
21 Includes support for IDT Tsi568 serial RapidIO switch. 18 Includes support for IDT Tsi568 serial RapidIO switch.
22 19
23config RAPIDIO_CPS_GEN2 20config RAPIDIO_CPS_GEN2
24 bool "IDT CPS Gen.2 SRIO switch support" 21 tristate "IDT CPS Gen.2 SRIO switch support"
25 depends on RAPIDIO
26 default n 22 default n
27 ---help--- 23 ---help---
28 Includes support for ITD CPS Gen.2 serial RapidIO switches. 24 Includes support for ITD CPS Gen.2 serial RapidIO switches.
29
30config RAPIDIO_TSI500
31 bool "Tsi500 Parallel RapidIO switch support"
32 depends on RAPIDIO
33 default n
34 ---help---
35 Includes support for IDT Tsi500 parallel RapidIO switch.
diff --git a/drivers/rapidio/switches/Makefile b/drivers/rapidio/switches/Makefile
index c4d3acc3c715..051cc6b38188 100644
--- a/drivers/rapidio/switches/Makefile
+++ b/drivers/rapidio/switches/Makefile
@@ -5,5 +5,4 @@
5obj-$(CONFIG_RAPIDIO_TSI57X) += tsi57x.o 5obj-$(CONFIG_RAPIDIO_TSI57X) += tsi57x.o
6obj-$(CONFIG_RAPIDIO_CPS_XX) += idtcps.o 6obj-$(CONFIG_RAPIDIO_CPS_XX) += idtcps.o
7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o 7obj-$(CONFIG_RAPIDIO_TSI568) += tsi568.o
8obj-$(CONFIG_RAPIDIO_TSI500) += tsi500.o
9obj-$(CONFIG_RAPIDIO_CPS_GEN2) += idt_gen2.o 8obj-$(CONFIG_RAPIDIO_CPS_GEN2) += idt_gen2.o
diff --git a/drivers/rapidio/switches/idt_gen2.c b/drivers/rapidio/switches/idt_gen2.c
index 809b7a3336ba..00a71ebb5cac 100644
--- a/drivers/rapidio/switches/idt_gen2.c
+++ b/drivers/rapidio/switches/idt_gen2.c
@@ -11,6 +11,7 @@
11 */ 11 */
12 12
13#include <linux/stat.h> 13#include <linux/stat.h>
14#include <linux/module.h>
14#include <linux/rio.h> 15#include <linux/rio.h>
15#include <linux/rio_drv.h> 16#include <linux/rio_drv.h>
16#include <linux/rio_ids.h> 17#include <linux/rio_ids.h>
@@ -387,12 +388,12 @@ idtg2_show_errlog(struct device *dev, struct device_attribute *attr, char *buf)
387 388
388static DEVICE_ATTR(errlog, S_IRUGO, idtg2_show_errlog, NULL); 389static DEVICE_ATTR(errlog, S_IRUGO, idtg2_show_errlog, NULL);
389 390
390static int idtg2_sysfs(struct rio_dev *rdev, int create) 391static int idtg2_sysfs(struct rio_dev *rdev, bool create)
391{ 392{
392 struct device *dev = &rdev->dev; 393 struct device *dev = &rdev->dev;
393 int err = 0; 394 int err = 0;
394 395
395 if (create == RIO_SW_SYSFS_CREATE) { 396 if (create) {
396 /* Initialize sysfs entries */ 397 /* Initialize sysfs entries */
397 err = device_create_file(dev, &dev_attr_errlog); 398 err = device_create_file(dev, &dev_attr_errlog);
398 if (err) 399 if (err)
@@ -403,29 +404,90 @@ static int idtg2_sysfs(struct rio_dev *rdev, int create)
403 return err; 404 return err;
404} 405}
405 406
406static int idtg2_switch_init(struct rio_dev *rdev, int do_enum) 407static struct rio_switch_ops idtg2_switch_ops = {
408 .owner = THIS_MODULE,
409 .add_entry = idtg2_route_add_entry,
410 .get_entry = idtg2_route_get_entry,
411 .clr_table = idtg2_route_clr_table,
412 .set_domain = idtg2_set_domain,
413 .get_domain = idtg2_get_domain,
414 .em_init = idtg2_em_init,
415 .em_handle = idtg2_em_handler,
416};
417
418static int idtg2_probe(struct rio_dev *rdev, const struct rio_device_id *id)
407{ 419{
408 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev)); 420 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
409 rdev->rswitch->add_entry = idtg2_route_add_entry; 421
410 rdev->rswitch->get_entry = idtg2_route_get_entry; 422 spin_lock(&rdev->rswitch->lock);
411 rdev->rswitch->clr_table = idtg2_route_clr_table; 423
412 rdev->rswitch->set_domain = idtg2_set_domain; 424 if (rdev->rswitch->ops) {
413 rdev->rswitch->get_domain = idtg2_get_domain; 425 spin_unlock(&rdev->rswitch->lock);
414 rdev->rswitch->em_init = idtg2_em_init; 426 return -EINVAL;
415 rdev->rswitch->em_handle = idtg2_em_handler; 427 }
416 rdev->rswitch->sw_sysfs = idtg2_sysfs; 428
417 429 rdev->rswitch->ops = &idtg2_switch_ops;
418 if (do_enum) { 430
431 if (rdev->do_enum) {
419 /* Ensure that default routing is disabled on startup */ 432 /* Ensure that default routing is disabled on startup */
420 rio_write_config_32(rdev, 433 rio_write_config_32(rdev,
421 RIO_STD_RTE_DEFAULT_PORT, IDT_NO_ROUTE); 434 RIO_STD_RTE_DEFAULT_PORT, IDT_NO_ROUTE);
422 } 435 }
423 436
437 /* Create device-specific sysfs attributes */
438 idtg2_sysfs(rdev, true);
439
440 spin_unlock(&rdev->rswitch->lock);
424 return 0; 441 return 0;
425} 442}
426 443
427DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1848, idtg2_switch_init); 444static void idtg2_remove(struct rio_dev *rdev)
428DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1616, idtg2_switch_init); 445{
429DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTVPS1616, idtg2_switch_init); 446 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
430DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTSPS1616, idtg2_switch_init); 447 spin_lock(&rdev->rswitch->lock);
431DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS1432, idtg2_switch_init); 448 if (rdev->rswitch->ops != &idtg2_switch_ops) {
449 spin_unlock(&rdev->rswitch->lock);
450 return;
451 }
452 rdev->rswitch->ops = NULL;
453
454 /* Remove device-specific sysfs attributes */
455 idtg2_sysfs(rdev, false);
456
457 spin_unlock(&rdev->rswitch->lock);
458}
459
460static struct rio_device_id idtg2_id_table[] = {
461 {RIO_DEVICE(RIO_DID_IDTCPS1848, RIO_VID_IDT)},
462 {RIO_DEVICE(RIO_DID_IDTCPS1616, RIO_VID_IDT)},
463 {RIO_DEVICE(RIO_DID_IDTVPS1616, RIO_VID_IDT)},
464 {RIO_DEVICE(RIO_DID_IDTSPS1616, RIO_VID_IDT)},
465 {RIO_DEVICE(RIO_DID_IDTCPS1432, RIO_VID_IDT)},
466 { 0, } /* terminate list */
467};
468
469static struct rio_driver idtg2_driver = {
470 .name = "idt_gen2",
471 .id_table = idtg2_id_table,
472 .probe = idtg2_probe,
473 .remove = idtg2_remove,
474};
475
476static int __init idtg2_init(void)
477{
478 return rio_register_driver(&idtg2_driver);
479}
480
481static void __exit idtg2_exit(void)
482{
483 pr_debug("RIO: %s\n", __func__);
484 rio_unregister_driver(&idtg2_driver);
485 pr_debug("RIO: %s done\n", __func__);
486}
487
488device_initcall(idtg2_init);
489module_exit(idtg2_exit);
490
491MODULE_DESCRIPTION("IDT CPS Gen.2 Serial RapidIO switch family driver");
492MODULE_AUTHOR("Integrated Device Technology, Inc.");
493MODULE_LICENSE("GPL");
diff --git a/drivers/rapidio/switches/idtcps.c b/drivers/rapidio/switches/idtcps.c
index d06ee2d44b44..7fbb60d31796 100644
--- a/drivers/rapidio/switches/idtcps.c
+++ b/drivers/rapidio/switches/idtcps.c
@@ -13,6 +13,7 @@
13#include <linux/rio.h> 13#include <linux/rio.h>
14#include <linux/rio_drv.h> 14#include <linux/rio_drv.h>
15#include <linux/rio_ids.h> 15#include <linux/rio_ids.h>
16#include <linux/module.h>
16#include "../rio.h" 17#include "../rio.h"
17 18
18#define CPS_DEFAULT_ROUTE 0xde 19#define CPS_DEFAULT_ROUTE 0xde
@@ -118,18 +119,31 @@ idtcps_get_domain(struct rio_mport *mport, u16 destid, u8 hopcount,
118 return 0; 119 return 0;
119} 120}
120 121
121static int idtcps_switch_init(struct rio_dev *rdev, int do_enum) 122static struct rio_switch_ops idtcps_switch_ops = {
123 .owner = THIS_MODULE,
124 .add_entry = idtcps_route_add_entry,
125 .get_entry = idtcps_route_get_entry,
126 .clr_table = idtcps_route_clr_table,
127 .set_domain = idtcps_set_domain,
128 .get_domain = idtcps_get_domain,
129 .em_init = NULL,
130 .em_handle = NULL,
131};
132
133static int idtcps_probe(struct rio_dev *rdev, const struct rio_device_id *id)
122{ 134{
123 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev)); 135 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
124 rdev->rswitch->add_entry = idtcps_route_add_entry; 136
125 rdev->rswitch->get_entry = idtcps_route_get_entry; 137 spin_lock(&rdev->rswitch->lock);
126 rdev->rswitch->clr_table = idtcps_route_clr_table; 138
127 rdev->rswitch->set_domain = idtcps_set_domain; 139 if (rdev->rswitch->ops) {
128 rdev->rswitch->get_domain = idtcps_get_domain; 140 spin_unlock(&rdev->rswitch->lock);
129 rdev->rswitch->em_init = NULL; 141 return -EINVAL;
130 rdev->rswitch->em_handle = NULL; 142 }
131 143
132 if (do_enum) { 144 rdev->rswitch->ops = &idtcps_switch_ops;
145
146 if (rdev->do_enum) {
133 /* set TVAL = ~50us */ 147 /* set TVAL = ~50us */
134 rio_write_config_32(rdev, 148 rio_write_config_32(rdev,
135 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8); 149 rdev->phys_efptr + RIO_PORT_LINKTO_CTL_CSR, 0x8e << 8);
@@ -138,12 +152,52 @@ static int idtcps_switch_init(struct rio_dev *rdev, int do_enum)
138 RIO_STD_RTE_DEFAULT_PORT, CPS_NO_ROUTE); 152 RIO_STD_RTE_DEFAULT_PORT, CPS_NO_ROUTE);
139 } 153 }
140 154
155 spin_unlock(&rdev->rswitch->lock);
141 return 0; 156 return 0;
142} 157}
143 158
144DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS6Q, idtcps_switch_init); 159static void idtcps_remove(struct rio_dev *rdev)
145DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS8, idtcps_switch_init); 160{
146DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS10Q, idtcps_switch_init); 161 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
147DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS12, idtcps_switch_init); 162 spin_lock(&rdev->rswitch->lock);
148DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDTCPS16, idtcps_switch_init); 163 if (rdev->rswitch->ops != &idtcps_switch_ops) {
149DECLARE_RIO_SWITCH_INIT(RIO_VID_IDT, RIO_DID_IDT70K200, idtcps_switch_init); 164 spin_unlock(&rdev->rswitch->lock);
165 return;
166 }
167 rdev->rswitch->ops = NULL;
168 spin_unlock(&rdev->rswitch->lock);
169}
170
171static struct rio_device_id idtcps_id_table[] = {
172 {RIO_DEVICE(RIO_DID_IDTCPS6Q, RIO_VID_IDT)},
173 {RIO_DEVICE(RIO_DID_IDTCPS8, RIO_VID_IDT)},
174 {RIO_DEVICE(RIO_DID_IDTCPS10Q, RIO_VID_IDT)},
175 {RIO_DEVICE(RIO_DID_IDTCPS12, RIO_VID_IDT)},
176 {RIO_DEVICE(RIO_DID_IDTCPS16, RIO_VID_IDT)},
177 {RIO_DEVICE(RIO_DID_IDT70K200, RIO_VID_IDT)},
178 { 0, } /* terminate list */
179};
180
181static struct rio_driver idtcps_driver = {
182 .name = "idtcps",
183 .id_table = idtcps_id_table,
184 .probe = idtcps_probe,
185 .remove = idtcps_remove,
186};
187
188static int __init idtcps_init(void)
189{
190 return rio_register_driver(&idtcps_driver);
191}
192
193static void __exit idtcps_exit(void)
194{
195 rio_unregister_driver(&idtcps_driver);
196}
197
198device_initcall(idtcps_init);
199module_exit(idtcps_exit);
200
201MODULE_DESCRIPTION("IDT CPS Gen.1 Serial RapidIO switch family driver");
202MODULE_AUTHOR("Integrated Device Technology, Inc.");
203MODULE_LICENSE("GPL");
diff --git a/drivers/rapidio/switches/tsi500.c b/drivers/rapidio/switches/tsi500.c
deleted file mode 100644
index 914eddd5aa42..000000000000
--- a/drivers/rapidio/switches/tsi500.c
+++ /dev/null
@@ -1,78 +0,0 @@
1/*
2 * RapidIO Tsi500 switch support
3 *
4 * Copyright 2009-2010 Integrated Device Technology, Inc.
5 * Alexandre Bounine <alexandre.bounine@idt.com>
6 * - Modified switch operations initialization.
7 *
8 * Copyright 2005 MontaVista Software, Inc.
9 * Matt Porter <mporter@kernel.crashing.org>
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by the
13 * Free Software Foundation; either version 2 of the License, or (at your
14 * option) any later version.
15 */
16
17#include <linux/rio.h>
18#include <linux/rio_drv.h>
19#include <linux/rio_ids.h>
20#include "../rio.h"
21
22static int
23tsi500_route_add_entry(struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 route_port)
24{
25 int i;
26 u32 offset = 0x10000 + 0xa00 + ((route_destid / 2)&~0x3);
27 u32 result;
28
29 if (table == 0xff) {
30 rio_mport_read_config_32(mport, destid, hopcount, offset, &result);
31 result &= ~(0xf << (4*(route_destid & 0x7)));
32 for (i=0;i<4;i++)
33 rio_mport_write_config_32(mport, destid, hopcount, offset + (0x20000*i), result | (route_port << (4*(route_destid & 0x7))));
34 }
35 else {
36 rio_mport_read_config_32(mport, destid, hopcount, offset + (0x20000*table), &result);
37 result &= ~(0xf << (4*(route_destid & 0x7)));
38 rio_mport_write_config_32(mport, destid, hopcount, offset + (0x20000*table), result | (route_port << (4*(route_destid & 0x7))));
39 }
40
41 return 0;
42}
43
44static int
45tsi500_route_get_entry(struct rio_mport *mport, u16 destid, u8 hopcount, u16 table, u16 route_destid, u8 *route_port)
46{
47 int ret = 0;
48 u32 offset = 0x10000 + 0xa00 + ((route_destid / 2)&~0x3);
49 u32 result;
50
51 if (table == 0xff)
52 rio_mport_read_config_32(mport, destid, hopcount, offset, &result);
53 else
54 rio_mport_read_config_32(mport, destid, hopcount, offset + (0x20000*table), &result);
55
56 result &= 0xf << (4*(route_destid & 0x7));
57 *route_port = result >> (4*(route_destid & 0x7));
58 if (*route_port > 3)
59 ret = -1;
60
61 return ret;
62}
63
64static int tsi500_switch_init(struct rio_dev *rdev, int do_enum)
65{
66 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
67 rdev->rswitch->add_entry = tsi500_route_add_entry;
68 rdev->rswitch->get_entry = tsi500_route_get_entry;
69 rdev->rswitch->clr_table = NULL;
70 rdev->rswitch->set_domain = NULL;
71 rdev->rswitch->get_domain = NULL;
72 rdev->rswitch->em_init = NULL;
73 rdev->rswitch->em_handle = NULL;
74
75 return 0;
76}
77
78DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI500, tsi500_switch_init);
diff --git a/drivers/rapidio/switches/tsi568.c b/drivers/rapidio/switches/tsi568.c
index 3994c00aa01f..8a43561b9d17 100644
--- a/drivers/rapidio/switches/tsi568.c
+++ b/drivers/rapidio/switches/tsi568.c
@@ -19,6 +19,7 @@
19#include <linux/rio_drv.h> 19#include <linux/rio_drv.h>
20#include <linux/rio_ids.h> 20#include <linux/rio_ids.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/module.h>
22#include "../rio.h" 23#include "../rio.h"
23 24
24/* Global (broadcast) route registers */ 25/* Global (broadcast) route registers */
@@ -129,18 +130,70 @@ tsi568_em_init(struct rio_dev *rdev)
129 return 0; 130 return 0;
130} 131}
131 132
132static int tsi568_switch_init(struct rio_dev *rdev, int do_enum) 133static struct rio_switch_ops tsi568_switch_ops = {
134 .owner = THIS_MODULE,
135 .add_entry = tsi568_route_add_entry,
136 .get_entry = tsi568_route_get_entry,
137 .clr_table = tsi568_route_clr_table,
138 .set_domain = NULL,
139 .get_domain = NULL,
140 .em_init = tsi568_em_init,
141 .em_handle = NULL,
142};
143
144static int tsi568_probe(struct rio_dev *rdev, const struct rio_device_id *id)
133{ 145{
134 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev)); 146 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
135 rdev->rswitch->add_entry = tsi568_route_add_entry;
136 rdev->rswitch->get_entry = tsi568_route_get_entry;
137 rdev->rswitch->clr_table = tsi568_route_clr_table;
138 rdev->rswitch->set_domain = NULL;
139 rdev->rswitch->get_domain = NULL;
140 rdev->rswitch->em_init = tsi568_em_init;
141 rdev->rswitch->em_handle = NULL;
142 147
148 spin_lock(&rdev->rswitch->lock);
149
150 if (rdev->rswitch->ops) {
151 spin_unlock(&rdev->rswitch->lock);
152 return -EINVAL;
153 }
154
155 rdev->rswitch->ops = &tsi568_switch_ops;
156 spin_unlock(&rdev->rswitch->lock);
143 return 0; 157 return 0;
144} 158}
145 159
146DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI568, tsi568_switch_init); 160static void tsi568_remove(struct rio_dev *rdev)
161{
162 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
163 spin_lock(&rdev->rswitch->lock);
164 if (rdev->rswitch->ops != &tsi568_switch_ops) {
165 spin_unlock(&rdev->rswitch->lock);
166 return;
167 }
168 rdev->rswitch->ops = NULL;
169 spin_unlock(&rdev->rswitch->lock);
170}
171
172static struct rio_device_id tsi568_id_table[] = {
173 {RIO_DEVICE(RIO_DID_TSI568, RIO_VID_TUNDRA)},
174 { 0, } /* terminate list */
175};
176
177static struct rio_driver tsi568_driver = {
178 .name = "tsi568",
179 .id_table = tsi568_id_table,
180 .probe = tsi568_probe,
181 .remove = tsi568_remove,
182};
183
184static int __init tsi568_init(void)
185{
186 return rio_register_driver(&tsi568_driver);
187}
188
189static void __exit tsi568_exit(void)
190{
191 rio_unregister_driver(&tsi568_driver);
192}
193
194device_initcall(tsi568_init);
195module_exit(tsi568_exit);
196
197MODULE_DESCRIPTION("IDT Tsi568 Serial RapidIO switch driver");
198MODULE_AUTHOR("Integrated Device Technology, Inc.");
199MODULE_LICENSE("GPL");
diff --git a/drivers/rapidio/switches/tsi57x.c b/drivers/rapidio/switches/tsi57x.c
index db8b8028988d..42c8b014fe15 100644
--- a/drivers/rapidio/switches/tsi57x.c
+++ b/drivers/rapidio/switches/tsi57x.c
@@ -19,6 +19,7 @@
19#include <linux/rio_drv.h> 19#include <linux/rio_drv.h>
20#include <linux/rio_ids.h> 20#include <linux/rio_ids.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/module.h>
22#include "../rio.h" 23#include "../rio.h"
23 24
24/* Global (broadcast) route registers */ 25/* Global (broadcast) route registers */
@@ -292,27 +293,79 @@ exit_es:
292 return 0; 293 return 0;
293} 294}
294 295
295static int tsi57x_switch_init(struct rio_dev *rdev, int do_enum) 296static struct rio_switch_ops tsi57x_switch_ops = {
297 .owner = THIS_MODULE,
298 .add_entry = tsi57x_route_add_entry,
299 .get_entry = tsi57x_route_get_entry,
300 .clr_table = tsi57x_route_clr_table,
301 .set_domain = tsi57x_set_domain,
302 .get_domain = tsi57x_get_domain,
303 .em_init = tsi57x_em_init,
304 .em_handle = tsi57x_em_handler,
305};
306
307static int tsi57x_probe(struct rio_dev *rdev, const struct rio_device_id *id)
296{ 308{
297 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev)); 309 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
298 rdev->rswitch->add_entry = tsi57x_route_add_entry; 310
299 rdev->rswitch->get_entry = tsi57x_route_get_entry; 311 spin_lock(&rdev->rswitch->lock);
300 rdev->rswitch->clr_table = tsi57x_route_clr_table; 312
301 rdev->rswitch->set_domain = tsi57x_set_domain; 313 if (rdev->rswitch->ops) {
302 rdev->rswitch->get_domain = tsi57x_get_domain; 314 spin_unlock(&rdev->rswitch->lock);
303 rdev->rswitch->em_init = tsi57x_em_init; 315 return -EINVAL;
304 rdev->rswitch->em_handle = tsi57x_em_handler; 316 }
305 317 rdev->rswitch->ops = &tsi57x_switch_ops;
306 if (do_enum) { 318
319 if (rdev->do_enum) {
307 /* Ensure that default routing is disabled on startup */ 320 /* Ensure that default routing is disabled on startup */
308 rio_write_config_32(rdev, RIO_STD_RTE_DEFAULT_PORT, 321 rio_write_config_32(rdev, RIO_STD_RTE_DEFAULT_PORT,
309 RIO_INVALID_ROUTE); 322 RIO_INVALID_ROUTE);
310 } 323 }
311 324
325 spin_unlock(&rdev->rswitch->lock);
312 return 0; 326 return 0;
313} 327}
314 328
315DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI572, tsi57x_switch_init); 329static void tsi57x_remove(struct rio_dev *rdev)
316DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI574, tsi57x_switch_init); 330{
317DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI577, tsi57x_switch_init); 331 pr_debug("RIO: %s for %s\n", __func__, rio_name(rdev));
318DECLARE_RIO_SWITCH_INIT(RIO_VID_TUNDRA, RIO_DID_TSI578, tsi57x_switch_init); 332 spin_lock(&rdev->rswitch->lock);
333 if (rdev->rswitch->ops != &tsi57x_switch_ops) {
334 spin_unlock(&rdev->rswitch->lock);
335 return;
336 }
337 rdev->rswitch->ops = NULL;
338 spin_unlock(&rdev->rswitch->lock);
339}
340
341static struct rio_device_id tsi57x_id_table[] = {
342 {RIO_DEVICE(RIO_DID_TSI572, RIO_VID_TUNDRA)},
343 {RIO_DEVICE(RIO_DID_TSI574, RIO_VID_TUNDRA)},
344 {RIO_DEVICE(RIO_DID_TSI577, RIO_VID_TUNDRA)},
345 {RIO_DEVICE(RIO_DID_TSI578, RIO_VID_TUNDRA)},
346 { 0, } /* terminate list */
347};
348
349static struct rio_driver tsi57x_driver = {
350 .name = "tsi57x",
351 .id_table = tsi57x_id_table,
352 .probe = tsi57x_probe,
353 .remove = tsi57x_remove,
354};
355
356static int __init tsi57x_init(void)
357{
358 return rio_register_driver(&tsi57x_driver);
359}
360
361static void __exit tsi57x_exit(void)
362{
363 rio_unregister_driver(&tsi57x_driver);
364}
365
366device_initcall(tsi57x_init);
367module_exit(tsi57x_exit);
368
369MODULE_DESCRIPTION("IDT Tsi57x Serial RapidIO switch family driver");
370MODULE_AUTHOR("Integrated Device Technology, Inc.");
371MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/Kconfig b/drivers/rtc/Kconfig
index b9838130a7b0..9e3498bf302b 100644
--- a/drivers/rtc/Kconfig
+++ b/drivers/rtc/Kconfig
@@ -313,6 +313,15 @@ config RTC_DRV_PALMAS
313 This driver can also be built as a module. If so, the module 313 This driver can also be built as a module. If so, the module
314 will be called rtc-palma. 314 will be called rtc-palma.
315 315
316config RTC_DRV_PCF2127
317 tristate "NXP PCF2127"
318 help
319 If you say yes here you get support for the NXP PCF2127/29 RTC
320 chips.
321
322 This driver can also be built as a module. If so, the module
323 will be called rtc-pcf2127.
324
316config RTC_DRV_PCF8523 325config RTC_DRV_PCF8523
317 tristate "NXP PCF8523" 326 tristate "NXP PCF8523"
318 help 327 help
@@ -1233,6 +1242,13 @@ config RTC_DRV_SNVS
1233 This driver can also be built as a module, if so, the module 1242 This driver can also be built as a module, if so, the module
1234 will be called "rtc-snvs". 1243 will be called "rtc-snvs".
1235 1244
1245config RTC_DRV_SIRFSOC
1246 tristate "SiRFSOC RTC"
1247 depends on ARCH_SIRF
1248 help
1249 Say "yes" here to support the real time clock on SiRF SOC chips.
1250 This driver can also be built as a module called rtc-sirfsoc.
1251
1236comment "HID Sensor RTC drivers" 1252comment "HID Sensor RTC drivers"
1237 1253
1238config RTC_DRV_HID_SENSOR_TIME 1254config RTC_DRV_HID_SENSOR_TIME
diff --git a/drivers/rtc/Makefile b/drivers/rtc/Makefile
index c33f86f1a69b..d3b4488f48f2 100644
--- a/drivers/rtc/Makefile
+++ b/drivers/rtc/Makefile
@@ -83,6 +83,7 @@ obj-$(CONFIG_RTC_DRV_NUC900) += rtc-nuc900.o
83obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o 83obj-$(CONFIG_RTC_DRV_OMAP) += rtc-omap.o
84obj-$(CONFIG_RTC_DRV_PALMAS) += rtc-palmas.o 84obj-$(CONFIG_RTC_DRV_PALMAS) += rtc-palmas.o
85obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o 85obj-$(CONFIG_RTC_DRV_PCAP) += rtc-pcap.o
86obj-$(CONFIG_RTC_DRV_PCF2127) += rtc-pcf2127.o
86obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o 87obj-$(CONFIG_RTC_DRV_PCF8523) += rtc-pcf8523.o
87obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o 88obj-$(CONFIG_RTC_DRV_PCF8563) += rtc-pcf8563.o
88obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o 89obj-$(CONFIG_RTC_DRV_PCF8583) += rtc-pcf8583.o
@@ -128,3 +129,4 @@ obj-$(CONFIG_RTC_DRV_VT8500) += rtc-vt8500.o
128obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o 129obj-$(CONFIG_RTC_DRV_WM831X) += rtc-wm831x.o
129obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o 130obj-$(CONFIG_RTC_DRV_WM8350) += rtc-wm8350.o
130obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o 131obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
132obj-$(CONFIG_RTC_DRV_SIRFSOC) += rtc-sirfsoc.o
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 66385402d20e..02426812bebc 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -38,7 +38,7 @@ static void rtc_device_release(struct device *dev)
38int rtc_hctosys_ret = -ENODEV; 38int rtc_hctosys_ret = -ENODEV;
39#endif 39#endif
40 40
41#if defined(CONFIG_PM) && defined(CONFIG_RTC_HCTOSYS_DEVICE) 41#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_RTC_HCTOSYS_DEVICE)
42/* 42/*
43 * On suspend(), measure the delta between one RTC and the 43 * On suspend(), measure the delta between one RTC and the
44 * system's wall clock; restore it on resume(). 44 * system's wall clock; restore it on resume().
@@ -47,7 +47,7 @@ int rtc_hctosys_ret = -ENODEV;
47static struct timespec old_rtc, old_system, old_delta; 47static struct timespec old_rtc, old_system, old_delta;
48 48
49 49
50static int rtc_suspend(struct device *dev, pm_message_t mesg) 50static int rtc_suspend(struct device *dev)
51{ 51{
52 struct rtc_device *rtc = to_rtc_device(dev); 52 struct rtc_device *rtc = to_rtc_device(dev);
53 struct rtc_time tm; 53 struct rtc_time tm;
@@ -135,9 +135,10 @@ static int rtc_resume(struct device *dev)
135 return 0; 135 return 0;
136} 136}
137 137
138static SIMPLE_DEV_PM_OPS(rtc_class_dev_pm_ops, rtc_suspend, rtc_resume);
139#define RTC_CLASS_DEV_PM_OPS (&rtc_class_dev_pm_ops)
138#else 140#else
139#define rtc_suspend NULL 141#define RTC_CLASS_DEV_PM_OPS NULL
140#define rtc_resume NULL
141#endif 142#endif
142 143
143 144
@@ -336,8 +337,7 @@ static int __init rtc_init(void)
336 pr_err("couldn't create class\n"); 337 pr_err("couldn't create class\n");
337 return PTR_ERR(rtc_class); 338 return PTR_ERR(rtc_class);
338 } 339 }
339 rtc_class->suspend = rtc_suspend; 340 rtc_class->pm = RTC_CLASS_DEV_PM_OPS;
340 rtc_class->resume = rtc_resume;
341 rtc_dev_init(); 341 rtc_dev_init();
342 rtc_sysfs_init(rtc_class); 342 rtc_sysfs_init(rtc_class);
343 return 0; 343 return 0;
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index 42bd57da239d..72c5cdbe0791 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -109,9 +109,9 @@ int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
109 err = rtc->ops->set_time(rtc->dev.parent, 109 err = rtc->ops->set_time(rtc->dev.parent,
110 &new); 110 &new);
111 } 111 }
112 } 112 } else {
113 else
114 err = -EINVAL; 113 err = -EINVAL;
114 }
115 115
116 mutex_unlock(&rtc->ops_lock); 116 mutex_unlock(&rtc->ops_lock);
117 /* A timer might have just expired */ 117 /* A timer might have just expired */
@@ -367,14 +367,14 @@ int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
367 err = mutex_lock_interruptible(&rtc->ops_lock); 367 err = mutex_lock_interruptible(&rtc->ops_lock);
368 if (err) 368 if (err)
369 return err; 369 return err;
370 if (rtc->aie_timer.enabled) { 370 if (rtc->aie_timer.enabled)
371 rtc_timer_remove(rtc, &rtc->aie_timer); 371 rtc_timer_remove(rtc, &rtc->aie_timer);
372 } 372
373 rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time); 373 rtc->aie_timer.node.expires = rtc_tm_to_ktime(alarm->time);
374 rtc->aie_timer.period = ktime_set(0, 0); 374 rtc->aie_timer.period = ktime_set(0, 0);
375 if (alarm->enabled) { 375 if (alarm->enabled)
376 err = rtc_timer_enqueue(rtc, &rtc->aie_timer); 376 err = rtc_timer_enqueue(rtc, &rtc->aie_timer);
377 } 377
378 mutex_unlock(&rtc->ops_lock); 378 mutex_unlock(&rtc->ops_lock);
379 return err; 379 return err;
380} 380}
@@ -698,9 +698,9 @@ retry:
698 spin_lock_irqsave(&rtc->irq_task_lock, flags); 698 spin_lock_irqsave(&rtc->irq_task_lock, flags);
699 if (rtc->irq_task != NULL && task == NULL) 699 if (rtc->irq_task != NULL && task == NULL)
700 err = -EBUSY; 700 err = -EBUSY;
701 if (rtc->irq_task != task) 701 else if (rtc->irq_task != task)
702 err = -EACCES; 702 err = -EACCES;
703 if (!err) { 703 else {
704 if (rtc_update_hrtimer(rtc, enabled) < 0) { 704 if (rtc_update_hrtimer(rtc, enabled) < 0) {
705 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 705 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
706 cpu_relax(); 706 cpu_relax();
@@ -734,9 +734,9 @@ retry:
734 spin_lock_irqsave(&rtc->irq_task_lock, flags); 734 spin_lock_irqsave(&rtc->irq_task_lock, flags);
735 if (rtc->irq_task != NULL && task == NULL) 735 if (rtc->irq_task != NULL && task == NULL)
736 err = -EBUSY; 736 err = -EBUSY;
737 if (rtc->irq_task != task) 737 else if (rtc->irq_task != task)
738 err = -EACCES; 738 err = -EACCES;
739 if (!err) { 739 else {
740 rtc->irq_freq = freq; 740 rtc->irq_freq = freq;
741 if (rtc->pie_enabled && rtc_update_hrtimer(rtc, 1) < 0) { 741 if (rtc->pie_enabled && rtc_update_hrtimer(rtc, 1) < 0) {
742 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 742 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
@@ -891,7 +891,7 @@ again:
891 * 891 *
892 * Kernel interface to initializing an rtc_timer. 892 * Kernel interface to initializing an rtc_timer.
893 */ 893 */
894void rtc_timer_init(struct rtc_timer *timer, void (*f)(void* p), void* data) 894void rtc_timer_init(struct rtc_timer *timer, void (*f)(void *p), void *data)
895{ 895{
896 timerqueue_init(&timer->node); 896 timerqueue_init(&timer->node);
897 timer->enabled = 0; 897 timer->enabled = 0;
@@ -907,7 +907,7 @@ void rtc_timer_init(struct rtc_timer *timer, void (*f)(void* p), void* data)
907 * 907 *
908 * Kernel interface to set an rtc_timer 908 * Kernel interface to set an rtc_timer
909 */ 909 */
910int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer* timer, 910int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer *timer,
911 ktime_t expires, ktime_t period) 911 ktime_t expires, ktime_t period)
912{ 912{
913 int ret = 0; 913 int ret = 0;
@@ -930,7 +930,7 @@ int rtc_timer_start(struct rtc_device *rtc, struct rtc_timer* timer,
930 * 930 *
931 * Kernel interface to cancel an rtc_timer 931 * Kernel interface to cancel an rtc_timer
932 */ 932 */
933int rtc_timer_cancel(struct rtc_device *rtc, struct rtc_timer* timer) 933int rtc_timer_cancel(struct rtc_device *rtc, struct rtc_timer *timer)
934{ 934{
935 int ret = 0; 935 int ret = 0;
936 mutex_lock(&rtc->ops_lock); 936 mutex_lock(&rtc->ops_lock);
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c
index f3742f364eb8..354c937a5866 100644
--- a/drivers/rtc/rtc-88pm80x.c
+++ b/drivers/rtc/rtc-88pm80x.c
@@ -345,7 +345,6 @@ out:
345static int pm80x_rtc_remove(struct platform_device *pdev) 345static int pm80x_rtc_remove(struct platform_device *pdev)
346{ 346{
347 struct pm80x_rtc_info *info = platform_get_drvdata(pdev); 347 struct pm80x_rtc_info *info = platform_get_drvdata(pdev);
348 platform_set_drvdata(pdev, NULL);
349 pm80x_free_irq(info->chip, info->irq, info); 348 pm80x_free_irq(info->chip, info->irq, info);
350 return 0; 349 return 0;
351} 350}
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index 0f2b91bfee37..4e30c85728e5 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -418,7 +418,6 @@ static int pm860x_rtc_remove(struct platform_device *pdev)
418 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0); 418 pm860x_set_bits(info->i2c, PM8607_MEAS_EN2, MEAS2_VRTC, 0);
419#endif /* VRTC_CALIBRATION */ 419#endif /* VRTC_CALIBRATION */
420 420
421 platform_set_drvdata(pdev, NULL);
422 return 0; 421 return 0;
423} 422}
424 423
diff --git a/drivers/rtc/rtc-ab3100.c b/drivers/rtc/rtc-ab3100.c
index 47a4f2c4d30e..ff435343ba9f 100644
--- a/drivers/rtc/rtc-ab3100.c
+++ b/drivers/rtc/rtc-ab3100.c
@@ -240,18 +240,11 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
240 return 0; 240 return 0;
241} 241}
242 242
243static int __exit ab3100_rtc_remove(struct platform_device *pdev)
244{
245 platform_set_drvdata(pdev, NULL);
246 return 0;
247}
248
249static struct platform_driver ab3100_rtc_driver = { 243static struct platform_driver ab3100_rtc_driver = {
250 .driver = { 244 .driver = {
251 .name = "ab3100-rtc", 245 .name = "ab3100-rtc",
252 .owner = THIS_MODULE, 246 .owner = THIS_MODULE,
253 }, 247 },
254 .remove = __exit_p(ab3100_rtc_remove),
255}; 248};
256 249
257module_platform_driver_probe(ab3100_rtc_driver, ab3100_rtc_probe); 250module_platform_driver_probe(ab3100_rtc_driver, ab3100_rtc_probe);
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index 63cfa314a39f..727e2f5d14d9 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -35,6 +35,10 @@
35#define AB8500_RTC_FORCE_BKUP_REG 0x0D 35#define AB8500_RTC_FORCE_BKUP_REG 0x0D
36#define AB8500_RTC_CALIB_REG 0x0E 36#define AB8500_RTC_CALIB_REG 0x0E
37#define AB8500_RTC_SWITCH_STAT_REG 0x0F 37#define AB8500_RTC_SWITCH_STAT_REG 0x0F
38#define AB8540_RTC_ALRM_SEC 0x22
39#define AB8540_RTC_ALRM_MIN_LOW_REG 0x23
40#define AB8540_RTC_ALRM_MIN_MID_REG 0x24
41#define AB8540_RTC_ALRM_MIN_HI_REG 0x25
38 42
39/* RtcReadRequest bits */ 43/* RtcReadRequest bits */
40#define RTC_READ_REQUEST 0x01 44#define RTC_READ_REQUEST 0x01
@@ -58,6 +62,11 @@ static const u8 ab8500_rtc_alarm_regs[] = {
58 AB8500_RTC_ALRM_MIN_LOW_REG 62 AB8500_RTC_ALRM_MIN_LOW_REG
59}; 63};
60 64
65static const u8 ab8540_rtc_alarm_regs[] = {
66 AB8540_RTC_ALRM_MIN_HI_REG, AB8540_RTC_ALRM_MIN_MID_REG,
67 AB8540_RTC_ALRM_MIN_LOW_REG, AB8540_RTC_ALRM_SEC
68};
69
61/* Calculate the seconds from 1970 to 01-01-2000 00:00:00 */ 70/* Calculate the seconds from 1970 to 01-01-2000 00:00:00 */
62static unsigned long get_elapsed_seconds(int year) 71static unsigned long get_elapsed_seconds(int year)
63{ 72{
@@ -267,6 +276,42 @@ static int ab8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
267 return ab8500_rtc_irq_enable(dev, alarm->enabled); 276 return ab8500_rtc_irq_enable(dev, alarm->enabled);
268} 277}
269 278
279static int ab8540_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alarm)
280{
281 int retval, i;
282 unsigned char buf[ARRAY_SIZE(ab8540_rtc_alarm_regs)];
283 unsigned long mins, secs = 0;
284
285 if (alarm->time.tm_year < (AB8500_RTC_EPOCH - 1900)) {
286 dev_dbg(dev, "year should be equal to or greater than %d\n",
287 AB8500_RTC_EPOCH);
288 return -EINVAL;
289 }
290
291 /* Get the number of seconds since 1970 */
292 rtc_tm_to_time(&alarm->time, &secs);
293
294 /*
295 * Convert it to the number of seconds since 01-01-2000 00:00:00
296 */
297 secs -= get_elapsed_seconds(AB8500_RTC_EPOCH);
298 mins = secs / 60;
299
300 buf[3] = secs % 60;
301 buf[2] = mins & 0xFF;
302 buf[1] = (mins >> 8) & 0xFF;
303 buf[0] = (mins >> 16) & 0xFF;
304
305 /* Set the alarm time */
306 for (i = 0; i < ARRAY_SIZE(ab8540_rtc_alarm_regs); i++) {
307 retval = abx500_set_register_interruptible(dev, AB8500_RTC,
308 ab8540_rtc_alarm_regs[i], buf[i]);
309 if (retval < 0)
310 return retval;
311 }
312
313 return ab8500_rtc_irq_enable(dev, alarm->enabled);
314}
270 315
271static int ab8500_rtc_set_calibration(struct device *dev, int calibration) 316static int ab8500_rtc_set_calibration(struct device *dev, int calibration)
272{ 317{
@@ -389,8 +434,22 @@ static const struct rtc_class_ops ab8500_rtc_ops = {
389 .alarm_irq_enable = ab8500_rtc_irq_enable, 434 .alarm_irq_enable = ab8500_rtc_irq_enable,
390}; 435};
391 436
437static const struct rtc_class_ops ab8540_rtc_ops = {
438 .read_time = ab8500_rtc_read_time,
439 .set_time = ab8500_rtc_set_time,
440 .read_alarm = ab8500_rtc_read_alarm,
441 .set_alarm = ab8540_rtc_set_alarm,
442 .alarm_irq_enable = ab8500_rtc_irq_enable,
443};
444
445static struct platform_device_id ab85xx_rtc_ids[] = {
446 { "ab8500-rtc", (kernel_ulong_t)&ab8500_rtc_ops, },
447 { "ab8540-rtc", (kernel_ulong_t)&ab8540_rtc_ops, },
448};
449
392static int ab8500_rtc_probe(struct platform_device *pdev) 450static int ab8500_rtc_probe(struct platform_device *pdev)
393{ 451{
452 const struct platform_device_id *platid = platform_get_device_id(pdev);
394 int err; 453 int err;
395 struct rtc_device *rtc; 454 struct rtc_device *rtc;
396 u8 rtc_ctrl; 455 u8 rtc_ctrl;
@@ -423,7 +482,8 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
423 device_init_wakeup(&pdev->dev, true); 482 device_init_wakeup(&pdev->dev, true);
424 483
425 rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc", 484 rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc",
426 &ab8500_rtc_ops, THIS_MODULE); 485 (struct rtc_class_ops *)platid->driver_data,
486 THIS_MODULE);
427 if (IS_ERR(rtc)) { 487 if (IS_ERR(rtc)) {
428 dev_err(&pdev->dev, "Registration failed\n"); 488 dev_err(&pdev->dev, "Registration failed\n");
429 err = PTR_ERR(rtc); 489 err = PTR_ERR(rtc);
@@ -451,8 +511,6 @@ static int ab8500_rtc_remove(struct platform_device *pdev)
451{ 511{
452 ab8500_sysfs_rtc_unregister(&pdev->dev); 512 ab8500_sysfs_rtc_unregister(&pdev->dev);
453 513
454 platform_set_drvdata(pdev, NULL);
455
456 return 0; 514 return 0;
457} 515}
458 516
@@ -463,6 +521,7 @@ static struct platform_driver ab8500_rtc_driver = {
463 }, 521 },
464 .probe = ab8500_rtc_probe, 522 .probe = ab8500_rtc_probe,
465 .remove = ab8500_rtc_remove, 523 .remove = ab8500_rtc_remove,
524 .id_table = ab85xx_rtc_ids,
466}; 525};
467 526
468module_platform_driver(ab8500_rtc_driver); 527module_platform_driver(ab8500_rtc_driver);
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c
index f47fbb5eee8b..3161ab5263ed 100644
--- a/drivers/rtc/rtc-at32ap700x.c
+++ b/drivers/rtc/rtc-at32ap700x.c
@@ -141,7 +141,7 @@ static int at32_rtc_alarm_irq_enable(struct device *dev, unsigned int enabled)
141 141
142 spin_lock_irq(&rtc->lock); 142 spin_lock_irq(&rtc->lock);
143 143
144 if(enabled) { 144 if (enabled) {
145 if (rtc_readl(rtc, VAL) > rtc->alarm_time) { 145 if (rtc_readl(rtc, VAL) > rtc->alarm_time) {
146 ret = -EINVAL; 146 ret = -EINVAL;
147 goto out; 147 goto out;
@@ -212,23 +212,20 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
212 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0); 212 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
213 if (!regs) { 213 if (!regs) {
214 dev_dbg(&pdev->dev, "no mmio resource defined\n"); 214 dev_dbg(&pdev->dev, "no mmio resource defined\n");
215 ret = -ENXIO; 215 return -ENXIO;
216 goto out;
217 } 216 }
218 217
219 irq = platform_get_irq(pdev, 0); 218 irq = platform_get_irq(pdev, 0);
220 if (irq <= 0) { 219 if (irq <= 0) {
221 dev_dbg(&pdev->dev, "could not get irq\n"); 220 dev_dbg(&pdev->dev, "could not get irq\n");
222 ret = -ENXIO; 221 return -ENXIO;
223 goto out;
224 } 222 }
225 223
226 rtc->irq = irq; 224 rtc->irq = irq;
227 rtc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs)); 225 rtc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
228 if (!rtc->regs) { 226 if (!rtc->regs) {
229 ret = -ENOMEM;
230 dev_dbg(&pdev->dev, "could not map I/O memory\n"); 227 dev_dbg(&pdev->dev, "could not map I/O memory\n");
231 goto out; 228 return -ENOMEM;
232 } 229 }
233 spin_lock_init(&rtc->lock); 230 spin_lock_init(&rtc->lock);
234 231
@@ -249,7 +246,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
249 "rtc", rtc); 246 "rtc", rtc);
250 if (ret) { 247 if (ret) {
251 dev_dbg(&pdev->dev, "could not request irq %d\n", irq); 248 dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
252 goto out; 249 return ret;
253 } 250 }
254 251
255 platform_set_drvdata(pdev, rtc); 252 platform_set_drvdata(pdev, rtc);
@@ -258,8 +255,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
258 &at32_rtc_ops, THIS_MODULE); 255 &at32_rtc_ops, THIS_MODULE);
259 if (IS_ERR(rtc->rtc)) { 256 if (IS_ERR(rtc->rtc)) {
260 dev_dbg(&pdev->dev, "could not register rtc device\n"); 257 dev_dbg(&pdev->dev, "could not register rtc device\n");
261 ret = PTR_ERR(rtc->rtc); 258 return PTR_ERR(rtc->rtc);
262 goto out;
263 } 259 }
264 260
265 device_init_wakeup(&pdev->dev, 1); 261 device_init_wakeup(&pdev->dev, 1);
@@ -268,18 +264,12 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
268 (unsigned long)rtc->regs, rtc->irq); 264 (unsigned long)rtc->regs, rtc->irq);
269 265
270 return 0; 266 return 0;
271
272out:
273 platform_set_drvdata(pdev, NULL);
274 return ret;
275} 267}
276 268
277static int __exit at32_rtc_remove(struct platform_device *pdev) 269static int __exit at32_rtc_remove(struct platform_device *pdev)
278{ 270{
279 device_init_wakeup(&pdev->dev, 0); 271 device_init_wakeup(&pdev->dev, 0);
280 272
281 platform_set_drvdata(pdev, NULL);
282
283 return 0; 273 return 0;
284} 274}
285 275
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index f296f3f7db9b..741892632ae0 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -31,8 +31,7 @@
31#include <linux/io.h> 31#include <linux/io.h>
32#include <linux/of.h> 32#include <linux/of.h>
33#include <linux/of_device.h> 33#include <linux/of_device.h>
34 34#include <linux/uaccess.h>
35#include <asm/uaccess.h>
36 35
37#include "rtc-at91rm9200.h" 36#include "rtc-at91rm9200.h"
38 37
@@ -439,7 +438,6 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
439 438
440 rtc_device_unregister(rtc); 439 rtc_device_unregister(rtc);
441 iounmap(at91_rtc_regs); 440 iounmap(at91_rtc_regs);
442 platform_set_drvdata(pdev, NULL);
443 441
444 return 0; 442 return 0;
445} 443}
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index b60a34cb145a..309b8b342d9c 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -324,16 +324,14 @@ static int at91_rtc_probe(struct platform_device *pdev)
324 rtc->rtt = devm_ioremap(&pdev->dev, r->start, resource_size(r)); 324 rtc->rtt = devm_ioremap(&pdev->dev, r->start, resource_size(r));
325 if (!rtc->rtt) { 325 if (!rtc->rtt) {
326 dev_err(&pdev->dev, "failed to map registers, aborting.\n"); 326 dev_err(&pdev->dev, "failed to map registers, aborting.\n");
327 ret = -ENOMEM; 327 return -ENOMEM;
328 goto fail;
329 } 328 }
330 329
331 rtc->gpbr = devm_ioremap(&pdev->dev, r_gpbr->start, 330 rtc->gpbr = devm_ioremap(&pdev->dev, r_gpbr->start,
332 resource_size(r_gpbr)); 331 resource_size(r_gpbr));
333 if (!rtc->gpbr) { 332 if (!rtc->gpbr) {
334 dev_err(&pdev->dev, "failed to map gpbr registers, aborting.\n"); 333 dev_err(&pdev->dev, "failed to map gpbr registers, aborting.\n");
335 ret = -ENOMEM; 334 return -ENOMEM;
336 goto fail;
337 } 335 }
338 336
339 mr = rtt_readl(rtc, MR); 337 mr = rtt_readl(rtc, MR);
@@ -350,17 +348,15 @@ static int at91_rtc_probe(struct platform_device *pdev)
350 348
351 rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name, 349 rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
352 &at91_rtc_ops, THIS_MODULE); 350 &at91_rtc_ops, THIS_MODULE);
353 if (IS_ERR(rtc->rtcdev)) { 351 if (IS_ERR(rtc->rtcdev))
354 ret = PTR_ERR(rtc->rtcdev); 352 return PTR_ERR(rtc->rtcdev);
355 goto fail;
356 }
357 353
358 /* register irq handler after we know what name we'll use */ 354 /* register irq handler after we know what name we'll use */
359 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt, 355 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
360 IRQF_SHARED, dev_name(&rtc->rtcdev->dev), rtc); 356 IRQF_SHARED, dev_name(&rtc->rtcdev->dev), rtc);
361 if (ret) { 357 if (ret) {
362 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); 358 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
363 goto fail; 359 return ret;
364 } 360 }
365 361
366 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the 362 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the
@@ -374,10 +370,6 @@ static int at91_rtc_probe(struct platform_device *pdev)
374 dev_name(&rtc->rtcdev->dev)); 370 dev_name(&rtc->rtcdev->dev));
375 371
376 return 0; 372 return 0;
377
378fail:
379 platform_set_drvdata(pdev, NULL);
380 return ret;
381} 373}
382 374
383/* 375/*
@@ -391,7 +383,6 @@ static int at91_rtc_remove(struct platform_device *pdev)
391 /* disable all interrupts */ 383 /* disable all interrupts */
392 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); 384 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
393 385
394 platform_set_drvdata(pdev, NULL);
395 return 0; 386 return 0;
396} 387}
397 388
diff --git a/drivers/rtc/rtc-au1xxx.c b/drivers/rtc/rtc-au1xxx.c
index 7995abc391fc..ed526a192ce0 100644
--- a/drivers/rtc/rtc-au1xxx.c
+++ b/drivers/rtc/rtc-au1xxx.c
@@ -116,19 +116,11 @@ out_err:
116 return ret; 116 return ret;
117} 117}
118 118
119static int au1xtoy_rtc_remove(struct platform_device *pdev)
120{
121 platform_set_drvdata(pdev, NULL);
122
123 return 0;
124}
125
126static struct platform_driver au1xrtc_driver = { 119static struct platform_driver au1xrtc_driver = {
127 .driver = { 120 .driver = {
128 .name = "rtc-au1xxx", 121 .name = "rtc-au1xxx",
129 .owner = THIS_MODULE, 122 .owner = THIS_MODULE,
130 }, 123 },
131 .remove = au1xtoy_rtc_remove,
132}; 124};
133 125
134module_platform_driver_probe(au1xrtc_driver, au1xtoy_rtc_probe); 126module_platform_driver_probe(au1xrtc_driver, au1xtoy_rtc_probe);
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index ad44ec5dc29a..0c53f452849d 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -391,7 +391,6 @@ static int bfin_rtc_remove(struct platform_device *pdev)
391 struct device *dev = &pdev->dev; 391 struct device *dev = &pdev->dev;
392 392
393 bfin_rtc_reset(dev, 0); 393 bfin_rtc_reset(dev, 0);
394 platform_set_drvdata(pdev, NULL);
395 394
396 return 0; 395 return 0;
397} 396}
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index fea78bc713ca..c74bf0dc52cc 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -163,11 +163,6 @@ static int bq32k_probe(struct i2c_client *client,
163 return 0; 163 return 0;
164} 164}
165 165
166static int bq32k_remove(struct i2c_client *client)
167{
168 return 0;
169}
170
171static const struct i2c_device_id bq32k_id[] = { 166static const struct i2c_device_id bq32k_id[] = {
172 { "bq32000", 0 }, 167 { "bq32000", 0 },
173 { } 168 { }
@@ -180,7 +175,6 @@ static struct i2c_driver bq32k_driver = {
180 .owner = THIS_MODULE, 175 .owner = THIS_MODULE,
181 }, 176 },
182 .probe = bq32k_probe, 177 .probe = bq32k_probe,
183 .remove = bq32k_remove,
184 .id_table = bq32k_id, 178 .id_table = bq32k_id,
185}; 179};
186 180
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index af2886784a7b..fc0ff87aa5df 100644
--- a/drivers/rtc/rtc-bq4802.c
+++ b/drivers/rtc/rtc-bq4802.c
@@ -186,13 +186,6 @@ out:
186 186
187} 187}
188 188
189static int bq4802_remove(struct platform_device *pdev)
190{
191 platform_set_drvdata(pdev, NULL);
192
193 return 0;
194}
195
196/* work with hotplug and coldplug */ 189/* work with hotplug and coldplug */
197MODULE_ALIAS("platform:rtc-bq4802"); 190MODULE_ALIAS("platform:rtc-bq4802");
198 191
@@ -202,7 +195,6 @@ static struct platform_driver bq4802_driver = {
202 .owner = THIS_MODULE, 195 .owner = THIS_MODULE,
203 }, 196 },
204 .probe = bq4802_probe, 197 .probe = bq4802_probe,
205 .remove = bq4802_remove,
206}; 198};
207 199
208module_platform_driver(bq4802_driver); 200module_platform_driver(bq4802_driver);
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index f1cb706445c7..be06d7150de5 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -326,7 +326,7 @@ static void cmos_irq_disable(struct cmos_rtc *cmos, unsigned char mask)
326static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t) 326static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
327{ 327{
328 struct cmos_rtc *cmos = dev_get_drvdata(dev); 328 struct cmos_rtc *cmos = dev_get_drvdata(dev);
329 unsigned char mon, mday, hrs, min, sec, rtc_control; 329 unsigned char mon, mday, hrs, min, sec, rtc_control;
330 330
331 if (!is_valid_irq(cmos->irq)) 331 if (!is_valid_irq(cmos->irq))
332 return -EIO; 332 return -EIO;
@@ -556,17 +556,24 @@ static irqreturn_t cmos_interrupt(int irq, void *p)
556 rtc_control = CMOS_READ(RTC_CONTROL); 556 rtc_control = CMOS_READ(RTC_CONTROL);
557 if (is_hpet_enabled()) 557 if (is_hpet_enabled())
558 irqstat = (unsigned long)irq & 0xF0; 558 irqstat = (unsigned long)irq & 0xF0;
559 irqstat &= (rtc_control & RTC_IRQMASK) | RTC_IRQF; 559
560 /* If we were suspended, RTC_CONTROL may not be accurate since the
561 * bios may have cleared it.
562 */
563 if (!cmos_rtc.suspend_ctrl)
564 irqstat &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
565 else
566 irqstat &= (cmos_rtc.suspend_ctrl & RTC_IRQMASK) | RTC_IRQF;
560 567
561 /* All Linux RTC alarms should be treated as if they were oneshot. 568 /* All Linux RTC alarms should be treated as if they were oneshot.
562 * Similar code may be needed in system wakeup paths, in case the 569 * Similar code may be needed in system wakeup paths, in case the
563 * alarm woke the system. 570 * alarm woke the system.
564 */ 571 */
565 if (irqstat & RTC_AIE) { 572 if (irqstat & RTC_AIE) {
573 cmos_rtc.suspend_ctrl &= ~RTC_AIE;
566 rtc_control &= ~RTC_AIE; 574 rtc_control &= ~RTC_AIE;
567 CMOS_WRITE(rtc_control, RTC_CONTROL); 575 CMOS_WRITE(rtc_control, RTC_CONTROL);
568 hpet_mask_rtc_irq_bit(RTC_AIE); 576 hpet_mask_rtc_irq_bit(RTC_AIE);
569
570 CMOS_READ(RTC_INTR_FLAGS); 577 CMOS_READ(RTC_INTR_FLAGS);
571 } 578 }
572 spin_unlock(&rtc_lock); 579 spin_unlock(&rtc_lock);
@@ -691,7 +698,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
691 /* FIXME: 698 /* FIXME:
692 * <asm-generic/rtc.h> doesn't know 12-hour mode either. 699 * <asm-generic/rtc.h> doesn't know 12-hour mode either.
693 */ 700 */
694 if (is_valid_irq(rtc_irq) && !(rtc_control & RTC_24H)) { 701 if (is_valid_irq(rtc_irq) && !(rtc_control & RTC_24H)) {
695 dev_warn(dev, "only 24-hr supported\n"); 702 dev_warn(dev, "only 24-hr supported\n");
696 retval = -ENXIO; 703 retval = -ENXIO;
697 goto cleanup1; 704 goto cleanup1;
@@ -839,21 +846,23 @@ static inline int cmos_poweroff(struct device *dev)
839static int cmos_resume(struct device *dev) 846static int cmos_resume(struct device *dev)
840{ 847{
841 struct cmos_rtc *cmos = dev_get_drvdata(dev); 848 struct cmos_rtc *cmos = dev_get_drvdata(dev);
842 unsigned char tmp = cmos->suspend_ctrl; 849 unsigned char tmp;
850
851 if (cmos->enabled_wake) {
852 if (cmos->wake_off)
853 cmos->wake_off(dev);
854 else
855 disable_irq_wake(cmos->irq);
856 cmos->enabled_wake = 0;
857 }
843 858
859 spin_lock_irq(&rtc_lock);
860 tmp = cmos->suspend_ctrl;
861 cmos->suspend_ctrl = 0;
844 /* re-enable any irqs previously active */ 862 /* re-enable any irqs previously active */
845 if (tmp & RTC_IRQMASK) { 863 if (tmp & RTC_IRQMASK) {
846 unsigned char mask; 864 unsigned char mask;
847 865
848 if (cmos->enabled_wake) {
849 if (cmos->wake_off)
850 cmos->wake_off(dev);
851 else
852 disable_irq_wake(cmos->irq);
853 cmos->enabled_wake = 0;
854 }
855
856 spin_lock_irq(&rtc_lock);
857 if (device_may_wakeup(dev)) 866 if (device_may_wakeup(dev))
858 hpet_rtc_timer_init(); 867 hpet_rtc_timer_init();
859 868
@@ -873,8 +882,8 @@ static int cmos_resume(struct device *dev)
873 tmp &= ~RTC_AIE; 882 tmp &= ~RTC_AIE;
874 hpet_mask_rtc_irq_bit(RTC_AIE); 883 hpet_mask_rtc_irq_bit(RTC_AIE);
875 } while (mask & RTC_AIE); 884 } while (mask & RTC_AIE);
876 spin_unlock_irq(&rtc_lock);
877 } 885 }
886 spin_unlock_irq(&rtc_lock);
878 887
879 dev_dbg(dev, "resume, ctrl %02x\n", tmp); 888 dev_dbg(dev, "resume, ctrl %02x\n", tmp);
880 889
@@ -991,7 +1000,7 @@ static int cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
991{ 1000{
992 cmos_wake_setup(&pnp->dev); 1001 cmos_wake_setup(&pnp->dev);
993 1002
994 if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0)) 1003 if (pnp_port_start(pnp, 0) == 0x70 && !pnp_irq_valid(pnp, 0))
995 /* Some machines contain a PNP entry for the RTC, but 1004 /* Some machines contain a PNP entry for the RTC, but
996 * don't define the IRQ. It should always be safe to 1005 * don't define the IRQ. It should always be safe to
997 * hardcode it in these cases 1006 * hardcode it in these cases
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c
index ad6863a76af9..73f157519dff 100644
--- a/drivers/rtc/rtc-coh901331.c
+++ b/drivers/rtc/rtc-coh901331.c
@@ -152,12 +152,10 @@ static struct rtc_class_ops coh901331_ops = {
152 152
153static int __exit coh901331_remove(struct platform_device *pdev) 153static int __exit coh901331_remove(struct platform_device *pdev)
154{ 154{
155 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 155 struct coh901331_port *rtap = platform_get_drvdata(pdev);
156 156
157 if (rtap) { 157 if (rtap)
158 clk_unprepare(rtap->clk); 158 clk_unprepare(rtap->clk);
159 platform_set_drvdata(pdev, NULL);
160 }
161 159
162 return 0; 160 return 0;
163} 161}
@@ -220,7 +218,6 @@ static int __init coh901331_probe(struct platform_device *pdev)
220 return 0; 218 return 0;
221 219
222 out_no_rtc: 220 out_no_rtc:
223 platform_set_drvdata(pdev, NULL);
224 clk_unprepare(rtap->clk); 221 clk_unprepare(rtap->clk);
225 return ret; 222 return ret;
226} 223}
@@ -267,7 +264,7 @@ static SIMPLE_DEV_PM_OPS(coh901331_pm_ops, coh901331_suspend, coh901331_resume);
267 264
268static void coh901331_shutdown(struct platform_device *pdev) 265static void coh901331_shutdown(struct platform_device *pdev)
269{ 266{
270 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 267 struct coh901331_port *rtap = platform_get_drvdata(pdev);
271 268
272 clk_enable(rtap->clk); 269 clk_enable(rtap->clk);
273 writel(0, rtap->virtbase + COH901331_IRQ_MASK); 270 writel(0, rtap->virtbase + COH901331_IRQ_MASK);
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 7286b279cf2d..9c8c19441cc6 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -15,6 +15,7 @@
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/platform_device.h> 16#include <linux/platform_device.h>
17#include <linux/rtc.h> 17#include <linux/rtc.h>
18#include <linux/err.h>
18 19
19#include <linux/mfd/da9052/da9052.h> 20#include <linux/mfd/da9052/da9052.h>
20#include <linux/mfd/da9052/reg.h> 21#include <linux/mfd/da9052/reg.h>
@@ -249,22 +250,11 @@ static int da9052_rtc_probe(struct platform_device *pdev)
249 250
250 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 251 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
251 &da9052_rtc_ops, THIS_MODULE); 252 &da9052_rtc_ops, THIS_MODULE);
252 if (IS_ERR(rtc->rtc)) 253 return PTR_RET(rtc->rtc);
253 return PTR_ERR(rtc->rtc);
254
255 return 0;
256}
257
258static int da9052_rtc_remove(struct platform_device *pdev)
259{
260 platform_set_drvdata(pdev, NULL);
261
262 return 0;
263} 254}
264 255
265static struct platform_driver da9052_rtc_driver = { 256static struct platform_driver da9052_rtc_driver = {
266 .probe = da9052_rtc_probe, 257 .probe = da9052_rtc_probe,
267 .remove = da9052_rtc_remove,
268 .driver = { 258 .driver = {
269 .name = "da9052-rtc", 259 .name = "da9052-rtc",
270 .owner = THIS_MODULE, 260 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-da9055.c b/drivers/rtc/rtc-da9055.c
index 73858ca9709a..e00642b61076 100644
--- a/drivers/rtc/rtc-da9055.c
+++ b/drivers/rtc/rtc-da9055.c
@@ -315,13 +315,6 @@ err_rtc:
315 315
316} 316}
317 317
318static int da9055_rtc_remove(struct platform_device *pdev)
319{
320 platform_set_drvdata(pdev, NULL);
321
322 return 0;
323}
324
325#ifdef CONFIG_PM 318#ifdef CONFIG_PM
326/* Turn off the alarm if it should not be a wake source. */ 319/* Turn off the alarm if it should not be a wake source. */
327static int da9055_rtc_suspend(struct device *dev) 320static int da9055_rtc_suspend(struct device *dev)
@@ -394,7 +387,6 @@ static const struct dev_pm_ops da9055_rtc_pm_ops = {
394 387
395static struct platform_driver da9055_rtc_driver = { 388static struct platform_driver da9055_rtc_driver = {
396 .probe = da9055_rtc_probe, 389 .probe = da9055_rtc_probe,
397 .remove = da9055_rtc_remove,
398 .driver = { 390 .driver = {
399 .name = "da9055-rtc", 391 .name = "da9055-rtc",
400 .owner = THIS_MODULE, 392 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-davinci.c b/drivers/rtc/rtc-davinci.c
index a55048c3e26f..24677ef8c39a 100644
--- a/drivers/rtc/rtc-davinci.c
+++ b/drivers/rtc/rtc-davinci.c
@@ -117,7 +117,7 @@
117static DEFINE_SPINLOCK(davinci_rtc_lock); 117static DEFINE_SPINLOCK(davinci_rtc_lock);
118 118
119struct davinci_rtc { 119struct davinci_rtc {
120 struct rtc_device *rtc; 120 struct rtc_device *rtc;
121 void __iomem *base; 121 void __iomem *base;
122 resource_size_t pbase; 122 resource_size_t pbase;
123 size_t base_size; 123 size_t base_size;
@@ -526,10 +526,9 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
526 davinci_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 526 davinci_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
527 &davinci_rtc_ops, THIS_MODULE); 527 &davinci_rtc_ops, THIS_MODULE);
528 if (IS_ERR(davinci_rtc->rtc)) { 528 if (IS_ERR(davinci_rtc->rtc)) {
529 ret = PTR_ERR(davinci_rtc->rtc);
530 dev_err(dev, "unable to register RTC device, err %d\n", 529 dev_err(dev, "unable to register RTC device, err %d\n",
531 ret); 530 ret);
532 goto fail1; 531 return PTR_ERR(davinci_rtc->rtc);
533 } 532 }
534 533
535 rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG); 534 rtcif_write(davinci_rtc, PRTCIF_INTFLG_RTCSS, PRTCIF_INTFLG);
@@ -543,7 +542,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
543 0, "davinci_rtc", davinci_rtc); 542 0, "davinci_rtc", davinci_rtc);
544 if (ret < 0) { 543 if (ret < 0) {
545 dev_err(dev, "unable to register davinci RTC interrupt\n"); 544 dev_err(dev, "unable to register davinci RTC interrupt\n");
546 goto fail1; 545 return ret;
547 } 546 }
548 547
549 /* Enable interrupts */ 548 /* Enable interrupts */
@@ -556,10 +555,6 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
556 device_init_wakeup(&pdev->dev, 0); 555 device_init_wakeup(&pdev->dev, 0);
557 556
558 return 0; 557 return 0;
559
560fail1:
561 platform_set_drvdata(pdev, NULL);
562 return ret;
563} 558}
564 559
565static int __exit davinci_rtc_remove(struct platform_device *pdev) 560static int __exit davinci_rtc_remove(struct platform_device *pdev)
@@ -570,8 +565,6 @@ static int __exit davinci_rtc_remove(struct platform_device *pdev)
570 565
571 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN); 566 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
572 567
573 platform_set_drvdata(pdev, NULL);
574
575 return 0; 568 return 0;
576} 569}
577 570
diff --git a/drivers/rtc/rtc-dm355evm.c b/drivers/rtc/rtc-dm355evm.c
index 1e1ca63d58a9..1aca08394c47 100644
--- a/drivers/rtc/rtc-dm355evm.c
+++ b/drivers/rtc/rtc-dm355evm.c
@@ -139,19 +139,12 @@ static int dm355evm_rtc_probe(struct platform_device *pdev)
139 return 0; 139 return 0;
140} 140}
141 141
142static int dm355evm_rtc_remove(struct platform_device *pdev)
143{
144 platform_set_drvdata(pdev, NULL);
145 return 0;
146}
147
148/* 142/*
149 * I2C is used to talk to the MSP430, but this platform device is 143 * I2C is used to talk to the MSP430, but this platform device is
150 * exposed by an MFD driver that manages I2C communications. 144 * exposed by an MFD driver that manages I2C communications.
151 */ 145 */
152static struct platform_driver rtc_dm355evm_driver = { 146static struct platform_driver rtc_dm355evm_driver = {
153 .probe = dm355evm_rtc_probe, 147 .probe = dm355evm_rtc_probe,
154 .remove = dm355evm_rtc_remove,
155 .driver = { 148 .driver = {
156 .owner = THIS_MODULE, 149 .owner = THIS_MODULE,
157 .name = "rtc-dm355evm", 150 .name = "rtc-dm355evm",
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c
index c7702b7269f7..9c04fd2bc209 100644
--- a/drivers/rtc/rtc-ds1216.c
+++ b/drivers/rtc/rtc-ds1216.c
@@ -167,34 +167,17 @@ static int __init ds1216_rtc_probe(struct platform_device *pdev)
167 return 0; 167 return 0;
168} 168}
169 169
170static int __exit ds1216_rtc_remove(struct platform_device *pdev)
171{
172 return 0;
173}
174
175static struct platform_driver ds1216_rtc_platform_driver = { 170static struct platform_driver ds1216_rtc_platform_driver = {
176 .driver = { 171 .driver = {
177 .name = "rtc-ds1216", 172 .name = "rtc-ds1216",
178 .owner = THIS_MODULE, 173 .owner = THIS_MODULE,
179 }, 174 },
180 .remove = __exit_p(ds1216_rtc_remove),
181}; 175};
182 176
183static int __init ds1216_rtc_init(void) 177module_platform_driver_probe(ds1216_rtc_platform_driver, ds1216_rtc_probe);
184{
185 return platform_driver_probe(&ds1216_rtc_platform_driver, ds1216_rtc_probe);
186}
187
188static void __exit ds1216_rtc_exit(void)
189{
190 platform_driver_unregister(&ds1216_rtc_platform_driver);
191}
192 178
193MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>"); 179MODULE_AUTHOR("Thomas Bogendoerfer <tsbogend@alpha.franken.de>");
194MODULE_DESCRIPTION("DS1216 RTC driver"); 180MODULE_DESCRIPTION("DS1216 RTC driver");
195MODULE_LICENSE("GPL"); 181MODULE_LICENSE("GPL");
196MODULE_VERSION(DRV_VERSION); 182MODULE_VERSION(DRV_VERSION);
197MODULE_ALIAS("platform:rtc-ds1216"); 183MODULE_ALIAS("platform:rtc-ds1216");
198
199module_init(ds1216_rtc_init);
200module_exit(ds1216_rtc_exit);
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
index 398c96a98fc4..50e109b78252 100644
--- a/drivers/rtc/rtc-ds1286.c
+++ b/drivers/rtc/rtc-ds1286.c
@@ -353,18 +353,12 @@ static int ds1286_probe(struct platform_device *pdev)
353 return 0; 353 return 0;
354} 354}
355 355
356static int ds1286_remove(struct platform_device *pdev)
357{
358 return 0;
359}
360
361static struct platform_driver ds1286_platform_driver = { 356static struct platform_driver ds1286_platform_driver = {
362 .driver = { 357 .driver = {
363 .name = "rtc-ds1286", 358 .name = "rtc-ds1286",
364 .owner = THIS_MODULE, 359 .owner = THIS_MODULE,
365 }, 360 },
366 .probe = ds1286_probe, 361 .probe = ds1286_probe,
367 .remove = ds1286_remove,
368}; 362};
369 363
370module_platform_driver(ds1286_platform_driver); 364module_platform_driver(ds1286_platform_driver);
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index d13954346286..07e8d79b4a09 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -23,8 +23,12 @@
23#define RTC_CMD_READ 0x81 /* Read command */ 23#define RTC_CMD_READ 0x81 /* Read command */
24#define RTC_CMD_WRITE 0x80 /* Write command */ 24#define RTC_CMD_WRITE 0x80 /* Write command */
25 25
26#define RTC_CMD_WRITE_ENABLE 0x00 /* Write enable */
27#define RTC_CMD_WRITE_DISABLE 0x80 /* Write disable */
28
26#define RTC_ADDR_RAM0 0x20 /* Address of RAM0 */ 29#define RTC_ADDR_RAM0 0x20 /* Address of RAM0 */
27#define RTC_ADDR_TCR 0x08 /* Address of trickle charge register */ 30#define RTC_ADDR_TCR 0x08 /* Address of trickle charge register */
31#define RTC_ADDR_CTRL 0x07 /* Address of control register */
28#define RTC_ADDR_YEAR 0x06 /* Address of year register */ 32#define RTC_ADDR_YEAR 0x06 /* Address of year register */
29#define RTC_ADDR_DAY 0x05 /* Address of day of week register */ 33#define RTC_ADDR_DAY 0x05 /* Address of day of week register */
30#define RTC_ADDR_MON 0x04 /* Address of month register */ 34#define RTC_ADDR_MON 0x04 /* Address of month register */
@@ -161,6 +165,7 @@ static int ds1302_rtc_read_time(struct device *dev, struct rtc_time *tm)
161 165
162static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm) 166static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
163{ 167{
168 ds1302_writebyte(RTC_ADDR_CTRL, RTC_CMD_WRITE_ENABLE);
164 /* Stop RTC */ 169 /* Stop RTC */
165 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80); 170 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) | 0x80);
166 171
@@ -175,6 +180,8 @@ static int ds1302_rtc_set_time(struct device *dev, struct rtc_time *tm)
175 /* Start RTC */ 180 /* Start RTC */
176 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80); 181 ds1302_writebyte(RTC_ADDR_SEC, ds1302_readbyte(RTC_ADDR_SEC) & ~0x80);
177 182
183 ds1302_writebyte(RTC_ADDR_CTRL, RTC_CMD_WRITE_DISABLE);
184
178 return 0; 185 return 0;
179} 186}
180 187
@@ -234,19 +241,11 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev)
234 return 0; 241 return 0;
235} 242}
236 243
237static int __exit ds1302_rtc_remove(struct platform_device *pdev)
238{
239 platform_set_drvdata(pdev, NULL);
240
241 return 0;
242}
243
244static struct platform_driver ds1302_platform_driver = { 244static struct platform_driver ds1302_platform_driver = {
245 .driver = { 245 .driver = {
246 .name = DRV_NAME, 246 .name = DRV_NAME,
247 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
248 }, 248 },
249 .remove = __exit_p(ds1302_rtc_remove),
250}; 249};
251 250
252module_platform_driver_probe(ds1302_platform_driver, ds1302_rtc_probe); 251module_platform_driver_probe(ds1302_platform_driver, ds1302_rtc_probe);
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index bb5f13f63630..dd6170acde95 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -158,7 +158,7 @@ static int ds1305_alarm_irq_enable(struct device *dev, unsigned int enabled)
158 goto done; 158 goto done;
159 buf[1] &= ~DS1305_AEI0; 159 buf[1] &= ~DS1305_AEI0;
160 } 160 }
161 err = spi_write_then_read(ds1305->spi, buf, sizeof buf, NULL, 0); 161 err = spi_write_then_read(ds1305->spi, buf, sizeof(buf), NULL, 0);
162 if (err >= 0) 162 if (err >= 0)
163 ds1305->ctrl[0] = buf[1]; 163 ds1305->ctrl[0] = buf[1];
164done: 164done:
@@ -181,8 +181,8 @@ static int ds1305_get_time(struct device *dev, struct rtc_time *time)
181 /* Use write-then-read to get all the date/time registers 181 /* Use write-then-read to get all the date/time registers
182 * since dma from stack is nonportable 182 * since dma from stack is nonportable
183 */ 183 */
184 status = spi_write_then_read(ds1305->spi, &addr, sizeof addr, 184 status = spi_write_then_read(ds1305->spi, &addr, sizeof(addr),
185 buf, sizeof buf); 185 buf, sizeof(buf));
186 if (status < 0) 186 if (status < 0)
187 return status; 187 return status;
188 188
@@ -237,7 +237,7 @@ static int ds1305_set_time(struct device *dev, struct rtc_time *time)
237 buf[4], buf[5], buf[6], buf[7]); 237 buf[4], buf[5], buf[6], buf[7]);
238 238
239 /* use write-then-read since dma from stack is nonportable */ 239 /* use write-then-read since dma from stack is nonportable */
240 return spi_write_then_read(ds1305->spi, buf, sizeof buf, 240 return spi_write_then_read(ds1305->spi, buf, sizeof(buf),
241 NULL, 0); 241 NULL, 0);
242} 242}
243 243
@@ -286,8 +286,8 @@ static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm)
286 * of EFI status is at best fragile anyway (given IRQ handlers). 286 * of EFI status is at best fragile anyway (given IRQ handlers).
287 */ 287 */
288 addr = DS1305_CONTROL; 288 addr = DS1305_CONTROL;
289 status = spi_write_then_read(spi, &addr, sizeof addr, 289 status = spi_write_then_read(spi, &addr, sizeof(addr),
290 ds1305->ctrl, sizeof ds1305->ctrl); 290 ds1305->ctrl, sizeof(ds1305->ctrl));
291 if (status < 0) 291 if (status < 0)
292 return status; 292 return status;
293 293
@@ -296,8 +296,8 @@ static int ds1305_get_alarm(struct device *dev, struct rtc_wkalrm *alm)
296 296
297 /* get and check ALM0 registers */ 297 /* get and check ALM0 registers */
298 addr = DS1305_ALM0(DS1305_SEC); 298 addr = DS1305_ALM0(DS1305_SEC);
299 status = spi_write_then_read(spi, &addr, sizeof addr, 299 status = spi_write_then_read(spi, &addr, sizeof(addr),
300 buf, sizeof buf); 300 buf, sizeof(buf));
301 if (status < 0) 301 if (status < 0)
302 return status; 302 return status;
303 303
@@ -381,7 +381,7 @@ static int ds1305_set_alarm(struct device *dev, struct rtc_wkalrm *alm)
381 "alm0 write", buf[1 + DS1305_SEC], buf[1 + DS1305_MIN], 381 "alm0 write", buf[1 + DS1305_SEC], buf[1 + DS1305_MIN],
382 buf[1 + DS1305_HOUR], buf[1 + DS1305_WDAY]); 382 buf[1 + DS1305_HOUR], buf[1 + DS1305_WDAY]);
383 383
384 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0); 384 status = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0);
385 if (status < 0) 385 if (status < 0)
386 return status; 386 return status;
387 387
@@ -474,7 +474,7 @@ static void ds1305_work(struct work_struct *work)
474 buf[1] = ds1305->ctrl[0]; 474 buf[1] = ds1305->ctrl[0];
475 buf[2] = 0; 475 buf[2] = 0;
476 476
477 status = spi_write_then_read(spi, buf, sizeof buf, 477 status = spi_write_then_read(spi, buf, sizeof(buf),
478 NULL, 0); 478 NULL, 0);
479 if (status < 0) 479 if (status < 0)
480 dev_dbg(&spi->dev, "clear irq --> %d\n", status); 480 dev_dbg(&spi->dev, "clear irq --> %d\n", status);
@@ -627,8 +627,8 @@ static int ds1305_probe(struct spi_device *spi)
627 627
628 /* read and cache control registers */ 628 /* read and cache control registers */
629 addr = DS1305_CONTROL; 629 addr = DS1305_CONTROL;
630 status = spi_write_then_read(spi, &addr, sizeof addr, 630 status = spi_write_then_read(spi, &addr, sizeof(addr),
631 ds1305->ctrl, sizeof ds1305->ctrl); 631 ds1305->ctrl, sizeof(ds1305->ctrl));
632 if (status < 0) { 632 if (status < 0) {
633 dev_dbg(&spi->dev, "can't %s, %d\n", 633 dev_dbg(&spi->dev, "can't %s, %d\n",
634 "read", status); 634 "read", status);
@@ -659,7 +659,7 @@ static int ds1305_probe(struct spi_device *spi)
659 659
660 buf[0] = DS1305_WRITE | DS1305_CONTROL; 660 buf[0] = DS1305_WRITE | DS1305_CONTROL;
661 buf[1] = ds1305->ctrl[0]; 661 buf[1] = ds1305->ctrl[0];
662 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0); 662 status = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0);
663 663
664 dev_dbg(&spi->dev, "clear WP --> %d\n", status); 664 dev_dbg(&spi->dev, "clear WP --> %d\n", status);
665 if (status < 0) 665 if (status < 0)
@@ -713,7 +713,7 @@ static int ds1305_probe(struct spi_device *spi)
713 buf[1] = ds1305->ctrl[0]; 713 buf[1] = ds1305->ctrl[0];
714 buf[2] = ds1305->ctrl[1]; 714 buf[2] = ds1305->ctrl[1];
715 buf[3] = ds1305->ctrl[2]; 715 buf[3] = ds1305->ctrl[2];
716 status = spi_write_then_read(spi, buf, sizeof buf, NULL, 0); 716 status = spi_write_then_read(spi, buf, sizeof(buf), NULL, 0);
717 if (status < 0) { 717 if (status < 0) {
718 dev_dbg(&spi->dev, "can't %s, %d\n", 718 dev_dbg(&spi->dev, "can't %s, %d\n",
719 "write", status); 719 "write", status);
@@ -725,8 +725,8 @@ static int ds1305_probe(struct spi_device *spi)
725 725
726 /* see if non-Linux software set up AM/PM mode */ 726 /* see if non-Linux software set up AM/PM mode */
727 addr = DS1305_HOUR; 727 addr = DS1305_HOUR;
728 status = spi_write_then_read(spi, &addr, sizeof addr, 728 status = spi_write_then_read(spi, &addr, sizeof(addr),
729 &value, sizeof value); 729 &value, sizeof(value));
730 if (status < 0) { 730 if (status < 0) {
731 dev_dbg(&spi->dev, "read HOUR --> %d\n", status); 731 dev_dbg(&spi->dev, "read HOUR --> %d\n", status);
732 return status; 732 return status;
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index b53992ab3090..ca18fd1433b3 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -683,7 +683,7 @@ static int ds1307_probe(struct i2c_client *client,
683 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 683 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
684 return -EIO; 684 return -EIO;
685 685
686 ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL); 686 ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL);
687 if (!ds1307) 687 if (!ds1307)
688 return -ENOMEM; 688 return -ENOMEM;
689 689
@@ -715,7 +715,7 @@ static int ds1307_probe(struct i2c_client *client,
715 if (tmp != 2) { 715 if (tmp != 2) {
716 dev_dbg(&client->dev, "read error %d\n", tmp); 716 dev_dbg(&client->dev, "read error %d\n", tmp);
717 err = -EIO; 717 err = -EIO;
718 goto exit_free; 718 goto exit;
719 } 719 }
720 720
721 /* oscillator off? turn it on, so clock can tick. */ 721 /* oscillator off? turn it on, so clock can tick. */
@@ -754,7 +754,7 @@ static int ds1307_probe(struct i2c_client *client,
754 if (tmp != 2) { 754 if (tmp != 2) {
755 dev_dbg(&client->dev, "read error %d\n", tmp); 755 dev_dbg(&client->dev, "read error %d\n", tmp);
756 err = -EIO; 756 err = -EIO;
757 goto exit_free; 757 goto exit;
758 } 758 }
759 759
760 /* oscillator off? turn it on, so clock can tick. */ 760 /* oscillator off? turn it on, so clock can tick. */
@@ -798,7 +798,7 @@ static int ds1307_probe(struct i2c_client *client,
798 if (tmp != 2) { 798 if (tmp != 2) {
799 dev_dbg(&client->dev, "read error %d\n", tmp); 799 dev_dbg(&client->dev, "read error %d\n", tmp);
800 err = -EIO; 800 err = -EIO;
801 goto exit_free; 801 goto exit;
802 } 802 }
803 803
804 /* correct hour */ 804 /* correct hour */
@@ -826,7 +826,7 @@ read_rtc:
826 if (tmp != 8) { 826 if (tmp != 8) {
827 dev_dbg(&client->dev, "read error %d\n", tmp); 827 dev_dbg(&client->dev, "read error %d\n", tmp);
828 err = -EIO; 828 err = -EIO;
829 goto exit_free; 829 goto exit;
830 } 830 }
831 831
832 /* 832 /*
@@ -868,7 +868,7 @@ read_rtc:
868 if (tmp < 0) { 868 if (tmp < 0) {
869 dev_dbg(&client->dev, "read error %d\n", tmp); 869 dev_dbg(&client->dev, "read error %d\n", tmp);
870 err = -EIO; 870 err = -EIO;
871 goto exit_free; 871 goto exit;
872 } 872 }
873 873
874 /* oscillator fault? clear flag, and warn */ 874 /* oscillator fault? clear flag, and warn */
@@ -927,13 +927,13 @@ read_rtc:
927 bin2bcd(tmp)); 927 bin2bcd(tmp));
928 } 928 }
929 929
930 ds1307->rtc = rtc_device_register(client->name, &client->dev, 930 ds1307->rtc = devm_rtc_device_register(&client->dev, client->name,
931 &ds13xx_rtc_ops, THIS_MODULE); 931 &ds13xx_rtc_ops, THIS_MODULE);
932 if (IS_ERR(ds1307->rtc)) { 932 if (IS_ERR(ds1307->rtc)) {
933 err = PTR_ERR(ds1307->rtc); 933 err = PTR_ERR(ds1307->rtc);
934 dev_err(&client->dev, 934 dev_err(&client->dev,
935 "unable to register the class device\n"); 935 "unable to register the class device\n");
936 goto exit_free; 936 goto exit;
937 } 937 }
938 938
939 if (want_irq) { 939 if (want_irq) {
@@ -942,7 +942,7 @@ read_rtc:
942 if (err) { 942 if (err) {
943 dev_err(&client->dev, 943 dev_err(&client->dev,
944 "unable to request IRQ!\n"); 944 "unable to request IRQ!\n");
945 goto exit_irq; 945 goto exit;
946 } 946 }
947 947
948 device_set_wakeup_capable(&client->dev, 1); 948 device_set_wakeup_capable(&client->dev, 1);
@@ -951,11 +951,12 @@ read_rtc:
951 } 951 }
952 952
953 if (chip->nvram_size) { 953 if (chip->nvram_size) {
954 ds1307->nvram = kzalloc(sizeof(struct bin_attribute), 954 ds1307->nvram = devm_kzalloc(&client->dev,
955 GFP_KERNEL); 955 sizeof(struct bin_attribute),
956 GFP_KERNEL);
956 if (!ds1307->nvram) { 957 if (!ds1307->nvram) {
957 err = -ENOMEM; 958 err = -ENOMEM;
958 goto exit_nvram; 959 goto exit;
959 } 960 }
960 ds1307->nvram->attr.name = "nvram"; 961 ds1307->nvram->attr.name = "nvram";
961 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; 962 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR;
@@ -965,21 +966,15 @@ read_rtc:
965 ds1307->nvram->size = chip->nvram_size; 966 ds1307->nvram->size = chip->nvram_size;
966 ds1307->nvram_offset = chip->nvram_offset; 967 ds1307->nvram_offset = chip->nvram_offset;
967 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram); 968 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram);
968 if (err) { 969 if (err)
969 kfree(ds1307->nvram); 970 goto exit;
970 goto exit_nvram;
971 }
972 set_bit(HAS_NVRAM, &ds1307->flags); 971 set_bit(HAS_NVRAM, &ds1307->flags);
973 dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size); 972 dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size);
974 } 973 }
975 974
976 return 0; 975 return 0;
977 976
978exit_nvram: 977exit:
979exit_irq:
980 rtc_device_unregister(ds1307->rtc);
981exit_free:
982 kfree(ds1307);
983 return err; 978 return err;
984} 979}
985 980
@@ -992,13 +987,9 @@ static int ds1307_remove(struct i2c_client *client)
992 cancel_work_sync(&ds1307->work); 987 cancel_work_sync(&ds1307->work);
993 } 988 }
994 989
995 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) { 990 if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags))
996 sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram); 991 sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram);
997 kfree(ds1307->nvram);
998 }
999 992
1000 rtc_device_unregister(ds1307->rtc);
1001 kfree(ds1307);
1002 return 0; 993 return 0;
1003} 994}
1004 995
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index 94366e12f40f..9e6e14fb53d7 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -65,7 +65,7 @@ struct ds1374 {
65static struct i2c_driver ds1374_driver; 65static struct i2c_driver ds1374_driver;
66 66
67static int ds1374_read_rtc(struct i2c_client *client, u32 *time, 67static int ds1374_read_rtc(struct i2c_client *client, u32 *time,
68 int reg, int nbytes) 68 int reg, int nbytes)
69{ 69{
70 u8 buf[4]; 70 u8 buf[4];
71 int ret; 71 int ret;
@@ -90,7 +90,7 @@ static int ds1374_read_rtc(struct i2c_client *client, u32 *time,
90} 90}
91 91
92static int ds1374_write_rtc(struct i2c_client *client, u32 time, 92static int ds1374_write_rtc(struct i2c_client *client, u32 time,
93 int reg, int nbytes) 93 int reg, int nbytes)
94{ 94{
95 u8 buf[4]; 95 u8 buf[4];
96 int i; 96 int i;
@@ -119,8 +119,7 @@ static int ds1374_check_rtc_status(struct i2c_client *client)
119 119
120 if (stat & DS1374_REG_SR_OSF) 120 if (stat & DS1374_REG_SR_OSF)
121 dev_warn(&client->dev, 121 dev_warn(&client->dev,
122 "oscillator discontinuity flagged, " 122 "oscillator discontinuity flagged, time unreliable\n");
123 "time unreliable\n");
124 123
125 stat &= ~(DS1374_REG_SR_OSF | DS1374_REG_SR_AF); 124 stat &= ~(DS1374_REG_SR_OSF | DS1374_REG_SR_AF);
126 125
@@ -363,7 +362,7 @@ static int ds1374_probe(struct i2c_client *client,
363 362
364 if (client->irq > 0) { 363 if (client->irq > 0) {
365 ret = devm_request_irq(&client->dev, client->irq, ds1374_irq, 0, 364 ret = devm_request_irq(&client->dev, client->irq, ds1374_irq, 0,
366 "ds1374", client); 365 "ds1374", client);
367 if (ret) { 366 if (ret) {
368 dev_err(&client->dev, "unable to request IRQ\n"); 367 dev_err(&client->dev, "unable to request IRQ\n");
369 return ret; 368 return ret;
@@ -373,7 +372,7 @@ static int ds1374_probe(struct i2c_client *client,
373 } 372 }
374 373
375 ds1374->rtc = devm_rtc_device_register(&client->dev, client->name, 374 ds1374->rtc = devm_rtc_device_register(&client->dev, client->name,
376 &ds1374_rtc_ops, THIS_MODULE); 375 &ds1374_rtc_ops, THIS_MODULE);
377 if (IS_ERR(ds1374->rtc)) { 376 if (IS_ERR(ds1374->rtc)) {
378 dev_err(&client->dev, "unable to register the class device\n"); 377 dev_err(&client->dev, "unable to register the class device\n");
379 return PTR_ERR(ds1374->rtc); 378 return PTR_ERR(ds1374->rtc);
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index 289af419dff4..be9d8c0a7e3a 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -154,18 +154,12 @@ static int ds1390_probe(struct spi_device *spi)
154 return res; 154 return res;
155} 155}
156 156
157static int ds1390_remove(struct spi_device *spi)
158{
159 return 0;
160}
161
162static struct spi_driver ds1390_driver = { 157static struct spi_driver ds1390_driver = {
163 .driver = { 158 .driver = {
164 .name = "rtc-ds1390", 159 .name = "rtc-ds1390",
165 .owner = THIS_MODULE, 160 .owner = THIS_MODULE,
166 }, 161 },
167 .probe = ds1390_probe, 162 .probe = ds1390_probe,
168 .remove = ds1390_remove,
169}; 163};
170 164
171module_spi_driver(ds1390_driver); 165module_spi_driver(ds1390_driver);
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 6ce8a997cf51..308a8fefe76f 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -104,31 +104,31 @@ static DEFINE_SPINLOCK(ds1511_lock);
104static __iomem char *ds1511_base; 104static __iomem char *ds1511_base;
105static u32 reg_spacing = 1; 105static u32 reg_spacing = 1;
106 106
107 static noinline void 107static noinline void
108rtc_write(uint8_t val, uint32_t reg) 108rtc_write(uint8_t val, uint32_t reg)
109{ 109{
110 writeb(val, ds1511_base + (reg * reg_spacing)); 110 writeb(val, ds1511_base + (reg * reg_spacing));
111} 111}
112 112
113 static inline void 113static inline void
114rtc_write_alarm(uint8_t val, enum ds1511reg reg) 114rtc_write_alarm(uint8_t val, enum ds1511reg reg)
115{ 115{
116 rtc_write((val | 0x80), reg); 116 rtc_write((val | 0x80), reg);
117} 117}
118 118
119 static noinline uint8_t 119static noinline uint8_t
120rtc_read(enum ds1511reg reg) 120rtc_read(enum ds1511reg reg)
121{ 121{
122 return readb(ds1511_base + (reg * reg_spacing)); 122 return readb(ds1511_base + (reg * reg_spacing));
123} 123}
124 124
125 static inline void 125static inline void
126rtc_disable_update(void) 126rtc_disable_update(void)
127{ 127{
128 rtc_write((rtc_read(RTC_CMD) & ~RTC_TE), RTC_CMD); 128 rtc_write((rtc_read(RTC_CMD) & ~RTC_TE), RTC_CMD);
129} 129}
130 130
131 static void 131static void
132rtc_enable_update(void) 132rtc_enable_update(void)
133{ 133{
134 rtc_write((rtc_read(RTC_CMD) | RTC_TE), RTC_CMD); 134 rtc_write((rtc_read(RTC_CMD) | RTC_TE), RTC_CMD);
@@ -145,7 +145,7 @@ rtc_enable_update(void)
145 * just enough code to set the watchdog timer so that it 145 * just enough code to set the watchdog timer so that it
146 * will reboot the system 146 * will reboot the system
147 */ 147 */
148 void 148void
149ds1511_wdog_set(unsigned long deciseconds) 149ds1511_wdog_set(unsigned long deciseconds)
150{ 150{
151 /* 151 /*
@@ -163,7 +163,7 @@ ds1511_wdog_set(unsigned long deciseconds)
163 rtc_write(DS1511_WDE | DS1511_WDS, RTC_CMD); 163 rtc_write(DS1511_WDE | DS1511_WDS, RTC_CMD);
164} 164}
165 165
166 void 166void
167ds1511_wdog_disable(void) 167ds1511_wdog_disable(void)
168{ 168{
169 /* 169 /*
@@ -191,13 +191,12 @@ static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
191 /* 191 /*
192 * won't have to change this for a while 192 * won't have to change this for a while
193 */ 193 */
194 if (rtc_tm->tm_year < 1900) { 194 if (rtc_tm->tm_year < 1900)
195 rtc_tm->tm_year += 1900; 195 rtc_tm->tm_year += 1900;
196 }
197 196
198 if (rtc_tm->tm_year < 1970) { 197 if (rtc_tm->tm_year < 1970)
199 return -EINVAL; 198 return -EINVAL;
200 } 199
201 yrs = rtc_tm->tm_year % 100; 200 yrs = rtc_tm->tm_year % 100;
202 cen = rtc_tm->tm_year / 100; 201 cen = rtc_tm->tm_year / 100;
203 mon = rtc_tm->tm_mon + 1; /* tm_mon starts at zero */ 202 mon = rtc_tm->tm_mon + 1; /* tm_mon starts at zero */
@@ -207,17 +206,14 @@ static int ds1511_rtc_set_time(struct device *dev, struct rtc_time *rtc_tm)
207 min = rtc_tm->tm_min; 206 min = rtc_tm->tm_min;
208 sec = rtc_tm->tm_sec; 207 sec = rtc_tm->tm_sec;
209 208
210 if ((mon > 12) || (day == 0)) { 209 if ((mon > 12) || (day == 0))
211 return -EINVAL; 210 return -EINVAL;
212 }
213 211
214 if (day > rtc_month_days(rtc_tm->tm_mon, rtc_tm->tm_year)) { 212 if (day > rtc_month_days(rtc_tm->tm_mon, rtc_tm->tm_year))
215 return -EINVAL; 213 return -EINVAL;
216 }
217 214
218 if ((hrs >= 24) || (min >= 60) || (sec >= 60)) { 215 if ((hrs >= 24) || (min >= 60) || (sec >= 60))
219 return -EINVAL; 216 return -EINVAL;
220 }
221 217
222 /* 218 /*
223 * each register is a different number of valid bits 219 * each register is a different number of valid bits
@@ -299,7 +295,7 @@ static int ds1511_rtc_read_time(struct device *dev, struct rtc_time *rtc_tm)
299 * date/hours/mins/secs matches. the ds1511 has many more 295 * date/hours/mins/secs matches. the ds1511 has many more
300 * permutations, but the kernel doesn't. 296 * permutations, but the kernel doesn't.
301 */ 297 */
302 static void 298static void
303ds1511_rtc_update_alarm(struct rtc_plat_data *pdata) 299ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
304{ 300{
305 unsigned long flags; 301 unsigned long flags;
@@ -322,7 +318,7 @@ ds1511_rtc_update_alarm(struct rtc_plat_data *pdata)
322 spin_unlock_irqrestore(&pdata->lock, flags); 318 spin_unlock_irqrestore(&pdata->lock, flags);
323} 319}
324 320
325 static int 321static int
326ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm) 322ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
327{ 323{
328 struct platform_device *pdev = to_platform_device(dev); 324 struct platform_device *pdev = to_platform_device(dev);
@@ -335,14 +331,14 @@ ds1511_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
335 pdata->alrm_hour = alrm->time.tm_hour; 331 pdata->alrm_hour = alrm->time.tm_hour;
336 pdata->alrm_min = alrm->time.tm_min; 332 pdata->alrm_min = alrm->time.tm_min;
337 pdata->alrm_sec = alrm->time.tm_sec; 333 pdata->alrm_sec = alrm->time.tm_sec;
338 if (alrm->enabled) { 334 if (alrm->enabled)
339 pdata->irqen |= RTC_AF; 335 pdata->irqen |= RTC_AF;
340 } 336
341 ds1511_rtc_update_alarm(pdata); 337 ds1511_rtc_update_alarm(pdata);
342 return 0; 338 return 0;
343} 339}
344 340
345 static int 341static int
346ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm) 342ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
347{ 343{
348 struct platform_device *pdev = to_platform_device(dev); 344 struct platform_device *pdev = to_platform_device(dev);
@@ -359,7 +355,7 @@ ds1511_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
359 return 0; 355 return 0;
360} 356}
361 357
362 static irqreturn_t 358static irqreturn_t
363ds1511_interrupt(int irq, void *dev_id) 359ds1511_interrupt(int irq, void *dev_id)
364{ 360{
365 struct platform_device *pdev = dev_id; 361 struct platform_device *pdev = dev_id;
@@ -406,7 +402,7 @@ static const struct rtc_class_ops ds1511_rtc_ops = {
406 .alarm_irq_enable = ds1511_rtc_alarm_irq_enable, 402 .alarm_irq_enable = ds1511_rtc_alarm_irq_enable,
407}; 403};
408 404
409 static ssize_t 405static ssize_t
410ds1511_nvram_read(struct file *filp, struct kobject *kobj, 406ds1511_nvram_read(struct file *filp, struct kobject *kobj,
411 struct bin_attribute *ba, 407 struct bin_attribute *ba,
412 char *buf, loff_t pos, size_t size) 408 char *buf, loff_t pos, size_t size)
@@ -417,26 +413,26 @@ ds1511_nvram_read(struct file *filp, struct kobject *kobj,
417 * if count is more than one, turn on "burst" mode 413 * if count is more than one, turn on "burst" mode
418 * turn it off when you're done 414 * turn it off when you're done
419 */ 415 */
420 if (size > 1) { 416 if (size > 1)
421 rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD); 417 rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD);
422 } 418
423 if (pos > DS1511_RAM_MAX) { 419 if (pos > DS1511_RAM_MAX)
424 pos = DS1511_RAM_MAX; 420 pos = DS1511_RAM_MAX;
425 } 421
426 if (size + pos > DS1511_RAM_MAX + 1) { 422 if (size + pos > DS1511_RAM_MAX + 1)
427 size = DS1511_RAM_MAX - pos + 1; 423 size = DS1511_RAM_MAX - pos + 1;
428 } 424
429 rtc_write(pos, DS1511_RAMADDR_LSB); 425 rtc_write(pos, DS1511_RAMADDR_LSB);
430 for (count = 0; size > 0; count++, size--) { 426 for (count = 0; size > 0; count++, size--)
431 *buf++ = rtc_read(DS1511_RAMDATA); 427 *buf++ = rtc_read(DS1511_RAMDATA);
432 } 428
433 if (count > 1) { 429 if (count > 1)
434 rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD); 430 rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD);
435 } 431
436 return count; 432 return count;
437} 433}
438 434
439 static ssize_t 435static ssize_t
440ds1511_nvram_write(struct file *filp, struct kobject *kobj, 436ds1511_nvram_write(struct file *filp, struct kobject *kobj,
441 struct bin_attribute *bin_attr, 437 struct bin_attribute *bin_attr,
442 char *buf, loff_t pos, size_t size) 438 char *buf, loff_t pos, size_t size)
@@ -447,22 +443,22 @@ ds1511_nvram_write(struct file *filp, struct kobject *kobj,
447 * if count is more than one, turn on "burst" mode 443 * if count is more than one, turn on "burst" mode
448 * turn it off when you're done 444 * turn it off when you're done
449 */ 445 */
450 if (size > 1) { 446 if (size > 1)
451 rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD); 447 rtc_write((rtc_read(RTC_CMD) | DS1511_BME), RTC_CMD);
452 } 448
453 if (pos > DS1511_RAM_MAX) { 449 if (pos > DS1511_RAM_MAX)
454 pos = DS1511_RAM_MAX; 450 pos = DS1511_RAM_MAX;
455 } 451
456 if (size + pos > DS1511_RAM_MAX + 1) { 452 if (size + pos > DS1511_RAM_MAX + 1)
457 size = DS1511_RAM_MAX - pos + 1; 453 size = DS1511_RAM_MAX - pos + 1;
458 } 454
459 rtc_write(pos, DS1511_RAMADDR_LSB); 455 rtc_write(pos, DS1511_RAMADDR_LSB);
460 for (count = 0; size > 0; count++, size--) { 456 for (count = 0; size > 0; count++, size--)
461 rtc_write(*buf++, DS1511_RAMDATA); 457 rtc_write(*buf++, DS1511_RAMDATA);
462 } 458
463 if (count > 1) { 459 if (count > 1)
464 rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD); 460 rtc_write((rtc_read(RTC_CMD) & ~DS1511_BME), RTC_CMD);
465 } 461
466 return count; 462 return count;
467} 463}
468 464
@@ -484,9 +480,9 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
484 int ret = 0; 480 int ret = 0;
485 481
486 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 482 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
487 if (!res) { 483 if (!res)
488 return -ENODEV; 484 return -ENODEV;
489 } 485
490 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 486 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
491 if (!pdata) 487 if (!pdata)
492 return -ENOMEM; 488 return -ENOMEM;
@@ -518,9 +514,8 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
518 /* 514 /*
519 * check for a dying bat-tree 515 * check for a dying bat-tree
520 */ 516 */
521 if (rtc_read(RTC_CMD1) & DS1511_BLF1) { 517 if (rtc_read(RTC_CMD1) & DS1511_BLF1)
522 dev_warn(&pdev->dev, "voltage-low detected.\n"); 518 dev_warn(&pdev->dev, "voltage-low detected.\n");
523 }
524 519
525 spin_lock_init(&pdata->lock); 520 spin_lock_init(&pdata->lock);
526 platform_set_drvdata(pdev, pdata); 521 platform_set_drvdata(pdev, pdata);
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 3fc2a4738027..18e2d8471472 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -153,11 +153,6 @@ static const struct rtc_class_ops ds1672_rtc_ops = {
153 .set_mmss = ds1672_rtc_set_mmss, 153 .set_mmss = ds1672_rtc_set_mmss,
154}; 154};
155 155
156static int ds1672_remove(struct i2c_client *client)
157{
158 return 0;
159}
160
161static int ds1672_probe(struct i2c_client *client, 156static int ds1672_probe(struct i2c_client *client,
162 const struct i2c_device_id *id) 157 const struct i2c_device_id *id)
163{ 158{
@@ -210,7 +205,6 @@ static struct i2c_driver ds1672_driver = {
210 .name = "rtc-ds1672", 205 .name = "rtc-ds1672",
211 }, 206 },
212 .probe = &ds1672_probe, 207 .probe = &ds1672_probe,
213 .remove = &ds1672_remove,
214 .id_table = ds1672_id, 208 .id_table = ds1672_id,
215}; 209};
216 210
diff --git a/drivers/rtc/rtc-ds3234.c b/drivers/rtc/rtc-ds3234.c
index ba98c0e9580d..4c9ba5368464 100644
--- a/drivers/rtc/rtc-ds3234.c
+++ b/drivers/rtc/rtc-ds3234.c
@@ -73,7 +73,7 @@ static int ds3234_read_time(struct device *dev, struct rtc_time *dt)
73 dt->tm_wday = bcd2bin(buf[3]) - 1; /* 0 = Sun */ 73 dt->tm_wday = bcd2bin(buf[3]) - 1; /* 0 = Sun */
74 dt->tm_mday = bcd2bin(buf[4]); 74 dt->tm_mday = bcd2bin(buf[4]);
75 dt->tm_mon = bcd2bin(buf[5] & 0x1f) - 1; /* 0 = Jan */ 75 dt->tm_mon = bcd2bin(buf[5] & 0x1f) - 1; /* 0 = Jan */
76 dt->tm_year = bcd2bin(buf[6] & 0xff) + 100; /* Assume 20YY */ 76 dt->tm_year = bcd2bin(buf[6] & 0xff) + 100; /* Assume 20YY */
77 77
78 return rtc_valid_tm(dt); 78 return rtc_valid_tm(dt);
79} 79}
@@ -156,18 +156,12 @@ static int ds3234_probe(struct spi_device *spi)
156 return 0; 156 return 0;
157} 157}
158 158
159static int ds3234_remove(struct spi_device *spi)
160{
161 return 0;
162}
163
164static struct spi_driver ds3234_driver = { 159static struct spi_driver ds3234_driver = {
165 .driver = { 160 .driver = {
166 .name = "ds3234", 161 .name = "ds3234",
167 .owner = THIS_MODULE, 162 .owner = THIS_MODULE,
168 }, 163 },
169 .probe = ds3234_probe, 164 .probe = ds3234_probe,
170 .remove = ds3234_remove,
171}; 165};
172 166
173module_spi_driver(ds3234_driver); 167module_spi_driver(ds3234_driver);
diff --git a/drivers/rtc/rtc-efi.c b/drivers/rtc/rtc-efi.c
index b3c8c0b1709d..797aa0252ba9 100644
--- a/drivers/rtc/rtc-efi.c
+++ b/drivers/rtc/rtc-efi.c
@@ -201,17 +201,11 @@ static int __init efi_rtc_probe(struct platform_device *dev)
201 return 0; 201 return 0;
202} 202}
203 203
204static int __exit efi_rtc_remove(struct platform_device *dev)
205{
206 return 0;
207}
208
209static struct platform_driver efi_rtc_driver = { 204static struct platform_driver efi_rtc_driver = {
210 .driver = { 205 .driver = {
211 .name = "rtc-efi", 206 .name = "rtc-efi",
212 .owner = THIS_MODULE, 207 .owner = THIS_MODULE,
213 }, 208 },
214 .remove = __exit_p(efi_rtc_remove),
215}; 209};
216 210
217module_platform_driver_probe(efi_rtc_driver, efi_rtc_probe); 211module_platform_driver_probe(efi_rtc_driver, efi_rtc_probe);
diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index 3f9eb57d0486..fccf36699245 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -131,11 +131,6 @@ static int em3027_probe(struct i2c_client *client,
131 return 0; 131 return 0;
132} 132}
133 133
134static int em3027_remove(struct i2c_client *client)
135{
136 return 0;
137}
138
139static struct i2c_device_id em3027_id[] = { 134static struct i2c_device_id em3027_id[] = {
140 { "em3027", 0 }, 135 { "em3027", 0 },
141 { } 136 { }
@@ -146,7 +141,6 @@ static struct i2c_driver em3027_driver = {
146 .name = "rtc-em3027", 141 .name = "rtc-em3027",
147 }, 142 },
148 .probe = &em3027_probe, 143 .probe = &em3027_probe,
149 .remove = &em3027_remove,
150 .id_table = em3027_id, 144 .id_table = em3027_id,
151}; 145};
152 146
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 5807b77c444a..549b3c3792d2 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -167,7 +167,6 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
167 return 0; 167 return 0;
168 168
169exit: 169exit:
170 platform_set_drvdata(pdev, NULL);
171 pdev->dev.platform_data = NULL; 170 pdev->dev.platform_data = NULL;
172 return err; 171 return err;
173} 172}
@@ -175,7 +174,6 @@ exit:
175static int ep93xx_rtc_remove(struct platform_device *pdev) 174static int ep93xx_rtc_remove(struct platform_device *pdev)
176{ 175{
177 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); 176 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
178 platform_set_drvdata(pdev, NULL);
179 pdev->dev.platform_data = NULL; 177 pdev->dev.platform_data = NULL;
180 178
181 return 0; 179 return 0;
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index 2835fb6c1965..83c3b3029fa7 100644
--- a/drivers/rtc/rtc-fm3130.c
+++ b/drivers/rtc/rtc-fm3130.c
@@ -47,7 +47,7 @@
47 47
48struct fm3130 { 48struct fm3130 {
49 u8 reg_addr_time; 49 u8 reg_addr_time;
50 u8 reg_addr_alarm; 50 u8 reg_addr_alarm;
51 u8 regs[15]; 51 u8 regs[15];
52 struct i2c_msg msg[4]; 52 struct i2c_msg msg[4];
53 struct i2c_client *client; 53 struct i2c_client *client;
@@ -520,18 +520,12 @@ exit_free:
520 return err; 520 return err;
521} 521}
522 522
523static int fm3130_remove(struct i2c_client *client)
524{
525 return 0;
526}
527
528static struct i2c_driver fm3130_driver = { 523static struct i2c_driver fm3130_driver = {
529 .driver = { 524 .driver = {
530 .name = "rtc-fm3130", 525 .name = "rtc-fm3130",
531 .owner = THIS_MODULE, 526 .owner = THIS_MODULE,
532 }, 527 },
533 .probe = fm3130_probe, 528 .probe = fm3130_probe,
534 .remove = fm3130_remove,
535 .id_table = fm3130_id, 529 .id_table = fm3130_id,
536}; 530};
537 531
diff --git a/drivers/rtc/rtc-generic.c b/drivers/rtc/rtc-generic.c
index 06279ce6bff2..9b6725ebbfb2 100644
--- a/drivers/rtc/rtc-generic.c
+++ b/drivers/rtc/rtc-generic.c
@@ -48,17 +48,11 @@ static int __init generic_rtc_probe(struct platform_device *dev)
48 return 0; 48 return 0;
49} 49}
50 50
51static int __exit generic_rtc_remove(struct platform_device *dev)
52{
53 return 0;
54}
55
56static struct platform_driver generic_rtc_driver = { 51static struct platform_driver generic_rtc_driver = {
57 .driver = { 52 .driver = {
58 .name = "rtc-generic", 53 .name = "rtc-generic",
59 .owner = THIS_MODULE, 54 .owner = THIS_MODULE,
60 }, 55 },
61 .remove = __exit_p(generic_rtc_remove),
62}; 56};
63 57
64module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe); 58module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe);
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 63024505dddc..7273b0139e5c 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -76,6 +76,20 @@ static int hid_time_proc_event(struct hid_sensor_hub_device *hsdev,
76 return 0; 76 return 0;
77} 77}
78 78
79static u32 hid_time_value(size_t raw_len, char *raw_data)
80{
81 switch (raw_len) {
82 case 1:
83 return *(u8 *)raw_data;
84 case 2:
85 return *(u16 *)raw_data;
86 case 4:
87 return *(u32 *)raw_data;
88 default:
89 return (u32)(~0U); /* 0xff... or -1 to denote an error */
90 }
91}
92
79static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev, 93static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
80 unsigned usage_id, size_t raw_len, 94 unsigned usage_id, size_t raw_len,
81 char *raw_data, void *priv) 95 char *raw_data, void *priv)
@@ -85,26 +99,35 @@ static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
85 99
86 switch (usage_id) { 100 switch (usage_id) {
87 case HID_USAGE_SENSOR_TIME_YEAR: 101 case HID_USAGE_SENSOR_TIME_YEAR:
88 time_buf->tm_year = *(u8 *)raw_data; 102 /*
89 if (time_buf->tm_year < 70) 103 * The draft for HID-sensors (HUTRR39) currently doesn't define
90 /* assume we are in 1970...2069 */ 104 * the range for the year attribute. Therefor we support
91 time_buf->tm_year += 100; 105 * 8 bit (0-99) and 16 or 32 bits (full) as size for the year.
106 */
107 if (raw_len == 1) {
108 time_buf->tm_year = *(u8 *)raw_data;
109 if (time_buf->tm_year < 70)
110 /* assume we are in 1970...2069 */
111 time_buf->tm_year += 100;
112 } else
113 time_buf->tm_year =
114 (int)hid_time_value(raw_len, raw_data)-1900;
92 break; 115 break;
93 case HID_USAGE_SENSOR_TIME_MONTH: 116 case HID_USAGE_SENSOR_TIME_MONTH:
94 /* sensor sending the month as 1-12, we need 0-11 */ 117 /* sensors are sending the month as 1-12, we need 0-11 */
95 time_buf->tm_mon = *(u8 *)raw_data-1; 118 time_buf->tm_mon = (int)hid_time_value(raw_len, raw_data)-1;
96 break; 119 break;
97 case HID_USAGE_SENSOR_TIME_DAY: 120 case HID_USAGE_SENSOR_TIME_DAY:
98 time_buf->tm_mday = *(u8 *)raw_data; 121 time_buf->tm_mday = (int)hid_time_value(raw_len, raw_data);
99 break; 122 break;
100 case HID_USAGE_SENSOR_TIME_HOUR: 123 case HID_USAGE_SENSOR_TIME_HOUR:
101 time_buf->tm_hour = *(u8 *)raw_data; 124 time_buf->tm_hour = (int)hid_time_value(raw_len, raw_data);
102 break; 125 break;
103 case HID_USAGE_SENSOR_TIME_MINUTE: 126 case HID_USAGE_SENSOR_TIME_MINUTE:
104 time_buf->tm_min = *(u8 *)raw_data; 127 time_buf->tm_min = (int)hid_time_value(raw_len, raw_data);
105 break; 128 break;
106 case HID_USAGE_SENSOR_TIME_SECOND: 129 case HID_USAGE_SENSOR_TIME_SECOND:
107 time_buf->tm_sec = *(u8 *)raw_data; 130 time_buf->tm_sec = (int)hid_time_value(raw_len, raw_data);
108 break; 131 break;
109 default: 132 default:
110 return -EINVAL; 133 return -EINVAL;
@@ -150,9 +173,10 @@ static int hid_time_parse_report(struct platform_device *pdev,
150 "not all needed attributes inside the same report!\n"); 173 "not all needed attributes inside the same report!\n");
151 return -EINVAL; 174 return -EINVAL;
152 } 175 }
153 if (time_state->info[i].size != 1) { 176 if (time_state->info[i].size == 3 ||
177 time_state->info[i].size > 4) {
154 dev_err(&pdev->dev, 178 dev_err(&pdev->dev,
155 "attribute '%s' not 8 bits wide!\n", 179 "attribute '%s' not 8, 16 or 32 bits wide!\n",
156 hid_time_attrib_name( 180 hid_time_attrib_name(
157 time_state->info[i].attrib_id)); 181 time_state->info[i].attrib_id));
158 return -EINVAL; 182 return -EINVAL;
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index a1bbbb8de029..5dbdc4405718 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -16,6 +16,7 @@
16#include <linux/rtc.h> 16#include <linux/rtc.h>
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/err.h>
19 20
20#define DRV_VERSION "0.1" 21#define DRV_VERSION "0.1"
21 22
@@ -267,15 +268,7 @@ static int isl12022_probe(struct i2c_client *client,
267 isl12022->rtc = devm_rtc_device_register(&client->dev, 268 isl12022->rtc = devm_rtc_device_register(&client->dev,
268 isl12022_driver.driver.name, 269 isl12022_driver.driver.name,
269 &isl12022_rtc_ops, THIS_MODULE); 270 &isl12022_rtc_ops, THIS_MODULE);
270 if (IS_ERR(isl12022->rtc)) 271 return PTR_RET(isl12022->rtc);
271 return PTR_ERR(isl12022->rtc);
272
273 return 0;
274}
275
276static int isl12022_remove(struct i2c_client *client)
277{
278 return 0;
279} 272}
280 273
281static const struct i2c_device_id isl12022_id[] = { 274static const struct i2c_device_id isl12022_id[] = {
@@ -289,7 +282,6 @@ static struct i2c_driver isl12022_driver = {
289 .name = "rtc-isl12022", 282 .name = "rtc-isl12022",
290 }, 283 },
291 .probe = isl12022_probe, 284 .probe = isl12022_probe,
292 .remove = isl12022_remove,
293 .id_table = isl12022_id, 285 .id_table = isl12022_id,
294}; 286};
295 287
diff --git a/drivers/rtc/rtc-jz4740.c b/drivers/rtc/rtc-jz4740.c
index 1e48686ca6d2..1b126d2513de 100644
--- a/drivers/rtc/rtc-jz4740.c
+++ b/drivers/rtc/rtc-jz4740.c
@@ -14,6 +14,7 @@
14 * 14 *
15 */ 15 */
16 16
17#include <linux/io.h>
17#include <linux/kernel.h> 18#include <linux/kernel.h>
18#include <linux/module.h> 19#include <linux/module.h>
19#include <linux/platform_device.h> 20#include <linux/platform_device.h>
@@ -216,37 +217,34 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
216 struct jz4740_rtc *rtc; 217 struct jz4740_rtc *rtc;
217 uint32_t scratchpad; 218 uint32_t scratchpad;
218 219
219 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 220 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
220 if (!rtc) 221 if (!rtc)
221 return -ENOMEM; 222 return -ENOMEM;
222 223
223 rtc->irq = platform_get_irq(pdev, 0); 224 rtc->irq = platform_get_irq(pdev, 0);
224 if (rtc->irq < 0) { 225 if (rtc->irq < 0) {
225 ret = -ENOENT;
226 dev_err(&pdev->dev, "Failed to get platform irq\n"); 226 dev_err(&pdev->dev, "Failed to get platform irq\n");
227 goto err_free; 227 return -ENOENT;
228 } 228 }
229 229
230 rtc->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 230 rtc->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
231 if (!rtc->mem) { 231 if (!rtc->mem) {
232 ret = -ENOENT;
233 dev_err(&pdev->dev, "Failed to get platform mmio memory\n"); 232 dev_err(&pdev->dev, "Failed to get platform mmio memory\n");
234 goto err_free; 233 return -ENOENT;
235 } 234 }
236 235
237 rtc->mem = request_mem_region(rtc->mem->start, resource_size(rtc->mem), 236 rtc->mem = devm_request_mem_region(&pdev->dev, rtc->mem->start,
238 pdev->name); 237 resource_size(rtc->mem), pdev->name);
239 if (!rtc->mem) { 238 if (!rtc->mem) {
240 ret = -EBUSY;
241 dev_err(&pdev->dev, "Failed to request mmio memory region\n"); 239 dev_err(&pdev->dev, "Failed to request mmio memory region\n");
242 goto err_free; 240 return -EBUSY;
243 } 241 }
244 242
245 rtc->base = ioremap_nocache(rtc->mem->start, resource_size(rtc->mem)); 243 rtc->base = devm_ioremap_nocache(&pdev->dev, rtc->mem->start,
244 resource_size(rtc->mem));
246 if (!rtc->base) { 245 if (!rtc->base) {
247 ret = -EBUSY;
248 dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); 246 dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
249 goto err_release_mem_region; 247 return -EBUSY;
250 } 248 }
251 249
252 spin_lock_init(&rtc->lock); 250 spin_lock_init(&rtc->lock);
@@ -255,19 +253,19 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
255 253
256 device_init_wakeup(&pdev->dev, 1); 254 device_init_wakeup(&pdev->dev, 1);
257 255
258 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &jz4740_rtc_ops, 256 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
259 THIS_MODULE); 257 &jz4740_rtc_ops, THIS_MODULE);
260 if (IS_ERR(rtc->rtc)) { 258 if (IS_ERR(rtc->rtc)) {
261 ret = PTR_ERR(rtc->rtc); 259 ret = PTR_ERR(rtc->rtc);
262 dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret); 260 dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret);
263 goto err_iounmap; 261 return ret;
264 } 262 }
265 263
266 ret = request_irq(rtc->irq, jz4740_rtc_irq, 0, 264 ret = devm_request_irq(&pdev->dev, rtc->irq, jz4740_rtc_irq, 0,
267 pdev->name, rtc); 265 pdev->name, rtc);
268 if (ret) { 266 if (ret) {
269 dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret); 267 dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret);
270 goto err_unregister_rtc; 268 return ret;
271 } 269 }
272 270
273 scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD); 271 scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD);
@@ -276,46 +274,13 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
276 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0); 274 ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0);
277 if (ret) { 275 if (ret) {
278 dev_err(&pdev->dev, "Could not write write to RTC registers\n"); 276 dev_err(&pdev->dev, "Could not write write to RTC registers\n");
279 goto err_free_irq; 277 return ret;
280 } 278 }
281 } 279 }
282 280
283 return 0; 281 return 0;
284
285err_free_irq:
286 free_irq(rtc->irq, rtc);
287err_unregister_rtc:
288 rtc_device_unregister(rtc->rtc);
289err_iounmap:
290 platform_set_drvdata(pdev, NULL);
291 iounmap(rtc->base);
292err_release_mem_region:
293 release_mem_region(rtc->mem->start, resource_size(rtc->mem));
294err_free:
295 kfree(rtc);
296
297 return ret;
298}
299
300static int jz4740_rtc_remove(struct platform_device *pdev)
301{
302 struct jz4740_rtc *rtc = platform_get_drvdata(pdev);
303
304 free_irq(rtc->irq, rtc);
305
306 rtc_device_unregister(rtc->rtc);
307
308 iounmap(rtc->base);
309 release_mem_region(rtc->mem->start, resource_size(rtc->mem));
310
311 kfree(rtc);
312
313 platform_set_drvdata(pdev, NULL);
314
315 return 0;
316} 282}
317 283
318
319#ifdef CONFIG_PM 284#ifdef CONFIG_PM
320static int jz4740_rtc_suspend(struct device *dev) 285static int jz4740_rtc_suspend(struct device *dev)
321{ 286{
@@ -347,7 +312,6 @@ static const struct dev_pm_ops jz4740_pm_ops = {
347 312
348static struct platform_driver jz4740_rtc_driver = { 313static struct platform_driver jz4740_rtc_driver = {
349 .probe = jz4740_rtc_probe, 314 .probe = jz4740_rtc_probe,
350 .remove = jz4740_rtc_remove,
351 .driver = { 315 .driver = {
352 .name = "jz4740-rtc", 316 .name = "jz4740-rtc",
353 .owner = THIS_MODULE, 317 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-lp8788.c b/drivers/rtc/rtc-lp8788.c
index 9853ac15b296..4ff6c73253b3 100644
--- a/drivers/rtc/rtc-lp8788.c
+++ b/drivers/rtc/rtc-lp8788.c
@@ -312,16 +312,8 @@ static int lp8788_rtc_probe(struct platform_device *pdev)
312 return 0; 312 return 0;
313} 313}
314 314
315static int lp8788_rtc_remove(struct platform_device *pdev)
316{
317 platform_set_drvdata(pdev, NULL);
318
319 return 0;
320}
321
322static struct platform_driver lp8788_rtc_driver = { 315static struct platform_driver lp8788_rtc_driver = {
323 .probe = lp8788_rtc_probe, 316 .probe = lp8788_rtc_probe,
324 .remove = lp8788_rtc_remove,
325 .driver = { 317 .driver = {
326 .name = LP8788_DEV_RTC, 318 .name = LP8788_DEV_RTC,
327 .owner = THIS_MODULE, 319 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c
index 787550d756e9..8276ae94a2a9 100644
--- a/drivers/rtc/rtc-lpc32xx.c
+++ b/drivers/rtc/rtc-lpc32xx.c
@@ -277,7 +277,6 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
277 &lpc32xx_rtc_ops, THIS_MODULE); 277 &lpc32xx_rtc_ops, THIS_MODULE);
278 if (IS_ERR(rtc->rtc)) { 278 if (IS_ERR(rtc->rtc)) {
279 dev_err(&pdev->dev, "Can't get RTC\n"); 279 dev_err(&pdev->dev, "Can't get RTC\n");
280 platform_set_drvdata(pdev, NULL);
281 return PTR_ERR(rtc->rtc); 280 return PTR_ERR(rtc->rtc);
282 } 281 }
283 282
@@ -306,8 +305,6 @@ static int lpc32xx_rtc_remove(struct platform_device *pdev)
306 if (rtc->irq >= 0) 305 if (rtc->irq >= 0)
307 device_init_wakeup(&pdev->dev, 0); 306 device_init_wakeup(&pdev->dev, 0);
308 307
309 platform_set_drvdata(pdev, NULL);
310
311 return 0; 308 return 0;
312} 309}
313 310
diff --git a/drivers/rtc/rtc-ls1x.c b/drivers/rtc/rtc-ls1x.c
index db82f91f4562..682ecb094839 100644
--- a/drivers/rtc/rtc-ls1x.c
+++ b/drivers/rtc/rtc-ls1x.c
@@ -185,19 +185,11 @@ err:
185 return ret; 185 return ret;
186} 186}
187 187
188static int ls1x_rtc_remove(struct platform_device *pdev)
189{
190 platform_set_drvdata(pdev, NULL);
191
192 return 0;
193}
194
195static struct platform_driver ls1x_rtc_driver = { 188static struct platform_driver ls1x_rtc_driver = {
196 .driver = { 189 .driver = {
197 .name = "ls1x-rtc", 190 .name = "ls1x-rtc",
198 .owner = THIS_MODULE, 191 .owner = THIS_MODULE,
199 }, 192 },
200 .remove = ls1x_rtc_remove,
201 .probe = ls1x_rtc_probe, 193 .probe = ls1x_rtc_probe,
202}; 194};
203 195
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index 89674b5e6efd..a5248aa1abf1 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -168,7 +168,7 @@ static int m41t80_set_datetime(struct i2c_client *client, struct rtc_time *tm)
168 buf[M41T80_REG_MIN] = 168 buf[M41T80_REG_MIN] =
169 bin2bcd(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f); 169 bin2bcd(tm->tm_min) | (buf[M41T80_REG_MIN] & ~0x7f);
170 buf[M41T80_REG_HOUR] = 170 buf[M41T80_REG_HOUR] =
171 bin2bcd(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f) ; 171 bin2bcd(tm->tm_hour) | (buf[M41T80_REG_HOUR] & ~0x3f);
172 buf[M41T80_REG_WDAY] = 172 buf[M41T80_REG_WDAY] =
173 (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07); 173 (tm->tm_wday & 0x07) | (buf[M41T80_REG_WDAY] & ~0x07);
174 buf[M41T80_REG_DAY] = 174 buf[M41T80_REG_DAY] =
diff --git a/drivers/rtc/rtc-m41t93.c b/drivers/rtc/rtc-m41t93.c
index 9707d36e8b15..4698c7e344e4 100644
--- a/drivers/rtc/rtc-m41t93.c
+++ b/drivers/rtc/rtc-m41t93.c
@@ -194,19 +194,12 @@ static int m41t93_probe(struct spi_device *spi)
194 return 0; 194 return 0;
195} 195}
196 196
197
198static int m41t93_remove(struct spi_device *spi)
199{
200 return 0;
201}
202
203static struct spi_driver m41t93_driver = { 197static struct spi_driver m41t93_driver = {
204 .driver = { 198 .driver = {
205 .name = "rtc-m41t93", 199 .name = "rtc-m41t93",
206 .owner = THIS_MODULE, 200 .owner = THIS_MODULE,
207 }, 201 },
208 .probe = m41t93_probe, 202 .probe = m41t93_probe,
209 .remove = m41t93_remove,
210}; 203};
211 204
212module_spi_driver(m41t93_driver); 205module_spi_driver(m41t93_driver);
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c
index 7454ef0a4cfa..8d800b1bf87b 100644
--- a/drivers/rtc/rtc-m41t94.c
+++ b/drivers/rtc/rtc-m41t94.c
@@ -134,18 +134,12 @@ static int m41t94_probe(struct spi_device *spi)
134 return 0; 134 return 0;
135} 135}
136 136
137static int m41t94_remove(struct spi_device *spi)
138{
139 return 0;
140}
141
142static struct spi_driver m41t94_driver = { 137static struct spi_driver m41t94_driver = {
143 .driver = { 138 .driver = {
144 .name = "rtc-m41t94", 139 .name = "rtc-m41t94",
145 .owner = THIS_MODULE, 140 .owner = THIS_MODULE,
146 }, 141 },
147 .probe = m41t94_probe, 142 .probe = m41t94_probe,
148 .remove = m41t94_remove,
149}; 143};
150 144
151module_spi_driver(m41t94_driver); 145module_spi_driver(m41t94_driver);
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
index 37444246e5e4..23c3779a5f2b 100644
--- a/drivers/rtc/rtc-m48t35.c
+++ b/drivers/rtc/rtc-m48t35.c
@@ -20,6 +20,7 @@
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/bcd.h> 21#include <linux/bcd.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/err.h>
23 24
24#define DRV_VERSION "1.0" 25#define DRV_VERSION "1.0"
25 26
@@ -174,15 +175,7 @@ static int m48t35_probe(struct platform_device *pdev)
174 175
175 priv->rtc = devm_rtc_device_register(&pdev->dev, "m48t35", 176 priv->rtc = devm_rtc_device_register(&pdev->dev, "m48t35",
176 &m48t35_ops, THIS_MODULE); 177 &m48t35_ops, THIS_MODULE);
177 if (IS_ERR(priv->rtc)) 178 return PTR_RET(priv->rtc);
178 return PTR_ERR(priv->rtc);
179
180 return 0;
181}
182
183static int m48t35_remove(struct platform_device *pdev)
184{
185 return 0;
186} 179}
187 180
188static struct platform_driver m48t35_platform_driver = { 181static struct platform_driver m48t35_platform_driver = {
@@ -191,7 +184,6 @@ static struct platform_driver m48t35_platform_driver = {
191 .owner = THIS_MODULE, 184 .owner = THIS_MODULE,
192 }, 185 },
193 .probe = m48t35_probe, 186 .probe = m48t35_probe,
194 .remove = m48t35_remove,
195}; 187};
196 188
197module_platform_driver(m48t35_platform_driver); 189module_platform_driver(m48t35_platform_driver);
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index 130f29af3869..fcb03291f145 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -409,7 +409,8 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
409 } else if (res->flags & IORESOURCE_MEM) { 409 } else if (res->flags & IORESOURCE_MEM) {
410 /* we are memory-mapped */ 410 /* we are memory-mapped */
411 if (!pdata) { 411 if (!pdata) {
412 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 412 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata),
413 GFP_KERNEL);
413 if (!pdata) 414 if (!pdata)
414 return -ENOMEM; 415 return -ENOMEM;
415 /* Ensure we only kmalloc platform data once */ 416 /* Ensure we only kmalloc platform data once */
@@ -425,7 +426,7 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
425 pdata->read_byte = m48t59_mem_readb; 426 pdata->read_byte = m48t59_mem_readb;
426 } 427 }
427 428
428 m48t59 = kzalloc(sizeof(*m48t59), GFP_KERNEL); 429 m48t59 = devm_kzalloc(&pdev->dev, sizeof(*m48t59), GFP_KERNEL);
429 if (!m48t59) 430 if (!m48t59)
430 return -ENOMEM; 431 return -ENOMEM;
431 432
@@ -433,9 +434,10 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
433 434
434 if (!m48t59->ioaddr) { 435 if (!m48t59->ioaddr) {
435 /* ioaddr not mapped externally */ 436 /* ioaddr not mapped externally */
436 m48t59->ioaddr = ioremap(res->start, resource_size(res)); 437 m48t59->ioaddr = devm_ioremap(&pdev->dev, res->start,
438 resource_size(res));
437 if (!m48t59->ioaddr) 439 if (!m48t59->ioaddr)
438 goto out; 440 return ret;
439 } 441 }
440 442
441 /* Try to get irq number. We also can work in 443 /* Try to get irq number. We also can work in
@@ -446,10 +448,11 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
446 m48t59->irq = NO_IRQ; 448 m48t59->irq = NO_IRQ;
447 449
448 if (m48t59->irq != NO_IRQ) { 450 if (m48t59->irq != NO_IRQ) {
449 ret = request_irq(m48t59->irq, m48t59_rtc_interrupt, 451 ret = devm_request_irq(&pdev->dev, m48t59->irq,
450 IRQF_SHARED, "rtc-m48t59", &pdev->dev); 452 m48t59_rtc_interrupt, IRQF_SHARED,
453 "rtc-m48t59", &pdev->dev);
451 if (ret) 454 if (ret)
452 goto out; 455 return ret;
453 } 456 }
454 switch (pdata->type) { 457 switch (pdata->type) {
455 case M48T59RTC_TYPE_M48T59: 458 case M48T59RTC_TYPE_M48T59:
@@ -469,52 +472,29 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
469 break; 472 break;
470 default: 473 default:
471 dev_err(&pdev->dev, "Unknown RTC type\n"); 474 dev_err(&pdev->dev, "Unknown RTC type\n");
472 ret = -ENODEV; 475 return -ENODEV;
473 goto out;
474 } 476 }
475 477
476 spin_lock_init(&m48t59->lock); 478 spin_lock_init(&m48t59->lock);
477 platform_set_drvdata(pdev, m48t59); 479 platform_set_drvdata(pdev, m48t59);
478 480
479 m48t59->rtc = rtc_device_register(name, &pdev->dev, ops, THIS_MODULE); 481 m48t59->rtc = devm_rtc_device_register(&pdev->dev, name, ops,
480 if (IS_ERR(m48t59->rtc)) { 482 THIS_MODULE);
481 ret = PTR_ERR(m48t59->rtc); 483 if (IS_ERR(m48t59->rtc))
482 goto out; 484 return PTR_ERR(m48t59->rtc);
483 }
484 485
485 m48t59_nvram_attr.size = pdata->offset; 486 m48t59_nvram_attr.size = pdata->offset;
486 487
487 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 488 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
488 if (ret) { 489 if (ret)
489 rtc_device_unregister(m48t59->rtc); 490 return ret;
490 goto out;
491 }
492 491
493 return 0; 492 return 0;
494
495out:
496 if (m48t59->irq != NO_IRQ)
497 free_irq(m48t59->irq, &pdev->dev);
498 if (m48t59->ioaddr)
499 iounmap(m48t59->ioaddr);
500 kfree(m48t59);
501 return ret;
502} 493}
503 494
504static int m48t59_rtc_remove(struct platform_device *pdev) 495static int m48t59_rtc_remove(struct platform_device *pdev)
505{ 496{
506 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
507 struct m48t59_plat_data *pdata = pdev->dev.platform_data;
508
509 sysfs_remove_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 497 sysfs_remove_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
510 if (!IS_ERR(m48t59->rtc))
511 rtc_device_unregister(m48t59->rtc);
512 if (m48t59->ioaddr && !pdata->ioaddr)
513 iounmap(m48t59->ioaddr);
514 if (m48t59->irq != NO_IRQ)
515 free_irq(m48t59->irq, &pdev->dev);
516 platform_set_drvdata(pdev, NULL);
517 kfree(m48t59);
518 return 0; 498 return 0;
519} 499}
520 500
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 33a91c484533..2d30314fa07f 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -166,20 +166,12 @@ static int m48t86_rtc_probe(struct platform_device *dev)
166 return 0; 166 return 0;
167} 167}
168 168
169static int m48t86_rtc_remove(struct platform_device *dev)
170{
171 platform_set_drvdata(dev, NULL);
172
173 return 0;
174}
175
176static struct platform_driver m48t86_rtc_platform_driver = { 169static struct platform_driver m48t86_rtc_platform_driver = {
177 .driver = { 170 .driver = {
178 .name = "rtc-m48t86", 171 .name = "rtc-m48t86",
179 .owner = THIS_MODULE, 172 .owner = THIS_MODULE,
180 }, 173 },
181 .probe = m48t86_rtc_probe, 174 .probe = m48t86_rtc_probe,
182 .remove = m48t86_rtc_remove,
183}; 175};
184 176
185module_platform_driver(m48t86_rtc_platform_driver); 177module_platform_driver(m48t86_rtc_platform_driver);
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index 8669d6d09a00..55969b1b771a 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -212,11 +212,6 @@ static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
212 return max6900_i2c_set_time(to_i2c_client(dev), tm); 212 return max6900_i2c_set_time(to_i2c_client(dev), tm);
213} 213}
214 214
215static int max6900_remove(struct i2c_client *client)
216{
217 return 0;
218}
219
220static const struct rtc_class_ops max6900_rtc_ops = { 215static const struct rtc_class_ops max6900_rtc_ops = {
221 .read_time = max6900_rtc_read_time, 216 .read_time = max6900_rtc_read_time,
222 .set_time = max6900_rtc_set_time, 217 .set_time = max6900_rtc_set_time,
@@ -252,7 +247,6 @@ static struct i2c_driver max6900_driver = {
252 .name = "rtc-max6900", 247 .name = "rtc-max6900",
253 }, 248 },
254 .probe = max6900_probe, 249 .probe = max6900_probe,
255 .remove = max6900_remove,
256 .id_table = max6900_id, 250 .id_table = max6900_id,
257}; 251};
258 252
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index e3aea00c3145..ac3f4191864f 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -143,23 +143,17 @@ static int max6902_probe(struct spi_device *spi)
143 return 0; 143 return 0;
144} 144}
145 145
146static int max6902_remove(struct spi_device *spi)
147{
148 return 0;
149}
150
151static struct spi_driver max6902_driver = { 146static struct spi_driver max6902_driver = {
152 .driver = { 147 .driver = {
153 .name = "rtc-max6902", 148 .name = "rtc-max6902",
154 .owner = THIS_MODULE, 149 .owner = THIS_MODULE,
155 }, 150 },
156 .probe = max6902_probe, 151 .probe = max6902_probe,
157 .remove = max6902_remove,
158}; 152};
159 153
160module_spi_driver(max6902_driver); 154module_spi_driver(max6902_driver);
161 155
162MODULE_DESCRIPTION ("max6902 spi RTC driver"); 156MODULE_DESCRIPTION("max6902 spi RTC driver");
163MODULE_AUTHOR ("Raphael Assenat"); 157MODULE_AUTHOR("Raphael Assenat");
164MODULE_LICENSE ("GPL"); 158MODULE_LICENSE("GPL");
165MODULE_ALIAS("spi:rtc-max6902"); 159MODULE_ALIAS("spi:rtc-max6902");
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 771812d62e6b..9915cb96014b 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -119,7 +119,7 @@ static int max77686_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
119 data[RTC_WEEKDAY] = 1 << tm->tm_wday; 119 data[RTC_WEEKDAY] = 1 << tm->tm_wday;
120 data[RTC_DATE] = tm->tm_mday; 120 data[RTC_DATE] = tm->tm_mday;
121 data[RTC_MONTH] = tm->tm_mon + 1; 121 data[RTC_MONTH] = tm->tm_mon + 1;
122 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0 ; 122 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
123 123
124 if (tm->tm_year < 100) { 124 if (tm->tm_year < 100) {
125 pr_warn("%s: MAX77686 RTC cannot handle the year %d." 125 pr_warn("%s: MAX77686 RTC cannot handle the year %d."
@@ -567,11 +567,6 @@ err_rtc:
567 return ret; 567 return ret;
568} 568}
569 569
570static int max77686_rtc_remove(struct platform_device *pdev)
571{
572 return 0;
573}
574
575static void max77686_rtc_shutdown(struct platform_device *pdev) 570static void max77686_rtc_shutdown(struct platform_device *pdev)
576{ 571{
577#ifdef MAX77686_RTC_WTSR_SMPL 572#ifdef MAX77686_RTC_WTSR_SMPL
@@ -610,7 +605,6 @@ static struct platform_driver max77686_rtc_driver = {
610 .owner = THIS_MODULE, 605 .owner = THIS_MODULE,
611 }, 606 },
612 .probe = max77686_rtc_probe, 607 .probe = max77686_rtc_probe,
613 .remove = max77686_rtc_remove,
614 .shutdown = max77686_rtc_shutdown, 608 .shutdown = max77686_rtc_shutdown,
615 .id_table = rtc_id, 609 .id_table = rtc_id,
616}; 610};
diff --git a/drivers/rtc/rtc-max8907.c b/drivers/rtc/rtc-max8907.c
index 86afb797125d..8e45b3c4aa2f 100644
--- a/drivers/rtc/rtc-max8907.c
+++ b/drivers/rtc/rtc-max8907.c
@@ -213,18 +213,12 @@ static int max8907_rtc_probe(struct platform_device *pdev)
213 return ret; 213 return ret;
214} 214}
215 215
216static int max8907_rtc_remove(struct platform_device *pdev)
217{
218 return 0;
219}
220
221static struct platform_driver max8907_rtc_driver = { 216static struct platform_driver max8907_rtc_driver = {
222 .driver = { 217 .driver = {
223 .name = "max8907-rtc", 218 .name = "max8907-rtc",
224 .owner = THIS_MODULE, 219 .owner = THIS_MODULE,
225 }, 220 },
226 .probe = max8907_rtc_probe, 221 .probe = max8907_rtc_probe,
227 .remove = max8907_rtc_remove,
228}; 222};
229module_platform_driver(max8907_rtc_driver); 223module_platform_driver(max8907_rtc_driver);
230 224
diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c
index 7c90f4e45e27..951d1a78e190 100644
--- a/drivers/rtc/rtc-max8925.c
+++ b/drivers/rtc/rtc-max8925.c
@@ -268,7 +268,7 @@ static int max8925_rtc_probe(struct platform_device *pdev)
268 if (ret < 0) { 268 if (ret < 0) {
269 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", 269 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
270 info->irq, ret); 270 info->irq, ret);
271 goto err; 271 return ret;
272 } 272 }
273 273
274 dev_set_drvdata(&pdev->dev, info); 274 dev_set_drvdata(&pdev->dev, info);
@@ -282,18 +282,10 @@ static int max8925_rtc_probe(struct platform_device *pdev)
282 ret = PTR_ERR(info->rtc_dev); 282 ret = PTR_ERR(info->rtc_dev);
283 if (IS_ERR(info->rtc_dev)) { 283 if (IS_ERR(info->rtc_dev)) {
284 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 284 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
285 goto err; 285 return ret;
286 } 286 }
287 287
288 return 0; 288 return 0;
289err:
290 platform_set_drvdata(pdev, NULL);
291 return ret;
292}
293
294static int max8925_rtc_remove(struct platform_device *pdev)
295{
296 return 0;
297} 289}
298 290
299#ifdef CONFIG_PM_SLEEP 291#ifdef CONFIG_PM_SLEEP
@@ -326,7 +318,6 @@ static struct platform_driver max8925_rtc_driver = {
326 .pm = &max8925_rtc_pm_ops, 318 .pm = &max8925_rtc_pm_ops,
327 }, 319 },
328 .probe = max8925_rtc_probe, 320 .probe = max8925_rtc_probe,
329 .remove = max8925_rtc_remove,
330}; 321};
331 322
332module_platform_driver(max8925_rtc_driver); 323module_platform_driver(max8925_rtc_driver);
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
index dacf48db7925..0777c01b58e0 100644
--- a/drivers/rtc/rtc-max8997.c
+++ b/drivers/rtc/rtc-max8997.c
@@ -104,7 +104,7 @@ static int max8997_rtc_tm_to_data(struct rtc_time *tm, u8 *data)
104 data[RTC_WEEKDAY] = 1 << tm->tm_wday; 104 data[RTC_WEEKDAY] = 1 << tm->tm_wday;
105 data[RTC_DATE] = tm->tm_mday; 105 data[RTC_DATE] = tm->tm_mday;
106 data[RTC_MONTH] = tm->tm_mon + 1; 106 data[RTC_MONTH] = tm->tm_mon + 1;
107 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0 ; 107 data[RTC_YEAR] = tm->tm_year > 100 ? (tm->tm_year - 100) : 0;
108 108
109 if (tm->tm_year < 100) { 109 if (tm->tm_year < 100) {
110 pr_warn("%s: MAX8997 RTC cannot handle the year %d." 110 pr_warn("%s: MAX8997 RTC cannot handle the year %d."
@@ -507,11 +507,6 @@ err_out:
507 return ret; 507 return ret;
508} 508}
509 509
510static int max8997_rtc_remove(struct platform_device *pdev)
511{
512 return 0;
513}
514
515static void max8997_rtc_shutdown(struct platform_device *pdev) 510static void max8997_rtc_shutdown(struct platform_device *pdev)
516{ 511{
517 struct max8997_rtc_info *info = platform_get_drvdata(pdev); 512 struct max8997_rtc_info *info = platform_get_drvdata(pdev);
@@ -531,7 +526,6 @@ static struct platform_driver max8997_rtc_driver = {
531 .owner = THIS_MODULE, 526 .owner = THIS_MODULE,
532 }, 527 },
533 .probe = max8997_rtc_probe, 528 .probe = max8997_rtc_probe,
534 .remove = max8997_rtc_remove,
535 .shutdown = max8997_rtc_shutdown, 529 .shutdown = max8997_rtc_shutdown,
536 .id_table = rtc_id, 530 .id_table = rtc_id,
537}; 531};
diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c
index d5af7baa48b5..5388336a2c4c 100644
--- a/drivers/rtc/rtc-max8998.c
+++ b/drivers/rtc/rtc-max8998.c
@@ -274,7 +274,7 @@ static int max8998_rtc_probe(struct platform_device *pdev)
274 if (IS_ERR(info->rtc_dev)) { 274 if (IS_ERR(info->rtc_dev)) {
275 ret = PTR_ERR(info->rtc_dev); 275 ret = PTR_ERR(info->rtc_dev);
276 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 276 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
277 goto out_rtc; 277 return ret;
278 } 278 }
279 279
280 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL, 280 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
@@ -292,15 +292,6 @@ static int max8998_rtc_probe(struct platform_device *pdev)
292 } 292 }
293 293
294 return 0; 294 return 0;
295
296out_rtc:
297 platform_set_drvdata(pdev, NULL);
298 return ret;
299}
300
301static int max8998_rtc_remove(struct platform_device *pdev)
302{
303 return 0;
304} 295}
305 296
306static const struct platform_device_id max8998_rtc_id[] = { 297static const struct platform_device_id max8998_rtc_id[] = {
@@ -315,7 +306,6 @@ static struct platform_driver max8998_rtc_driver = {
315 .owner = THIS_MODULE, 306 .owner = THIS_MODULE,
316 }, 307 },
317 .probe = max8998_rtc_probe, 308 .probe = max8998_rtc_probe,
318 .remove = max8998_rtc_remove,
319 .id_table = max8998_rtc_id, 309 .id_table = max8998_rtc_id,
320}; 310};
321 311
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c
index 7a8ed27a5f2e..77ea9896b5ba 100644
--- a/drivers/rtc/rtc-mc13xxx.c
+++ b/drivers/rtc/rtc-mc13xxx.c
@@ -370,8 +370,6 @@ err_reset_irq_status:
370err_reset_irq_request: 370err_reset_irq_request:
371 371
372 mc13xxx_unlock(mc13xxx); 372 mc13xxx_unlock(mc13xxx);
373
374 platform_set_drvdata(pdev, NULL);
375 } 373 }
376 374
377 return ret; 375 return ret;
@@ -389,8 +387,6 @@ static int __exit mc13xxx_rtc_remove(struct platform_device *pdev)
389 387
390 mc13xxx_unlock(priv->mc13xxx); 388 mc13xxx_unlock(priv->mc13xxx);
391 389
392 platform_set_drvdata(pdev, NULL);
393
394 return 0; 390 return 0;
395} 391}
396 392
diff --git a/drivers/rtc/rtc-mpc5121.c b/drivers/rtc/rtc-mpc5121.c
index bdcc60830aec..9c8f60903799 100644
--- a/drivers/rtc/rtc-mpc5121.c
+++ b/drivers/rtc/rtc-mpc5121.c
@@ -68,7 +68,7 @@ struct mpc5121_rtc_regs {
68 u32 target_time; /* RTC + 0x20 */ 68 u32 target_time; /* RTC + 0x20 */
69 /* 69 /*
70 * actual_time: 70 * actual_time:
71 * readonly time since VBAT_RTC was last connected 71 * readonly time since VBAT_RTC was last connected
72 */ 72 */
73 u32 actual_time; /* RTC + 0x24 */ 73 u32 actual_time; /* RTC + 0x24 */
74 u32 keep_alive; /* RTC + 0x28 */ 74 u32 keep_alive; /* RTC + 0x28 */
@@ -312,20 +312,19 @@ static int mpc5121_rtc_probe(struct platform_device *op)
312 struct mpc5121_rtc_data *rtc; 312 struct mpc5121_rtc_data *rtc;
313 int err = 0; 313 int err = 0;
314 314
315 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 315 rtc = devm_kzalloc(&op->dev, sizeof(*rtc), GFP_KERNEL);
316 if (!rtc) 316 if (!rtc)
317 return -ENOMEM; 317 return -ENOMEM;
318 318
319 rtc->regs = of_iomap(op->dev.of_node, 0); 319 rtc->regs = of_iomap(op->dev.of_node, 0);
320 if (!rtc->regs) { 320 if (!rtc->regs) {
321 dev_err(&op->dev, "%s: couldn't map io space\n", __func__); 321 dev_err(&op->dev, "%s: couldn't map io space\n", __func__);
322 err = -ENOSYS; 322 return -ENOSYS;
323 goto out_free;
324 } 323 }
325 324
326 device_init_wakeup(&op->dev, 1); 325 device_init_wakeup(&op->dev, 1);
327 326
328 dev_set_drvdata(&op->dev, rtc); 327 platform_set_drvdata(op, rtc);
329 328
330 rtc->irq = irq_of_parse_and_map(op->dev.of_node, 1); 329 rtc->irq = irq_of_parse_and_map(op->dev.of_node, 1);
331 err = request_irq(rtc->irq, mpc5121_rtc_handler, 0, 330 err = request_irq(rtc->irq, mpc5121_rtc_handler, 0,
@@ -354,10 +353,10 @@ static int mpc5121_rtc_probe(struct platform_device *op)
354 out_be32(&rtc->regs->keep_alive, ka); 353 out_be32(&rtc->regs->keep_alive, ka);
355 } 354 }
356 355
357 rtc->rtc = rtc_device_register("mpc5121-rtc", &op->dev, 356 rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5121-rtc",
358 &mpc5121_rtc_ops, THIS_MODULE); 357 &mpc5121_rtc_ops, THIS_MODULE);
359 } else { 358 } else {
360 rtc->rtc = rtc_device_register("mpc5200-rtc", &op->dev, 359 rtc->rtc = devm_rtc_device_register(&op->dev, "mpc5200-rtc",
361 &mpc5200_rtc_ops, THIS_MODULE); 360 &mpc5200_rtc_ops, THIS_MODULE);
362 } 361 }
363 362
@@ -377,29 +376,24 @@ out_dispose2:
377out_dispose: 376out_dispose:
378 irq_dispose_mapping(rtc->irq); 377 irq_dispose_mapping(rtc->irq);
379 iounmap(rtc->regs); 378 iounmap(rtc->regs);
380out_free:
381 kfree(rtc);
382 379
383 return err; 380 return err;
384} 381}
385 382
386static int mpc5121_rtc_remove(struct platform_device *op) 383static int mpc5121_rtc_remove(struct platform_device *op)
387{ 384{
388 struct mpc5121_rtc_data *rtc = dev_get_drvdata(&op->dev); 385 struct mpc5121_rtc_data *rtc = platform_get_drvdata(op);
389 struct mpc5121_rtc_regs __iomem *regs = rtc->regs; 386 struct mpc5121_rtc_regs __iomem *regs = rtc->regs;
390 387
391 /* disable interrupt, so there are no nasty surprises */ 388 /* disable interrupt, so there are no nasty surprises */
392 out_8(&regs->alm_enable, 0); 389 out_8(&regs->alm_enable, 0);
393 out_8(&regs->int_enable, in_8(&regs->int_enable) & ~0x1); 390 out_8(&regs->int_enable, in_8(&regs->int_enable) & ~0x1);
394 391
395 rtc_device_unregister(rtc->rtc);
396 iounmap(rtc->regs); 392 iounmap(rtc->regs);
397 free_irq(rtc->irq, &op->dev); 393 free_irq(rtc->irq, &op->dev);
398 free_irq(rtc->irq_periodic, &op->dev); 394 free_irq(rtc->irq_periodic, &op->dev);
399 irq_dispose_mapping(rtc->irq); 395 irq_dispose_mapping(rtc->irq);
400 irq_dispose_mapping(rtc->irq_periodic); 396 irq_dispose_mapping(rtc->irq_periodic);
401 dev_set_drvdata(&op->dev, NULL);
402 kfree(rtc);
403 397
404 return 0; 398 return 0;
405} 399}
diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c
index 771f86a05d14..426cb5189daa 100644
--- a/drivers/rtc/rtc-msm6242.c
+++ b/drivers/rtc/rtc-msm6242.c
@@ -111,8 +111,8 @@ static void msm6242_lock(struct msm6242_priv *priv)
111 } 111 }
112 112
113 if (!cnt) 113 if (!cnt)
114 pr_warning("msm6242: timed out waiting for RTC (0x%x)\n", 114 pr_warn("msm6242: timed out waiting for RTC (0x%x)\n",
115 msm6242_read(priv, MSM6242_CD)); 115 msm6242_read(priv, MSM6242_CD));
116} 116}
117 117
118static void msm6242_unlock(struct msm6242_priv *priv) 118static void msm6242_unlock(struct msm6242_priv *priv)
@@ -199,7 +199,6 @@ static int __init msm6242_rtc_probe(struct platform_device *pdev)
199 struct resource *res; 199 struct resource *res;
200 struct msm6242_priv *priv; 200 struct msm6242_priv *priv;
201 struct rtc_device *rtc; 201 struct rtc_device *rtc;
202 int error;
203 202
204 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 203 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
205 if (!res) 204 if (!res)
@@ -216,22 +215,11 @@ static int __init msm6242_rtc_probe(struct platform_device *pdev)
216 215
217 rtc = devm_rtc_device_register(&pdev->dev, "rtc-msm6242", 216 rtc = devm_rtc_device_register(&pdev->dev, "rtc-msm6242",
218 &msm6242_rtc_ops, THIS_MODULE); 217 &msm6242_rtc_ops, THIS_MODULE);
219 if (IS_ERR(rtc)) { 218 if (IS_ERR(rtc))
220 error = PTR_ERR(rtc); 219 return PTR_ERR(rtc);
221 goto out_unmap;
222 }
223 220
224 priv->rtc = rtc; 221 priv->rtc = rtc;
225 return 0; 222 return 0;
226
227out_unmap:
228 platform_set_drvdata(pdev, NULL);
229 return error;
230}
231
232static int __exit msm6242_rtc_remove(struct platform_device *pdev)
233{
234 return 0;
235} 223}
236 224
237static struct platform_driver msm6242_rtc_driver = { 225static struct platform_driver msm6242_rtc_driver = {
@@ -239,7 +227,6 @@ static struct platform_driver msm6242_rtc_driver = {
239 .name = "rtc-msm6242", 227 .name = "rtc-msm6242",
240 .owner = THIS_MODULE, 228 .owner = THIS_MODULE,
241 }, 229 },
242 .remove = __exit_p(msm6242_rtc_remove),
243}; 230};
244 231
245module_platform_driver_probe(msm6242_rtc_driver, msm6242_rtc_probe); 232module_platform_driver_probe(msm6242_rtc_driver, msm6242_rtc_probe);
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 9a3895bc4f4d..ab87bacb8f88 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -436,22 +436,20 @@ static int mxc_rtc_probe(struct platform_device *pdev)
436 pdata->irq = -1; 436 pdata->irq = -1;
437 } 437 }
438 438
439 if (pdata->irq >=0) 439 if (pdata->irq >= 0)
440 device_init_wakeup(&pdev->dev, 1); 440 device_init_wakeup(&pdev->dev, 1);
441 441
442 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops, 442 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &mxc_rtc_ops,
443 THIS_MODULE); 443 THIS_MODULE);
444 if (IS_ERR(rtc)) { 444 if (IS_ERR(rtc)) {
445 ret = PTR_ERR(rtc); 445 ret = PTR_ERR(rtc);
446 goto exit_clr_drvdata; 446 goto exit_put_clk;
447 } 447 }
448 448
449 pdata->rtc = rtc; 449 pdata->rtc = rtc;
450 450
451 return 0; 451 return 0;
452 452
453exit_clr_drvdata:
454 platform_set_drvdata(pdev, NULL);
455exit_put_clk: 453exit_put_clk:
456 clk_disable_unprepare(pdata->clk); 454 clk_disable_unprepare(pdata->clk);
457 455
@@ -465,7 +463,6 @@ static int mxc_rtc_remove(struct platform_device *pdev)
465 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 463 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
466 464
467 clk_disable_unprepare(pdata->clk); 465 clk_disable_unprepare(pdata->clk);
468 platform_set_drvdata(pdev, NULL);
469 466
470 return 0; 467 return 0;
471} 468}
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
index d592e2fe43f7..22861c5e0c59 100644
--- a/drivers/rtc/rtc-nuc900.c
+++ b/drivers/rtc/rtc-nuc900.c
@@ -260,15 +260,7 @@ static int __init nuc900_rtc_probe(struct platform_device *pdev)
260 return 0; 260 return 0;
261} 261}
262 262
263static int __exit nuc900_rtc_remove(struct platform_device *pdev)
264{
265 platform_set_drvdata(pdev, NULL);
266
267 return 0;
268}
269
270static struct platform_driver nuc900_rtc_driver = { 263static struct platform_driver nuc900_rtc_driver = {
271 .remove = __exit_p(nuc900_rtc_remove),
272 .driver = { 264 .driver = {
273 .name = "nuc900-rtc", 265 .name = "nuc900-rtc",
274 .owner = THIS_MODULE, 266 .owner = THIS_MODULE,
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index b0ba3fc991ea..c6ffbaec32a4 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -23,9 +23,7 @@
23#include <linux/of.h> 23#include <linux/of.h>
24#include <linux/of_device.h> 24#include <linux/of_device.h>
25#include <linux/pm_runtime.h> 25#include <linux/pm_runtime.h>
26 26#include <linux/io.h>
27#include <asm/io.h>
28
29 27
30/* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock 28/* The OMAP1 RTC is a year/month/day/hours/minutes/seconds BCD clock
31 * with century-range alarm matching, driven by the 32kHz clock. 29 * with century-range alarm matching, driven by the 32kHz clock.
@@ -423,6 +421,8 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
423 * is write-only, and always reads as zero...) 421 * is write-only, and always reads as zero...)
424 */ 422 */
425 423
424 device_init_wakeup(&pdev->dev, true);
425
426 if (new_ctrl & (u8) OMAP_RTC_CTRL_SPLIT) 426 if (new_ctrl & (u8) OMAP_RTC_CTRL_SPLIT)
427 pr_info("%s: split power mode\n", pdev->name); 427 pr_info("%s: split power mode\n", pdev->name);
428 428
diff --git a/drivers/rtc/rtc-palmas.c b/drivers/rtc/rtc-palmas.c
index 50204d474eb7..a1fecc8d97fc 100644
--- a/drivers/rtc/rtc-palmas.c
+++ b/drivers/rtc/rtc-palmas.c
@@ -265,6 +265,7 @@ static int palmas_rtc_probe(struct platform_device *pdev)
265 265
266 palmas_rtc->irq = platform_get_irq(pdev, 0); 266 palmas_rtc->irq = platform_get_irq(pdev, 0);
267 267
268 device_init_wakeup(&pdev->dev, 1);
268 palmas_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 269 palmas_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
269 &palmas_rtc_ops, THIS_MODULE); 270 &palmas_rtc_ops, THIS_MODULE);
270 if (IS_ERR(palmas_rtc->rtc)) { 271 if (IS_ERR(palmas_rtc->rtc)) {
@@ -283,7 +284,6 @@ static int palmas_rtc_probe(struct platform_device *pdev)
283 return ret; 284 return ret;
284 } 285 }
285 286
286 device_set_wakeup_capable(&pdev->dev, 1);
287 return 0; 287 return 0;
288} 288}
289 289
diff --git a/drivers/rtc/rtc-pcap.c b/drivers/rtc/rtc-pcap.c
index 539a90b98bc5..40b5c630bc7d 100644
--- a/drivers/rtc/rtc-pcap.c
+++ b/drivers/rtc/rtc-pcap.c
@@ -156,10 +156,8 @@ static int __init pcap_rtc_probe(struct platform_device *pdev)
156 156
157 pcap_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pcap", 157 pcap_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pcap",
158 &pcap_rtc_ops, THIS_MODULE); 158 &pcap_rtc_ops, THIS_MODULE);
159 if (IS_ERR(pcap_rtc->rtc)) { 159 if (IS_ERR(pcap_rtc->rtc))
160 err = PTR_ERR(pcap_rtc->rtc); 160 return PTR_ERR(pcap_rtc->rtc);
161 goto fail;
162 }
163 161
164 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ); 162 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ);
165 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA); 163 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA);
@@ -167,17 +165,14 @@ static int __init pcap_rtc_probe(struct platform_device *pdev)
167 err = devm_request_irq(&pdev->dev, timer_irq, pcap_rtc_irq, 0, 165 err = devm_request_irq(&pdev->dev, timer_irq, pcap_rtc_irq, 0,
168 "RTC Timer", pcap_rtc); 166 "RTC Timer", pcap_rtc);
169 if (err) 167 if (err)
170 goto fail; 168 return err;
171 169
172 err = devm_request_irq(&pdev->dev, alarm_irq, pcap_rtc_irq, 0, 170 err = devm_request_irq(&pdev->dev, alarm_irq, pcap_rtc_irq, 0,
173 "RTC Alarm", pcap_rtc); 171 "RTC Alarm", pcap_rtc);
174 if (err) 172 if (err)
175 goto fail; 173 return err;
176 174
177 return 0; 175 return 0;
178fail:
179 platform_set_drvdata(pdev, NULL);
180 return err;
181} 176}
182 177
183static int __exit pcap_rtc_remove(struct platform_device *pdev) 178static int __exit pcap_rtc_remove(struct platform_device *pdev)
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 796a6c5067dd..1725b5090e33 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -18,11 +18,11 @@
18 * should look something like: 18 * should look something like:
19 * 19 *
20 * static struct spi_board_info ek_spi_devices[] = { 20 * static struct spi_board_info ek_spi_devices[] = {
21 * ... 21 * ...
22 * { 22 * {
23 * .modalias = "rtc-pcf2123", 23 * .modalias = "rtc-pcf2123",
24 * .chip_select = 1, 24 * .chip_select = 1,
25 * .controller_data = (void *)AT91_PIN_PA10, 25 * .controller_data = (void *)AT91_PIN_PA10,
26 * .max_speed_hz = 1000 * 1000, 26 * .max_speed_hz = 1000 * 1000,
27 * .mode = SPI_CS_HIGH, 27 * .mode = SPI_CS_HIGH,
28 * .bus_num = 0, 28 * .bus_num = 0,
@@ -94,8 +94,9 @@ static ssize_t pcf2123_show(struct device *dev, struct device_attribute *attr,
94 94
95 r = container_of(attr, struct pcf2123_sysfs_reg, attr); 95 r = container_of(attr, struct pcf2123_sysfs_reg, attr);
96 96
97 if (strict_strtoul(r->name, 16, &reg)) 97 ret = kstrtoul(r->name, 16, &reg);
98 return -EINVAL; 98 if (ret)
99 return ret;
99 100
100 txbuf[0] = PCF2123_READ | reg; 101 txbuf[0] = PCF2123_READ | reg;
101 ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1); 102 ret = spi_write_then_read(spi, txbuf, 1, rxbuf, 1);
@@ -117,9 +118,13 @@ static ssize_t pcf2123_store(struct device *dev, struct device_attribute *attr,
117 118
118 r = container_of(attr, struct pcf2123_sysfs_reg, attr); 119 r = container_of(attr, struct pcf2123_sysfs_reg, attr);
119 120
120 if (strict_strtoul(r->name, 16, &reg) 121 ret = kstrtoul(r->name, 16, &reg);
121 || strict_strtoul(buffer, 10, &val)) 122 if (ret)
122 return -EINVAL; 123 return ret;
124
125 ret = kstrtoul(buffer, 10, &val);
126 if (ret)
127 return ret;
123 128
124 txbuf[0] = PCF2123_WRITE | reg; 129 txbuf[0] = PCF2123_WRITE | reg;
125 txbuf[1] = val; 130 txbuf[1] = val;
diff --git a/drivers/rtc/rtc-pcf2127.c b/drivers/rtc/rtc-pcf2127.c
new file mode 100644
index 000000000000..205b9f7da1b8
--- /dev/null
+++ b/drivers/rtc/rtc-pcf2127.c
@@ -0,0 +1,241 @@
1/*
2 * An I2C driver for the NXP PCF2127 RTC
3 * Copyright 2013 Til-Technologies
4 *
5 * Author: Renaud Cerrato <r.cerrato@til-technologies.fr>
6 *
7 * based on the other drivers in this same directory.
8 *
9 * http://www.nxp.com/documents/data_sheet/PCF2127AT.pdf
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <linux/i2c.h>
17#include <linux/bcd.h>
18#include <linux/rtc.h>
19#include <linux/slab.h>
20#include <linux/module.h>
21#include <linux/of.h>
22
23#define DRV_VERSION "0.0.1"
24
25#define PCF2127_REG_CTRL1 (0x00) /* Control Register 1 */
26#define PCF2127_REG_CTRL2 (0x01) /* Control Register 2 */
27#define PCF2127_REG_CTRL3 (0x02) /* Control Register 3 */
28#define PCF2127_REG_SC (0x03) /* datetime */
29#define PCF2127_REG_MN (0x04)
30#define PCF2127_REG_HR (0x05)
31#define PCF2127_REG_DM (0x06)
32#define PCF2127_REG_DW (0x07)
33#define PCF2127_REG_MO (0x08)
34#define PCF2127_REG_YR (0x09)
35
36static struct i2c_driver pcf2127_driver;
37
38struct pcf2127 {
39 struct rtc_device *rtc;
40 int voltage_low; /* indicates if a low_voltage was detected */
41};
42
43/*
44 * In the routines that deal directly with the pcf2127 hardware, we use
45 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
46 */
47static int pcf2127_get_datetime(struct i2c_client *client, struct rtc_time *tm)
48{
49 struct pcf2127 *pcf2127 = i2c_get_clientdata(client);
50 unsigned char buf[10] = { PCF2127_REG_CTRL1 };
51
52 /* read registers */
53 if (i2c_master_send(client, buf, 1) != 1 ||
54 i2c_master_recv(client, buf, sizeof(buf)) != sizeof(buf)) {
55 dev_err(&client->dev, "%s: read error\n", __func__);
56 return -EIO;
57 }
58
59 if (buf[PCF2127_REG_CTRL3] & 0x04) {
60 pcf2127->voltage_low = 1;
61 dev_info(&client->dev,
62 "low voltage detected, date/time is not reliable.\n");
63 }
64
65 dev_dbg(&client->dev,
66 "%s: raw data is cr1=%02x, cr2=%02x, cr3=%02x, "
67 "sec=%02x, min=%02x, hr=%02x, "
68 "mday=%02x, wday=%02x, mon=%02x, year=%02x\n",
69 __func__,
70 buf[0], buf[1], buf[2],
71 buf[3], buf[4], buf[5],
72 buf[6], buf[7], buf[8], buf[9]);
73
74
75 tm->tm_sec = bcd2bin(buf[PCF2127_REG_SC] & 0x7F);
76 tm->tm_min = bcd2bin(buf[PCF2127_REG_MN] & 0x7F);
77 tm->tm_hour = bcd2bin(buf[PCF2127_REG_HR] & 0x3F); /* rtc hr 0-23 */
78 tm->tm_mday = bcd2bin(buf[PCF2127_REG_DM] & 0x3F);
79 tm->tm_wday = buf[PCF2127_REG_DW] & 0x07;
80 tm->tm_mon = bcd2bin(buf[PCF2127_REG_MO] & 0x1F) - 1; /* rtc mn 1-12 */
81 tm->tm_year = bcd2bin(buf[PCF2127_REG_YR]);
82 if (tm->tm_year < 70)
83 tm->tm_year += 100; /* assume we are in 1970...2069 */
84
85 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
86 "mday=%d, mon=%d, year=%d, wday=%d\n",
87 __func__,
88 tm->tm_sec, tm->tm_min, tm->tm_hour,
89 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
90
91 /* the clock can give out invalid datetime, but we cannot return
92 * -EINVAL otherwise hwclock will refuse to set the time on bootup.
93 */
94 if (rtc_valid_tm(tm) < 0)
95 dev_err(&client->dev, "retrieved date/time is not valid.\n");
96
97 return 0;
98}
99
100static int pcf2127_set_datetime(struct i2c_client *client, struct rtc_time *tm)
101{
102 unsigned char buf[8];
103 int i = 0, err;
104
105 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
106 "mday=%d, mon=%d, year=%d, wday=%d\n",
107 __func__,
108 tm->tm_sec, tm->tm_min, tm->tm_hour,
109 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
110
111 /* start register address */
112 buf[i++] = PCF2127_REG_SC;
113
114 /* hours, minutes and seconds */
115 buf[i++] = bin2bcd(tm->tm_sec);
116 buf[i++] = bin2bcd(tm->tm_min);
117 buf[i++] = bin2bcd(tm->tm_hour);
118 buf[i++] = bin2bcd(tm->tm_mday);
119 buf[i++] = tm->tm_wday & 0x07;
120
121 /* month, 1 - 12 */
122 buf[i++] = bin2bcd(tm->tm_mon + 1);
123
124 /* year */
125 buf[i++] = bin2bcd(tm->tm_year % 100);
126
127 /* write register's data */
128 err = i2c_master_send(client, buf, i);
129 if (err != i) {
130 dev_err(&client->dev,
131 "%s: err=%d", __func__, err);
132 return -EIO;
133 }
134
135 return 0;
136}
137
138#ifdef CONFIG_RTC_INTF_DEV
139static int pcf2127_rtc_ioctl(struct device *dev,
140 unsigned int cmd, unsigned long arg)
141{
142 struct pcf2127 *pcf2127 = i2c_get_clientdata(to_i2c_client(dev));
143
144 switch (cmd) {
145 case RTC_VL_READ:
146 if (pcf2127->voltage_low)
147 dev_info(dev, "low voltage detected, date/time is not reliable.\n");
148
149 if (copy_to_user((void __user *)arg, &pcf2127->voltage_low,
150 sizeof(int)))
151 return -EFAULT;
152 return 0;
153 default:
154 return -ENOIOCTLCMD;
155 }
156}
157#else
158#define pcf2127_rtc_ioctl NULL
159#endif
160
161static int pcf2127_rtc_read_time(struct device *dev, struct rtc_time *tm)
162{
163 return pcf2127_get_datetime(to_i2c_client(dev), tm);
164}
165
166static int pcf2127_rtc_set_time(struct device *dev, struct rtc_time *tm)
167{
168 return pcf2127_set_datetime(to_i2c_client(dev), tm);
169}
170
171static const struct rtc_class_ops pcf2127_rtc_ops = {
172 .ioctl = pcf2127_rtc_ioctl,
173 .read_time = pcf2127_rtc_read_time,
174 .set_time = pcf2127_rtc_set_time,
175};
176
177static int pcf2127_probe(struct i2c_client *client,
178 const struct i2c_device_id *id)
179{
180 struct pcf2127 *pcf2127;
181
182 dev_dbg(&client->dev, "%s\n", __func__);
183
184 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
185 return -ENODEV;
186
187 pcf2127 = devm_kzalloc(&client->dev, sizeof(struct pcf2127),
188 GFP_KERNEL);
189 if (!pcf2127)
190 return -ENOMEM;
191
192 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
193
194 i2c_set_clientdata(client, pcf2127);
195
196 pcf2127->rtc = devm_rtc_device_register(&client->dev,
197 pcf2127_driver.driver.name,
198 &pcf2127_rtc_ops, THIS_MODULE);
199
200 if (IS_ERR(pcf2127->rtc))
201 return PTR_ERR(pcf2127->rtc);
202
203 return 0;
204}
205
206static int pcf2127_remove(struct i2c_client *client)
207{
208 return 0;
209}
210
211static const struct i2c_device_id pcf2127_id[] = {
212 { "pcf2127", 0 },
213 { }
214};
215MODULE_DEVICE_TABLE(i2c, pcf2127_id);
216
217#ifdef CONFIG_OF
218static const struct of_device_id pcf2127_of_match[] = {
219 { .compatible = "nxp,pcf2127" },
220 {}
221};
222MODULE_DEVICE_TABLE(of, pcf2127_of_match);
223#endif
224
225static struct i2c_driver pcf2127_driver = {
226 .driver = {
227 .name = "rtc-pcf2127",
228 .owner = THIS_MODULE,
229 .of_match_table = of_match_ptr(pcf2127_of_match),
230 },
231 .probe = pcf2127_probe,
232 .remove = pcf2127_remove,
233 .id_table = pcf2127_id,
234};
235
236module_i2c_driver(pcf2127_driver);
237
238MODULE_AUTHOR("Renaud Cerrato <r.cerrato@til-technologies.fr>");
239MODULE_DESCRIPTION("NXP PCF2127 RTC driver");
240MODULE_LICENSE("GPL");
241MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index 305c9515e5bb..5c8f8226c848 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -317,11 +317,6 @@ static int pcf8523_probe(struct i2c_client *client,
317 return 0; 317 return 0;
318} 318}
319 319
320static int pcf8523_remove(struct i2c_client *client)
321{
322 return 0;
323}
324
325static const struct i2c_device_id pcf8523_id[] = { 320static const struct i2c_device_id pcf8523_id[] = {
326 { "pcf8523", 0 }, 321 { "pcf8523", 0 },
327 { } 322 { }
@@ -343,7 +338,6 @@ static struct i2c_driver pcf8523_driver = {
343 .of_match_table = of_match_ptr(pcf8523_of_match), 338 .of_match_table = of_match_ptr(pcf8523_of_match),
344 }, 339 },
345 .probe = pcf8523_probe, 340 .probe = pcf8523_probe,
346 .remove = pcf8523_remove,
347 .id_table = pcf8523_id, 341 .id_table = pcf8523_id,
348}; 342};
349module_i2c_driver(pcf8523_driver); 343module_i2c_driver(pcf8523_driver);
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index 97b354a26a44..710c3a5aa6ff 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -20,6 +20,7 @@
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/module.h> 21#include <linux/module.h>
22#include <linux/of.h> 22#include <linux/of.h>
23#include <linux/err.h>
23 24
24#define DRV_VERSION "0.4.3" 25#define DRV_VERSION "0.4.3"
25 26
@@ -263,15 +264,7 @@ static int pcf8563_probe(struct i2c_client *client,
263 pcf8563_driver.driver.name, 264 pcf8563_driver.driver.name,
264 &pcf8563_rtc_ops, THIS_MODULE); 265 &pcf8563_rtc_ops, THIS_MODULE);
265 266
266 if (IS_ERR(pcf8563->rtc)) 267 return PTR_RET(pcf8563->rtc);
267 return PTR_ERR(pcf8563->rtc);
268
269 return 0;
270}
271
272static int pcf8563_remove(struct i2c_client *client)
273{
274 return 0;
275} 268}
276 269
277static const struct i2c_device_id pcf8563_id[] = { 270static const struct i2c_device_id pcf8563_id[] = {
@@ -296,7 +289,6 @@ static struct i2c_driver pcf8563_driver = {
296 .of_match_table = of_match_ptr(pcf8563_of_match), 289 .of_match_table = of_match_ptr(pcf8563_of_match),
297 }, 290 },
298 .probe = pcf8563_probe, 291 .probe = pcf8563_probe,
299 .remove = pcf8563_remove,
300 .id_table = pcf8563_id, 292 .id_table = pcf8563_id,
301}; 293};
302 294
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 95886dcf4a39..843a745c42f3 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -17,6 +17,7 @@
17#include <linux/slab.h> 17#include <linux/slab.h>
18#include <linux/rtc.h> 18#include <linux/rtc.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/err.h>
20#include <linux/errno.h> 21#include <linux/errno.h>
21#include <linux/bcd.h> 22#include <linux/bcd.h>
22 23
@@ -188,7 +189,8 @@ static int pcf8583_rtc_read_time(struct device *dev, struct rtc_time *tm)
188 dev_warn(dev, "resetting control %02x -> %02x\n", 189 dev_warn(dev, "resetting control %02x -> %02x\n",
189 ctrl, new_ctrl); 190 ctrl, new_ctrl);
190 191
191 if ((err = pcf8583_set_ctrl(client, &new_ctrl)) < 0) 192 err = pcf8583_set_ctrl(client, &new_ctrl);
193 if (err < 0)
192 return err; 194 return err;
193 } 195 }
194 196
@@ -283,15 +285,7 @@ static int pcf8583_probe(struct i2c_client *client,
283 pcf8583_driver.driver.name, 285 pcf8583_driver.driver.name,
284 &pcf8583_rtc_ops, THIS_MODULE); 286 &pcf8583_rtc_ops, THIS_MODULE);
285 287
286 if (IS_ERR(pcf8583->rtc)) 288 return PTR_RET(pcf8583->rtc);
287 return PTR_ERR(pcf8583->rtc);
288
289 return 0;
290}
291
292static int pcf8583_remove(struct i2c_client *client)
293{
294 return 0;
295} 289}
296 290
297static const struct i2c_device_id pcf8583_id[] = { 291static const struct i2c_device_id pcf8583_id[] = {
@@ -306,7 +300,6 @@ static struct i2c_driver pcf8583_driver = {
306 .owner = THIS_MODULE, 300 .owner = THIS_MODULE,
307 }, 301 },
308 .probe = pcf8583_probe, 302 .probe = pcf8583_probe,
309 .remove = pcf8583_remove,
310 .id_table = pcf8583_id, 303 .id_table = pcf8583_id,
311}; 304};
312 305
diff --git a/drivers/rtc/rtc-pm8xxx.c b/drivers/rtc/rtc-pm8xxx.c
index f1a6557261f3..03f8f75d5af2 100644
--- a/drivers/rtc/rtc-pm8xxx.c
+++ b/drivers/rtc/rtc-pm8xxx.c
@@ -395,7 +395,7 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
395 if (pdata != NULL) 395 if (pdata != NULL)
396 rtc_write_enable = pdata->rtc_write_enable; 396 rtc_write_enable = pdata->rtc_write_enable;
397 397
398 rtc_dd = kzalloc(sizeof(*rtc_dd), GFP_KERNEL); 398 rtc_dd = devm_kzalloc(&pdev->dev, sizeof(*rtc_dd), GFP_KERNEL);
399 if (rtc_dd == NULL) { 399 if (rtc_dd == NULL) {
400 dev_err(&pdev->dev, "Unable to allocate memory!\n"); 400 dev_err(&pdev->dev, "Unable to allocate memory!\n");
401 return -ENOMEM; 401 return -ENOMEM;
@@ -407,16 +407,14 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
407 rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0); 407 rtc_dd->rtc_alarm_irq = platform_get_irq(pdev, 0);
408 if (rtc_dd->rtc_alarm_irq < 0) { 408 if (rtc_dd->rtc_alarm_irq < 0) {
409 dev_err(&pdev->dev, "Alarm IRQ resource absent!\n"); 409 dev_err(&pdev->dev, "Alarm IRQ resource absent!\n");
410 rc = -ENXIO; 410 return -ENXIO;
411 goto fail_rtc_enable;
412 } 411 }
413 412
414 rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO, 413 rtc_resource = platform_get_resource_byname(pdev, IORESOURCE_IO,
415 "pmic_rtc_base"); 414 "pmic_rtc_base");
416 if (!(rtc_resource && rtc_resource->start)) { 415 if (!(rtc_resource && rtc_resource->start)) {
417 dev_err(&pdev->dev, "RTC IO resource absent!\n"); 416 dev_err(&pdev->dev, "RTC IO resource absent!\n");
418 rc = -ENXIO; 417 return -ENXIO;
419 goto fail_rtc_enable;
420 } 418 }
421 419
422 rtc_dd->rtc_base = rtc_resource->start; 420 rtc_dd->rtc_base = rtc_resource->start;
@@ -432,7 +430,7 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
432 rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1); 430 rc = pm8xxx_read_wrapper(rtc_dd, &ctrl_reg, rtc_dd->rtc_base, 1);
433 if (rc < 0) { 431 if (rc < 0) {
434 dev_err(&pdev->dev, "RTC control register read failed!\n"); 432 dev_err(&pdev->dev, "RTC control register read failed!\n");
435 goto fail_rtc_enable; 433 return rc;
436 } 434 }
437 435
438 if (!(ctrl_reg & PM8xxx_RTC_ENABLE)) { 436 if (!(ctrl_reg & PM8xxx_RTC_ENABLE)) {
@@ -442,7 +440,7 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
442 if (rc < 0) { 440 if (rc < 0) {
443 dev_err(&pdev->dev, "Write to RTC control register " 441 dev_err(&pdev->dev, "Write to RTC control register "
444 "failed\n"); 442 "failed\n");
445 goto fail_rtc_enable; 443 return rc;
446 } 444 }
447 } 445 }
448 446
@@ -453,13 +451,12 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
453 platform_set_drvdata(pdev, rtc_dd); 451 platform_set_drvdata(pdev, rtc_dd);
454 452
455 /* Register the RTC device */ 453 /* Register the RTC device */
456 rtc_dd->rtc = rtc_device_register("pm8xxx_rtc", &pdev->dev, 454 rtc_dd->rtc = devm_rtc_device_register(&pdev->dev, "pm8xxx_rtc",
457 &pm8xxx_rtc_ops, THIS_MODULE); 455 &pm8xxx_rtc_ops, THIS_MODULE);
458 if (IS_ERR(rtc_dd->rtc)) { 456 if (IS_ERR(rtc_dd->rtc)) {
459 dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n", 457 dev_err(&pdev->dev, "%s: RTC registration failed (%ld)\n",
460 __func__, PTR_ERR(rtc_dd->rtc)); 458 __func__, PTR_ERR(rtc_dd->rtc));
461 rc = PTR_ERR(rtc_dd->rtc); 459 return PTR_ERR(rtc_dd->rtc);
462 goto fail_rtc_enable;
463 } 460 }
464 461
465 /* Request the alarm IRQ */ 462 /* Request the alarm IRQ */
@@ -468,7 +465,7 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
468 "pm8xxx_rtc_alarm", rtc_dd); 465 "pm8xxx_rtc_alarm", rtc_dd);
469 if (rc < 0) { 466 if (rc < 0) {
470 dev_err(&pdev->dev, "Request IRQ failed (%d)\n", rc); 467 dev_err(&pdev->dev, "Request IRQ failed (%d)\n", rc);
471 goto fail_req_irq; 468 return rc;
472 } 469 }
473 470
474 device_init_wakeup(&pdev->dev, 1); 471 device_init_wakeup(&pdev->dev, 1);
@@ -476,13 +473,6 @@ static int pm8xxx_rtc_probe(struct platform_device *pdev)
476 dev_dbg(&pdev->dev, "Probe success !!\n"); 473 dev_dbg(&pdev->dev, "Probe success !!\n");
477 474
478 return 0; 475 return 0;
479
480fail_req_irq:
481 rtc_device_unregister(rtc_dd->rtc);
482fail_rtc_enable:
483 platform_set_drvdata(pdev, NULL);
484 kfree(rtc_dd);
485 return rc;
486} 476}
487 477
488static int pm8xxx_rtc_remove(struct platform_device *pdev) 478static int pm8xxx_rtc_remove(struct platform_device *pdev)
@@ -491,9 +481,6 @@ static int pm8xxx_rtc_remove(struct platform_device *pdev)
491 481
492 device_init_wakeup(&pdev->dev, 0); 482 device_init_wakeup(&pdev->dev, 0);
493 free_irq(rtc_dd->rtc_alarm_irq, rtc_dd); 483 free_irq(rtc_dd->rtc_alarm_irq, rtc_dd);
494 rtc_device_unregister(rtc_dd->rtc);
495 platform_set_drvdata(pdev, NULL);
496 kfree(rtc_dd);
497 484
498 return 0; 485 return 0;
499} 486}
diff --git a/drivers/rtc/rtc-ps3.c b/drivers/rtc/rtc-ps3.c
index 4bb825bb5804..554ada5e9b76 100644
--- a/drivers/rtc/rtc-ps3.c
+++ b/drivers/rtc/rtc-ps3.c
@@ -71,17 +71,11 @@ static int __init ps3_rtc_probe(struct platform_device *dev)
71 return 0; 71 return 0;
72} 72}
73 73
74static int __exit ps3_rtc_remove(struct platform_device *dev)
75{
76 return 0;
77}
78
79static struct platform_driver ps3_rtc_driver = { 74static struct platform_driver ps3_rtc_driver = {
80 .driver = { 75 .driver = {
81 .name = "rtc-ps3", 76 .name = "rtc-ps3",
82 .owner = THIS_MODULE, 77 .owner = THIS_MODULE,
83 }, 78 },
84 .remove = __exit_p(ps3_rtc_remove),
85}; 79};
86 80
87module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe); 81module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
diff --git a/drivers/rtc/rtc-puv3.c b/drivers/rtc/rtc-puv3.c
index 72f437170d2e..402732cfb32a 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -224,7 +224,6 @@ static int puv3_rtc_remove(struct platform_device *dev)
224{ 224{
225 struct rtc_device *rtc = platform_get_drvdata(dev); 225 struct rtc_device *rtc = platform_get_drvdata(dev);
226 226
227 platform_set_drvdata(dev, NULL);
228 rtc_device_unregister(rtc); 227 rtc_device_unregister(rtc);
229 228
230 puv3_rtc_setpie(&dev->dev, 0); 229 puv3_rtc_setpie(&dev->dev, 0);
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index ed037ae91c5f..a355f2b82bb8 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -324,37 +324,35 @@ static int __init pxa_rtc_probe(struct platform_device *pdev)
324 int ret; 324 int ret;
325 u32 rttr; 325 u32 rttr;
326 326
327 pxa_rtc = kzalloc(sizeof(struct pxa_rtc), GFP_KERNEL); 327 pxa_rtc = devm_kzalloc(dev, sizeof(*pxa_rtc), GFP_KERNEL);
328 if (!pxa_rtc) 328 if (!pxa_rtc)
329 return -ENOMEM; 329 return -ENOMEM;
330 330
331 spin_lock_init(&pxa_rtc->lock); 331 spin_lock_init(&pxa_rtc->lock);
332 platform_set_drvdata(pdev, pxa_rtc); 332 platform_set_drvdata(pdev, pxa_rtc);
333 333
334 ret = -ENXIO;
335 pxa_rtc->ress = platform_get_resource(pdev, IORESOURCE_MEM, 0); 334 pxa_rtc->ress = platform_get_resource(pdev, IORESOURCE_MEM, 0);
336 if (!pxa_rtc->ress) { 335 if (!pxa_rtc->ress) {
337 dev_err(dev, "No I/O memory resource defined\n"); 336 dev_err(dev, "No I/O memory resource defined\n");
338 goto err_ress; 337 return -ENXIO;
339 } 338 }
340 339
341 pxa_rtc->irq_1Hz = platform_get_irq(pdev, 0); 340 pxa_rtc->irq_1Hz = platform_get_irq(pdev, 0);
342 if (pxa_rtc->irq_1Hz < 0) { 341 if (pxa_rtc->irq_1Hz < 0) {
343 dev_err(dev, "No 1Hz IRQ resource defined\n"); 342 dev_err(dev, "No 1Hz IRQ resource defined\n");
344 goto err_ress; 343 return -ENXIO;
345 } 344 }
346 pxa_rtc->irq_Alrm = platform_get_irq(pdev, 1); 345 pxa_rtc->irq_Alrm = platform_get_irq(pdev, 1);
347 if (pxa_rtc->irq_Alrm < 0) { 346 if (pxa_rtc->irq_Alrm < 0) {
348 dev_err(dev, "No alarm IRQ resource defined\n"); 347 dev_err(dev, "No alarm IRQ resource defined\n");
349 goto err_ress; 348 return -ENXIO;
350 } 349 }
351 pxa_rtc_open(dev); 350 pxa_rtc_open(dev);
352 ret = -ENOMEM; 351 pxa_rtc->base = devm_ioremap(dev, pxa_rtc->ress->start,
353 pxa_rtc->base = ioremap(pxa_rtc->ress->start,
354 resource_size(pxa_rtc->ress)); 352 resource_size(pxa_rtc->ress));
355 if (!pxa_rtc->base) { 353 if (!pxa_rtc->base) {
356 dev_err(&pdev->dev, "Unable to map pxa RTC I/O memory\n"); 354 dev_err(dev, "Unable to map pxa RTC I/O memory\n");
357 goto err_map; 355 return -ENOMEM;
358 } 356 }
359 357
360 /* 358 /*
@@ -370,41 +368,24 @@ static int __init pxa_rtc_probe(struct platform_device *pdev)
370 368
371 rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE); 369 rtsr_clear_bits(pxa_rtc, RTSR_PIALE | RTSR_RDALE1 | RTSR_HZE);
372 370
373 pxa_rtc->rtc = rtc_device_register("pxa-rtc", &pdev->dev, &pxa_rtc_ops, 371 pxa_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pxa-rtc",
374 THIS_MODULE); 372 &pxa_rtc_ops, THIS_MODULE);
375 ret = PTR_ERR(pxa_rtc->rtc);
376 if (IS_ERR(pxa_rtc->rtc)) { 373 if (IS_ERR(pxa_rtc->rtc)) {
374 ret = PTR_ERR(pxa_rtc->rtc);
377 dev_err(dev, "Failed to register RTC device -> %d\n", ret); 375 dev_err(dev, "Failed to register RTC device -> %d\n", ret);
378 goto err_rtc_reg; 376 return ret;
379 } 377 }
380 378
381 device_init_wakeup(dev, 1); 379 device_init_wakeup(dev, 1);
382 380
383 return 0; 381 return 0;
384
385err_rtc_reg:
386 iounmap(pxa_rtc->base);
387err_ress:
388err_map:
389 kfree(pxa_rtc);
390 return ret;
391} 382}
392 383
393static int __exit pxa_rtc_remove(struct platform_device *pdev) 384static int __exit pxa_rtc_remove(struct platform_device *pdev)
394{ 385{
395 struct pxa_rtc *pxa_rtc = platform_get_drvdata(pdev);
396
397 struct device *dev = &pdev->dev; 386 struct device *dev = &pdev->dev;
398 pxa_rtc_release(dev);
399
400 rtc_device_unregister(pxa_rtc->rtc);
401
402 spin_lock_irq(&pxa_rtc->lock);
403 iounmap(pxa_rtc->base);
404 spin_unlock_irq(&pxa_rtc->lock);
405
406 kfree(pxa_rtc);
407 387
388 pxa_rtc_release(dev);
408 return 0; 389 return 0;
409} 390}
410 391
diff --git a/drivers/rtc/rtc-rc5t583.c b/drivers/rtc/rtc-rc5t583.c
index 8eabcf51b35a..e53e9b1c69b3 100644
--- a/drivers/rtc/rtc-rc5t583.c
+++ b/drivers/rtc/rtc-rc5t583.c
@@ -273,7 +273,7 @@ static int rc5t583_rtc_probe(struct platform_device *pdev)
273 */ 273 */
274static int rc5t583_rtc_remove(struct platform_device *pdev) 274static int rc5t583_rtc_remove(struct platform_device *pdev)
275{ 275{
276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev); 276 struct rc5t583_rtc *rc5t583_rtc = platform_get_drvdata(pdev);
277 277
278 rc5t583_rtc_alarm_irq_enable(&rc5t583_rtc->rtc->dev, 0); 278 rc5t583_rtc_alarm_irq_enable(&rc5t583_rtc->rtc->dev, 0);
279 return 0; 279 return 0;
diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c
index 873c689f01c3..89d073679267 100644
--- a/drivers/rtc/rtc-rp5c01.c
+++ b/drivers/rtc/rtc-rp5c01.c
@@ -251,21 +251,15 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
251 251
252 rtc = devm_rtc_device_register(&dev->dev, "rtc-rp5c01", &rp5c01_rtc_ops, 252 rtc = devm_rtc_device_register(&dev->dev, "rtc-rp5c01", &rp5c01_rtc_ops,
253 THIS_MODULE); 253 THIS_MODULE);
254 if (IS_ERR(rtc)) { 254 if (IS_ERR(rtc))
255 error = PTR_ERR(rtc); 255 return PTR_ERR(rtc);
256 goto out;
257 }
258 priv->rtc = rtc; 256 priv->rtc = rtc;
259 257
260 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr); 258 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr);
261 if (error) 259 if (error)
262 goto out; 260 return error;
263 261
264 return 0; 262 return 0;
265
266out:
267 platform_set_drvdata(dev, NULL);
268 return error;
269} 263}
270 264
271static int __exit rp5c01_rtc_remove(struct platform_device *dev) 265static int __exit rp5c01_rtc_remove(struct platform_device *dev)
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index 8089fc63e403..68f7856422f1 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -47,10 +47,10 @@
47#include <linux/platform_device.h> 47#include <linux/platform_device.h>
48#include <linux/bcd.h> 48#include <linux/bcd.h>
49#include <linux/delay.h> 49#include <linux/delay.h>
50#include <asm/io.h> 50#include <linux/io.h>
51 51
52#define DRV_NAME "rs5c313" 52#define DRV_NAME "rs5c313"
53#define DRV_VERSION "1.13" 53#define DRV_VERSION "1.13"
54 54
55#ifdef CONFIG_SH_LANDISK 55#ifdef CONFIG_SH_LANDISK
56/*****************************************************/ 56/*****************************************************/
@@ -301,7 +301,7 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
301 rs5c313_write_reg(RS5C313_ADDR_SEC10, (data >> 4)); 301 rs5c313_write_reg(RS5C313_ADDR_SEC10, (data >> 4));
302 302
303 data = bin2bcd(tm->tm_min); 303 data = bin2bcd(tm->tm_min);
304 rs5c313_write_reg(RS5C313_ADDR_MIN, data ); 304 rs5c313_write_reg(RS5C313_ADDR_MIN, data);
305 rs5c313_write_reg(RS5C313_ADDR_MIN10, (data >> 4)); 305 rs5c313_write_reg(RS5C313_ADDR_MIN10, (data >> 4));
306 306
307 data = bin2bcd(tm->tm_hour); 307 data = bin2bcd(tm->tm_hour);
@@ -310,7 +310,7 @@ static int rs5c313_rtc_set_time(struct device *dev, struct rtc_time *tm)
310 310
311 data = bin2bcd(tm->tm_mday); 311 data = bin2bcd(tm->tm_mday);
312 rs5c313_write_reg(RS5C313_ADDR_DAY, data); 312 rs5c313_write_reg(RS5C313_ADDR_DAY, data);
313 rs5c313_write_reg(RS5C313_ADDR_DAY10, (data>> 4)); 313 rs5c313_write_reg(RS5C313_ADDR_DAY10, (data >> 4));
314 314
315 data = bin2bcd(tm->tm_mon + 1); 315 data = bin2bcd(tm->tm_mon + 1);
316 rs5c313_write_reg(RS5C313_ADDR_MON, data); 316 rs5c313_write_reg(RS5C313_ADDR_MON, data);
@@ -349,9 +349,9 @@ static void rs5c313_check_xstp_bit(void)
349 } 349 }
350 350
351 memset(&tm, 0, sizeof(struct rtc_time)); 351 memset(&tm, 0, sizeof(struct rtc_time));
352 tm.tm_mday = 1; 352 tm.tm_mday = 1;
353 tm.tm_mon = 1 - 1; 353 tm.tm_mon = 1 - 1;
354 tm.tm_year = 2000 - 1900; 354 tm.tm_year = 2000 - 1900;
355 355
356 rs5c313_rtc_set_time(NULL, &tm); 356 rs5c313_rtc_set_time(NULL, &tm);
357 pr_err("invalid value, resetting to 1 Jan 2000\n"); 357 pr_err("invalid value, resetting to 1 Jan 2000\n");
@@ -378,18 +378,12 @@ static int rs5c313_rtc_probe(struct platform_device *pdev)
378 return 0; 378 return 0;
379} 379}
380 380
381static int rs5c313_rtc_remove(struct platform_device *pdev)
382{
383 return 0;
384}
385
386static struct platform_driver rs5c313_rtc_platform_driver = { 381static struct platform_driver rs5c313_rtc_platform_driver = {
387 .driver = { 382 .driver = {
388 .name = DRV_NAME, 383 .name = DRV_NAME,
389 .owner = THIS_MODULE, 384 .owner = THIS_MODULE,
390 }, 385 },
391 .probe = rs5c313_rtc_probe, 386 .probe = rs5c313_rtc_probe,
392 .remove = rs5c313_rtc_remove,
393}; 387};
394 388
395static int __init rs5c313_rtc_init(void) 389static int __init rs5c313_rtc_init(void)
@@ -408,7 +402,7 @@ static int __init rs5c313_rtc_init(void)
408 402
409static void __exit rs5c313_rtc_exit(void) 403static void __exit rs5c313_rtc_exit(void)
410{ 404{
411 platform_driver_unregister( &rs5c313_rtc_platform_driver ); 405 platform_driver_unregister(&rs5c313_rtc_platform_driver);
412} 406}
413 407
414module_init(rs5c313_rtc_init); 408module_init(rs5c313_rtc_init);
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 2c37df3586c7..f7a90a116a39 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -218,18 +218,12 @@ static int rs5c348_probe(struct spi_device *spi)
218 return ret; 218 return ret;
219} 219}
220 220
221static int rs5c348_remove(struct spi_device *spi)
222{
223 return 0;
224}
225
226static struct spi_driver rs5c348_driver = { 221static struct spi_driver rs5c348_driver = {
227 .driver = { 222 .driver = {
228 .name = "rtc-rs5c348", 223 .name = "rtc-rs5c348",
229 .owner = THIS_MODULE, 224 .owner = THIS_MODULE,
230 }, 225 },
231 .probe = rs5c348_probe, 226 .probe = rs5c348_probe,
232 .remove = rs5c348_remove,
233}; 227};
234 228
235module_spi_driver(rs5c348_driver); 229module_spi_driver(rs5c348_driver);
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index 5032c24ec159..1a779a67ff66 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -310,7 +310,7 @@ static int rv3029c2_rtc_i2c_set_alarm(struct i2c_client *client,
310 dev_dbg(&client->dev, "alarm IRQ armed\n"); 310 dev_dbg(&client->dev, "alarm IRQ armed\n");
311 } else { 311 } else {
312 /* disable AIE irq */ 312 /* disable AIE irq */
313 ret = rv3029c2_rtc_i2c_alarm_set_irq(client, 1); 313 ret = rv3029c2_rtc_i2c_alarm_set_irq(client, 0);
314 if (ret) 314 if (ret)
315 return ret; 315 return ret;
316 316
@@ -412,17 +412,11 @@ static int rv3029c2_probe(struct i2c_client *client,
412 return 0; 412 return 0;
413} 413}
414 414
415static int rv3029c2_remove(struct i2c_client *client)
416{
417 return 0;
418}
419
420static struct i2c_driver rv3029c2_driver = { 415static struct i2c_driver rv3029c2_driver = {
421 .driver = { 416 .driver = {
422 .name = "rtc-rv3029c2", 417 .name = "rtc-rv3029c2",
423 }, 418 },
424 .probe = rv3029c2_probe, 419 .probe = rv3029c2_probe,
425 .remove = rv3029c2_remove,
426 .id_table = rv3029c2_id, 420 .id_table = rv3029c2_id,
427}; 421};
428 422
diff --git a/drivers/rtc/rtc-rx4581.c b/drivers/rtc/rtc-rx4581.c
index 84eb08d65d30..6889222f9ed6 100644
--- a/drivers/rtc/rtc-rx4581.c
+++ b/drivers/rtc/rtc-rx4581.c
@@ -282,11 +282,6 @@ static int rx4581_probe(struct spi_device *spi)
282 return 0; 282 return 0;
283} 283}
284 284
285static int rx4581_remove(struct spi_device *spi)
286{
287 return 0;
288}
289
290static const struct spi_device_id rx4581_id[] = { 285static const struct spi_device_id rx4581_id[] = {
291 { "rx4581", 0 }, 286 { "rx4581", 0 },
292 { } 287 { }
@@ -299,7 +294,6 @@ static struct spi_driver rx4581_driver = {
299 .owner = THIS_MODULE, 294 .owner = THIS_MODULE,
300 }, 295 },
301 .probe = rx4581_probe, 296 .probe = rx4581_probe,
302 .remove = rx4581_remove,
303 .id_table = rx4581_id, 297 .id_table = rx4581_id,
304}; 298};
305 299
diff --git a/drivers/rtc/rtc-rx8025.c b/drivers/rtc/rtc-rx8025.c
index 0722d36b9c9a..8fa23eabcb68 100644
--- a/drivers/rtc/rtc-rx8025.c
+++ b/drivers/rtc/rtc-rx8025.c
@@ -549,7 +549,7 @@ static int rx8025_probe(struct i2c_client *client,
549 goto errout; 549 goto errout;
550 } 550 }
551 551
552 rx8025 = kzalloc(sizeof(*rx8025), GFP_KERNEL); 552 rx8025 = devm_kzalloc(&client->dev, sizeof(*rx8025), GFP_KERNEL);
553 if (!rx8025) { 553 if (!rx8025) {
554 dev_err(&adapter->dev, "failed to alloc memory\n"); 554 dev_err(&adapter->dev, "failed to alloc memory\n");
555 err = -ENOMEM; 555 err = -ENOMEM;
@@ -562,7 +562,7 @@ static int rx8025_probe(struct i2c_client *client,
562 562
563 err = rx8025_init_client(client, &need_reset); 563 err = rx8025_init_client(client, &need_reset);
564 if (err) 564 if (err)
565 goto errout_free; 565 goto errout;
566 566
567 if (need_reset) { 567 if (need_reset) {
568 struct rtc_time tm; 568 struct rtc_time tm;
@@ -572,12 +572,12 @@ static int rx8025_probe(struct i2c_client *client,
572 rx8025_set_time(&client->dev, &tm); 572 rx8025_set_time(&client->dev, &tm);
573 } 573 }
574 574
575 rx8025->rtc = rtc_device_register(client->name, &client->dev, 575 rx8025->rtc = devm_rtc_device_register(&client->dev, client->name,
576 &rx8025_rtc_ops, THIS_MODULE); 576 &rx8025_rtc_ops, THIS_MODULE);
577 if (IS_ERR(rx8025->rtc)) { 577 if (IS_ERR(rx8025->rtc)) {
578 err = PTR_ERR(rx8025->rtc); 578 err = PTR_ERR(rx8025->rtc);
579 dev_err(&client->dev, "unable to register the class device\n"); 579 dev_err(&client->dev, "unable to register the class device\n");
580 goto errout_free; 580 goto errout;
581 } 581 }
582 582
583 if (client->irq > 0) { 583 if (client->irq > 0) {
@@ -586,7 +586,7 @@ static int rx8025_probe(struct i2c_client *client,
586 0, "rx8025", client); 586 0, "rx8025", client);
587 if (err) { 587 if (err) {
588 dev_err(&client->dev, "unable to request IRQ\n"); 588 dev_err(&client->dev, "unable to request IRQ\n");
589 goto errout_reg; 589 goto errout;
590 } 590 }
591 } 591 }
592 592
@@ -603,12 +603,6 @@ errout_irq:
603 if (client->irq > 0) 603 if (client->irq > 0)
604 free_irq(client->irq, client); 604 free_irq(client->irq, client);
605 605
606errout_reg:
607 rtc_device_unregister(rx8025->rtc);
608
609errout_free:
610 kfree(rx8025);
611
612errout: 606errout:
613 dev_err(&adapter->dev, "probing for rx8025 failed\n"); 607 dev_err(&adapter->dev, "probing for rx8025 failed\n");
614 return err; 608 return err;
@@ -629,8 +623,6 @@ static int rx8025_remove(struct i2c_client *client)
629 } 623 }
630 624
631 rx8025_sysfs_unregister(&client->dev); 625 rx8025_sysfs_unregister(&client->dev);
632 rtc_device_unregister(rx8025->rtc);
633 kfree(rx8025);
634 return 0; 626 return 0;
635} 627}
636 628
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c
index 07f3037b18f4..00b0eb7fe166 100644
--- a/drivers/rtc/rtc-rx8581.c
+++ b/drivers/rtc/rtc-rx8581.c
@@ -251,11 +251,6 @@ static int rx8581_probe(struct i2c_client *client,
251 return 0; 251 return 0;
252} 252}
253 253
254static int rx8581_remove(struct i2c_client *client)
255{
256 return 0;
257}
258
259static const struct i2c_device_id rx8581_id[] = { 254static const struct i2c_device_id rx8581_id[] = {
260 { "rx8581", 0 }, 255 { "rx8581", 0 },
261 { } 256 { }
@@ -268,7 +263,6 @@ static struct i2c_driver rx8581_driver = {
268 .owner = THIS_MODULE, 263 .owner = THIS_MODULE,
269 }, 264 },
270 .probe = rx8581_probe, 265 .probe = rx8581_probe,
271 .remove = rx8581_remove,
272 .id_table = rx8581_id, 266 .id_table = rx8581_id,
273}; 267};
274 268
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index 0b495e8b8e66..7afd373b9595 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -421,8 +421,6 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
421 421
422static int s3c_rtc_remove(struct platform_device *dev) 422static int s3c_rtc_remove(struct platform_device *dev)
423{ 423{
424 platform_set_drvdata(dev, NULL);
425
426 s3c_rtc_setaie(&dev->dev, 0); 424 s3c_rtc_setaie(&dev->dev, 0);
427 425
428 clk_unprepare(rtc_clk); 426 clk_unprepare(rtc_clk);
@@ -549,23 +547,20 @@ static int s3c_rtc_probe(struct platform_device *pdev)
549 0, "s3c2410-rtc alarm", rtc); 547 0, "s3c2410-rtc alarm", rtc);
550 if (ret) { 548 if (ret) {
551 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_alarmno, ret); 549 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_alarmno, ret);
552 goto err_alarm_irq; 550 goto err_nortc;
553 } 551 }
554 552
555 ret = devm_request_irq(&pdev->dev, s3c_rtc_tickno, s3c_rtc_tickirq, 553 ret = devm_request_irq(&pdev->dev, s3c_rtc_tickno, s3c_rtc_tickirq,
556 0, "s3c2410-rtc tick", rtc); 554 0, "s3c2410-rtc tick", rtc);
557 if (ret) { 555 if (ret) {
558 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_tickno, ret); 556 dev_err(&pdev->dev, "IRQ%d error %d\n", s3c_rtc_tickno, ret);
559 goto err_alarm_irq; 557 goto err_nortc;
560 } 558 }
561 559
562 clk_disable(rtc_clk); 560 clk_disable(rtc_clk);
563 561
564 return 0; 562 return 0;
565 563
566 err_alarm_irq:
567 platform_set_drvdata(pdev, NULL);
568
569 err_nortc: 564 err_nortc:
570 s3c_rtc_enable(pdev, 0); 565 s3c_rtc_enable(pdev, 0);
571 clk_disable_unprepare(rtc_clk); 566 clk_disable_unprepare(rtc_clk);
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 00605601dbf7..0f7adeb1944a 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -249,7 +249,7 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
249 249
250 ret = clk_prepare_enable(info->clk); 250 ret = clk_prepare_enable(info->clk);
251 if (ret) 251 if (ret)
252 goto err_enable_clk; 252 return ret;
253 /* 253 /*
254 * According to the manual we should be able to let RTTR be zero 254 * According to the manual we should be able to let RTTR be zero
255 * and then a default diviser for a 32.768KHz clock is used. 255 * and then a default diviser for a 32.768KHz clock is used.
@@ -303,8 +303,6 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
303 return 0; 303 return 0;
304err_dev: 304err_dev:
305 clk_disable_unprepare(info->clk); 305 clk_disable_unprepare(info->clk);
306err_enable_clk:
307 platform_set_drvdata(pdev, NULL);
308 return ret; 306 return ret;
309} 307}
310 308
@@ -312,10 +310,8 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
312{ 310{
313 struct sa1100_rtc *info = platform_get_drvdata(pdev); 311 struct sa1100_rtc *info = platform_get_drvdata(pdev);
314 312
315 if (info) { 313 if (info)
316 clk_disable_unprepare(info->clk); 314 clk_disable_unprepare(info->clk);
317 platform_set_drvdata(pdev, NULL);
318 }
319 315
320 return 0; 316 return 0;
321} 317}
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index 8d5bd2e36776..6d87e26355a3 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -593,7 +593,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
593 char clk_name[6]; 593 char clk_name[6];
594 int clk_id, ret; 594 int clk_id, ret;
595 595
596 rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL); 596 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
597 if (unlikely(!rtc)) 597 if (unlikely(!rtc))
598 return -ENOMEM; 598 return -ENOMEM;
599 599
@@ -602,9 +602,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
602 /* get periodic/carry/alarm irqs */ 602 /* get periodic/carry/alarm irqs */
603 ret = platform_get_irq(pdev, 0); 603 ret = platform_get_irq(pdev, 0);
604 if (unlikely(ret <= 0)) { 604 if (unlikely(ret <= 0)) {
605 ret = -ENOENT;
606 dev_err(&pdev->dev, "No IRQ resource\n"); 605 dev_err(&pdev->dev, "No IRQ resource\n");
607 goto err_badres; 606 return -ENOENT;
608 } 607 }
609 608
610 rtc->periodic_irq = ret; 609 rtc->periodic_irq = ret;
@@ -613,24 +612,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
613 612
614 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 613 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
615 if (unlikely(res == NULL)) { 614 if (unlikely(res == NULL)) {
616 ret = -ENOENT;
617 dev_err(&pdev->dev, "No IO resource\n"); 615 dev_err(&pdev->dev, "No IO resource\n");
618 goto err_badres; 616 return -ENOENT;
619 } 617 }
620 618
621 rtc->regsize = resource_size(res); 619 rtc->regsize = resource_size(res);
622 620
623 rtc->res = request_mem_region(res->start, rtc->regsize, pdev->name); 621 rtc->res = devm_request_mem_region(&pdev->dev, res->start,
624 if (unlikely(!rtc->res)) { 622 rtc->regsize, pdev->name);
625 ret = -EBUSY; 623 if (unlikely(!rtc->res))
626 goto err_badres; 624 return -EBUSY;
627 }
628 625
629 rtc->regbase = ioremap_nocache(rtc->res->start, rtc->regsize); 626 rtc->regbase = devm_ioremap_nocache(&pdev->dev, rtc->res->start,
630 if (unlikely(!rtc->regbase)) { 627 rtc->regsize);
631 ret = -EINVAL; 628 if (unlikely(!rtc->regbase))
632 goto err_badmap; 629 return -EINVAL;
633 }
634 630
635 clk_id = pdev->id; 631 clk_id = pdev->id;
636 /* With a single device, the clock id is still "rtc0" */ 632 /* With a single device, the clock id is still "rtc0" */
@@ -639,7 +635,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
639 635
640 snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id); 636 snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id);
641 637
642 rtc->clk = clk_get(&pdev->dev, clk_name); 638 rtc->clk = devm_clk_get(&pdev->dev, clk_name);
643 if (IS_ERR(rtc->clk)) { 639 if (IS_ERR(rtc->clk)) {
644 /* 640 /*
645 * No error handling for rtc->clk intentionally, not all 641 * No error handling for rtc->clk intentionally, not all
@@ -665,8 +661,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
665 661
666 if (rtc->carry_irq <= 0) { 662 if (rtc->carry_irq <= 0) {
667 /* register shared periodic/carry/alarm irq */ 663 /* register shared periodic/carry/alarm irq */
668 ret = request_irq(rtc->periodic_irq, sh_rtc_shared, 664 ret = devm_request_irq(&pdev->dev, rtc->periodic_irq,
669 0, "sh-rtc", rtc); 665 sh_rtc_shared, 0, "sh-rtc", rtc);
670 if (unlikely(ret)) { 666 if (unlikely(ret)) {
671 dev_err(&pdev->dev, 667 dev_err(&pdev->dev,
672 "request IRQ failed with %d, IRQ %d\n", ret, 668 "request IRQ failed with %d, IRQ %d\n", ret,
@@ -675,8 +671,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
675 } 671 }
676 } else { 672 } else {
677 /* register periodic/carry/alarm irqs */ 673 /* register periodic/carry/alarm irqs */
678 ret = request_irq(rtc->periodic_irq, sh_rtc_periodic, 674 ret = devm_request_irq(&pdev->dev, rtc->periodic_irq,
679 0, "sh-rtc period", rtc); 675 sh_rtc_periodic, 0, "sh-rtc period", rtc);
680 if (unlikely(ret)) { 676 if (unlikely(ret)) {
681 dev_err(&pdev->dev, 677 dev_err(&pdev->dev,
682 "request period IRQ failed with %d, IRQ %d\n", 678 "request period IRQ failed with %d, IRQ %d\n",
@@ -684,24 +680,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
684 goto err_unmap; 680 goto err_unmap;
685 } 681 }
686 682
687 ret = request_irq(rtc->carry_irq, sh_rtc_interrupt, 683 ret = devm_request_irq(&pdev->dev, rtc->carry_irq,
688 0, "sh-rtc carry", rtc); 684 sh_rtc_interrupt, 0, "sh-rtc carry", rtc);
689 if (unlikely(ret)) { 685 if (unlikely(ret)) {
690 dev_err(&pdev->dev, 686 dev_err(&pdev->dev,
691 "request carry IRQ failed with %d, IRQ %d\n", 687 "request carry IRQ failed with %d, IRQ %d\n",
692 ret, rtc->carry_irq); 688 ret, rtc->carry_irq);
693 free_irq(rtc->periodic_irq, rtc);
694 goto err_unmap; 689 goto err_unmap;
695 } 690 }
696 691
697 ret = request_irq(rtc->alarm_irq, sh_rtc_alarm, 692 ret = devm_request_irq(&pdev->dev, rtc->alarm_irq,
698 0, "sh-rtc alarm", rtc); 693 sh_rtc_alarm, 0, "sh-rtc alarm", rtc);
699 if (unlikely(ret)) { 694 if (unlikely(ret)) {
700 dev_err(&pdev->dev, 695 dev_err(&pdev->dev,
701 "request alarm IRQ failed with %d, IRQ %d\n", 696 "request alarm IRQ failed with %d, IRQ %d\n",
702 ret, rtc->alarm_irq); 697 ret, rtc->alarm_irq);
703 free_irq(rtc->carry_irq, rtc);
704 free_irq(rtc->periodic_irq, rtc);
705 goto err_unmap; 698 goto err_unmap;
706 } 699 }
707 } 700 }
@@ -714,13 +707,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
714 sh_rtc_setaie(&pdev->dev, 0); 707 sh_rtc_setaie(&pdev->dev, 0);
715 sh_rtc_setcie(&pdev->dev, 0); 708 sh_rtc_setcie(&pdev->dev, 0);
716 709
717 rtc->rtc_dev = rtc_device_register("sh", &pdev->dev, 710 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh",
718 &sh_rtc_ops, THIS_MODULE); 711 &sh_rtc_ops, THIS_MODULE);
719 if (IS_ERR(rtc->rtc_dev)) { 712 if (IS_ERR(rtc->rtc_dev)) {
720 ret = PTR_ERR(rtc->rtc_dev); 713 ret = PTR_ERR(rtc->rtc_dev);
721 free_irq(rtc->periodic_irq, rtc);
722 free_irq(rtc->carry_irq, rtc);
723 free_irq(rtc->alarm_irq, rtc);
724 goto err_unmap; 714 goto err_unmap;
725 } 715 }
726 716
@@ -737,12 +727,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
737 727
738err_unmap: 728err_unmap:
739 clk_disable(rtc->clk); 729 clk_disable(rtc->clk);
740 clk_put(rtc->clk);
741 iounmap(rtc->regbase);
742err_badmap:
743 release_mem_region(rtc->res->start, rtc->regsize);
744err_badres:
745 kfree(rtc);
746 730
747 return ret; 731 return ret;
748} 732}
@@ -751,28 +735,12 @@ static int __exit sh_rtc_remove(struct platform_device *pdev)
751{ 735{
752 struct sh_rtc *rtc = platform_get_drvdata(pdev); 736 struct sh_rtc *rtc = platform_get_drvdata(pdev);
753 737
754 rtc_device_unregister(rtc->rtc_dev);
755 sh_rtc_irq_set_state(&pdev->dev, 0); 738 sh_rtc_irq_set_state(&pdev->dev, 0);
756 739
757 sh_rtc_setaie(&pdev->dev, 0); 740 sh_rtc_setaie(&pdev->dev, 0);
758 sh_rtc_setcie(&pdev->dev, 0); 741 sh_rtc_setcie(&pdev->dev, 0);
759 742
760 free_irq(rtc->periodic_irq, rtc);
761
762 if (rtc->carry_irq > 0) {
763 free_irq(rtc->carry_irq, rtc);
764 free_irq(rtc->alarm_irq, rtc);
765 }
766
767 iounmap(rtc->regbase);
768 release_mem_region(rtc->res->start, rtc->regsize);
769
770 clk_disable(rtc->clk); 743 clk_disable(rtc->clk);
771 clk_put(rtc->clk);
772
773 platform_set_drvdata(pdev, NULL);
774
775 kfree(rtc);
776 744
777 return 0; 745 return 0;
778} 746}
diff --git a/drivers/rtc/rtc-sirfsoc.c b/drivers/rtc/rtc-sirfsoc.c
new file mode 100644
index 000000000000..aa7ed4b5f7f0
--- /dev/null
+++ b/drivers/rtc/rtc-sirfsoc.c
@@ -0,0 +1,475 @@
1/*
2 * SiRFSoC Real Time Clock interface for Linux
3 *
4 * Copyright (c) 2013 Cambridge Silicon Radio Limited, a CSR plc group company.
5 *
6 * Licensed under GPLv2 or later.
7 */
8
9#include <linux/module.h>
10#include <linux/err.h>
11#include <linux/rtc.h>
12#include <linux/platform_device.h>
13#include <linux/slab.h>
14#include <linux/io.h>
15#include <linux/of.h>
16#include <linux/rtc/sirfsoc_rtciobrg.h>
17
18
19#define RTC_CN 0x00
20#define RTC_ALARM0 0x04
21#define RTC_ALARM1 0x18
22#define RTC_STATUS 0x08
23#define RTC_SW_VALUE 0x40
24#define SIRFSOC_RTC_AL1E (1<<6)
25#define SIRFSOC_RTC_AL1 (1<<4)
26#define SIRFSOC_RTC_HZE (1<<3)
27#define SIRFSOC_RTC_AL0E (1<<2)
28#define SIRFSOC_RTC_HZ (1<<1)
29#define SIRFSOC_RTC_AL0 (1<<0)
30#define RTC_DIV 0x0c
31#define RTC_DEEP_CTRL 0x14
32#define RTC_CLOCK_SWITCH 0x1c
33#define SIRFSOC_RTC_CLK 0x03 /* others are reserved */
34
35/* Refer to RTC DIV switch */
36#define RTC_HZ 16
37
38/* This macro is also defined in arch/arm/plat-sirfsoc/cpu.c */
39#define RTC_SHIFT 4
40
41#define INTR_SYSRTC_CN 0x48
42
43struct sirfsoc_rtc_drv {
44 struct rtc_device *rtc;
45 u32 rtc_base;
46 u32 irq;
47 /* Overflow for every 8 years extra time */
48 u32 overflow_rtc;
49#ifdef CONFIG_PM
50 u32 saved_counter;
51 u32 saved_overflow_rtc;
52#endif
53};
54
55static int sirfsoc_rtc_read_alarm(struct device *dev,
56 struct rtc_wkalrm *alrm)
57{
58 unsigned long rtc_alarm, rtc_count;
59 struct sirfsoc_rtc_drv *rtcdrv;
60
61 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev);
62
63 local_irq_disable();
64
65 rtc_count = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
66
67 rtc_alarm = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_ALARM0);
68 memset(alrm, 0, sizeof(struct rtc_wkalrm));
69
70 /*
71 * assume alarm interval not beyond one round counter overflow_rtc:
72 * 0->0xffffffff
73 */
74 /* if alarm is in next overflow cycle */
75 if (rtc_count > rtc_alarm)
76 rtc_time_to_tm((rtcdrv->overflow_rtc + 1)
77 << (BITS_PER_LONG - RTC_SHIFT)
78 | rtc_alarm >> RTC_SHIFT, &(alrm->time));
79 else
80 rtc_time_to_tm(rtcdrv->overflow_rtc
81 << (BITS_PER_LONG - RTC_SHIFT)
82 | rtc_alarm >> RTC_SHIFT, &(alrm->time));
83 if (sirfsoc_rtc_iobrg_readl(
84 rtcdrv->rtc_base + RTC_STATUS) & SIRFSOC_RTC_AL0E)
85 alrm->enabled = 1;
86 local_irq_enable();
87
88 return 0;
89}
90
91static int sirfsoc_rtc_set_alarm(struct device *dev,
92 struct rtc_wkalrm *alrm)
93{
94 unsigned long rtc_status_reg, rtc_alarm;
95 struct sirfsoc_rtc_drv *rtcdrv;
96 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev);
97
98 if (alrm->enabled) {
99 rtc_tm_to_time(&(alrm->time), &rtc_alarm);
100
101 local_irq_disable();
102
103 rtc_status_reg = sirfsoc_rtc_iobrg_readl(
104 rtcdrv->rtc_base + RTC_STATUS);
105 if (rtc_status_reg & SIRFSOC_RTC_AL0E) {
106 /*
107 * An ongoing alarm in progress - ingore it and not
108 * to return EBUSY
109 */
110 dev_info(dev, "An old alarm was set, will be replaced by a new one\n");
111 }
112
113 sirfsoc_rtc_iobrg_writel(
114 rtc_alarm << RTC_SHIFT, rtcdrv->rtc_base + RTC_ALARM0);
115 rtc_status_reg &= ~0x07; /* mask out the lower status bits */
116 /*
117 * This bit RTC_AL sets it as a wake-up source for Sleep Mode
118 * Writing 1 into this bit will clear it
119 */
120 rtc_status_reg |= SIRFSOC_RTC_AL0;
121 /* enable the RTC alarm interrupt */
122 rtc_status_reg |= SIRFSOC_RTC_AL0E;
123 sirfsoc_rtc_iobrg_writel(
124 rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS);
125 local_irq_enable();
126 } else {
127 /*
128 * if this function was called with enabled=0
129 * then it could mean that the application is
130 * trying to cancel an ongoing alarm
131 */
132 local_irq_disable();
133
134 rtc_status_reg = sirfsoc_rtc_iobrg_readl(
135 rtcdrv->rtc_base + RTC_STATUS);
136 if (rtc_status_reg & SIRFSOC_RTC_AL0E) {
137 /* clear the RTC status register's alarm bit */
138 rtc_status_reg &= ~0x07;
139 /* write 1 into SIRFSOC_RTC_AL0 to force a clear */
140 rtc_status_reg |= (SIRFSOC_RTC_AL0);
141 /* Clear the Alarm enable bit */
142 rtc_status_reg &= ~(SIRFSOC_RTC_AL0E);
143
144 sirfsoc_rtc_iobrg_writel(rtc_status_reg,
145 rtcdrv->rtc_base + RTC_STATUS);
146 }
147
148 local_irq_enable();
149 }
150
151 return 0;
152}
153
154static int sirfsoc_rtc_read_time(struct device *dev,
155 struct rtc_time *tm)
156{
157 unsigned long tmp_rtc = 0;
158 struct sirfsoc_rtc_drv *rtcdrv;
159 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev);
160 /*
161 * This patch is taken from WinCE - Need to validate this for
162 * correctness. To work around sirfsoc RTC counter double sync logic
163 * fail, read several times to make sure get stable value.
164 */
165 do {
166 tmp_rtc = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
167 cpu_relax();
168 } while (tmp_rtc != sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN));
169
170 rtc_time_to_tm(rtcdrv->overflow_rtc << (BITS_PER_LONG - RTC_SHIFT) |
171 tmp_rtc >> RTC_SHIFT, tm);
172 return 0;
173}
174
175static int sirfsoc_rtc_set_time(struct device *dev,
176 struct rtc_time *tm)
177{
178 unsigned long rtc_time;
179 struct sirfsoc_rtc_drv *rtcdrv;
180 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev);
181
182 rtc_tm_to_time(tm, &rtc_time);
183
184 rtcdrv->overflow_rtc = rtc_time >> (BITS_PER_LONG - RTC_SHIFT);
185
186 sirfsoc_rtc_iobrg_writel(rtcdrv->overflow_rtc,
187 rtcdrv->rtc_base + RTC_SW_VALUE);
188 sirfsoc_rtc_iobrg_writel(
189 rtc_time << RTC_SHIFT, rtcdrv->rtc_base + RTC_CN);
190
191 return 0;
192}
193
194static int sirfsoc_rtc_ioctl(struct device *dev, unsigned int cmd,
195 unsigned long arg)
196{
197 switch (cmd) {
198 case RTC_PIE_ON:
199 case RTC_PIE_OFF:
200 case RTC_UIE_ON:
201 case RTC_UIE_OFF:
202 case RTC_AIE_ON:
203 case RTC_AIE_OFF:
204 return 0;
205
206 default:
207 return -ENOIOCTLCMD;
208 }
209}
210
211static const struct rtc_class_ops sirfsoc_rtc_ops = {
212 .read_time = sirfsoc_rtc_read_time,
213 .set_time = sirfsoc_rtc_set_time,
214 .read_alarm = sirfsoc_rtc_read_alarm,
215 .set_alarm = sirfsoc_rtc_set_alarm,
216 .ioctl = sirfsoc_rtc_ioctl
217};
218
219static irqreturn_t sirfsoc_rtc_irq_handler(int irq, void *pdata)
220{
221 struct sirfsoc_rtc_drv *rtcdrv = pdata;
222 unsigned long rtc_status_reg = 0x0;
223 unsigned long events = 0x0;
224
225 rtc_status_reg = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_STATUS);
226 /* this bit will be set ONLY if an alarm was active
227 * and it expired NOW
228 * So this is being used as an ASSERT
229 */
230 if (rtc_status_reg & SIRFSOC_RTC_AL0) {
231 /*
232 * clear the RTC status register's alarm bit
233 * mask out the lower status bits
234 */
235 rtc_status_reg &= ~0x07;
236 /* write 1 into SIRFSOC_RTC_AL0 to ACK the alarm interrupt */
237 rtc_status_reg |= (SIRFSOC_RTC_AL0);
238 /* Clear the Alarm enable bit */
239 rtc_status_reg &= ~(SIRFSOC_RTC_AL0E);
240 }
241 sirfsoc_rtc_iobrg_writel(rtc_status_reg, rtcdrv->rtc_base + RTC_STATUS);
242 /* this should wake up any apps polling/waiting on the read
243 * after setting the alarm
244 */
245 events |= RTC_IRQF | RTC_AF;
246 rtc_update_irq(rtcdrv->rtc, 1, events);
247
248 return IRQ_HANDLED;
249}
250
251static const struct of_device_id sirfsoc_rtc_of_match[] = {
252 { .compatible = "sirf,prima2-sysrtc"},
253 {},
254};
255MODULE_DEVICE_TABLE(of, sirfsoc_rtc_of_match);
256
257static int sirfsoc_rtc_probe(struct platform_device *pdev)
258{
259 int err;
260 unsigned long rtc_div;
261 struct sirfsoc_rtc_drv *rtcdrv;
262 struct device_node *np = pdev->dev.of_node;
263
264 rtcdrv = devm_kzalloc(&pdev->dev,
265 sizeof(struct sirfsoc_rtc_drv), GFP_KERNEL);
266 if (rtcdrv == NULL) {
267 dev_err(&pdev->dev,
268 "%s: can't alloc mem for drv struct\n",
269 pdev->name);
270 return -ENOMEM;
271 }
272
273 err = of_property_read_u32(np, "reg", &rtcdrv->rtc_base);
274 if (err) {
275 dev_err(&pdev->dev, "unable to find base address of rtc node in dtb\n");
276 goto error;
277 }
278
279 platform_set_drvdata(pdev, rtcdrv);
280
281 /* Register rtc alarm as a wakeup source */
282 device_init_wakeup(&pdev->dev, 1);
283
284 /*
285 * Set SYS_RTC counter in RTC_HZ HZ Units
286 * We are using 32K RTC crystal (32768 / RTC_HZ / 2) -1
287 * If 16HZ, therefore RTC_DIV = 1023;
288 */
289 rtc_div = ((32768 / RTC_HZ) / 2) - 1;
290 sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV);
291
292 rtcdrv->rtc = rtc_device_register(pdev->name, &(pdev->dev),
293 &sirfsoc_rtc_ops, THIS_MODULE);
294 if (IS_ERR(rtcdrv->rtc)) {
295 err = PTR_ERR(rtcdrv->rtc);
296 dev_err(&pdev->dev, "can't register RTC device\n");
297 return err;
298 }
299
300 /* 0x3 -> RTC_CLK */
301 sirfsoc_rtc_iobrg_writel(SIRFSOC_RTC_CLK,
302 rtcdrv->rtc_base + RTC_CLOCK_SWITCH);
303
304 /* reset SYS RTC ALARM0 */
305 sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM0);
306
307 /* reset SYS RTC ALARM1 */
308 sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM1);
309
310 /* Restore RTC Overflow From Register After Command Reboot */
311 rtcdrv->overflow_rtc =
312 sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_SW_VALUE);
313
314 rtcdrv->irq = platform_get_irq(pdev, 0);
315 err = devm_request_irq(
316 &pdev->dev,
317 rtcdrv->irq,
318 sirfsoc_rtc_irq_handler,
319 IRQF_SHARED,
320 pdev->name,
321 rtcdrv);
322 if (err) {
323 dev_err(&pdev->dev, "Unable to register for the SiRF SOC RTC IRQ\n");
324 goto error;
325 }
326
327 return 0;
328
329error:
330 if (rtcdrv->rtc)
331 rtc_device_unregister(rtcdrv->rtc);
332
333 return err;
334}
335
336static int sirfsoc_rtc_remove(struct platform_device *pdev)
337{
338 struct sirfsoc_rtc_drv *rtcdrv = platform_get_drvdata(pdev);
339
340 device_init_wakeup(&pdev->dev, 0);
341 rtc_device_unregister(rtcdrv->rtc);
342
343 return 0;
344}
345
346#ifdef CONFIG_PM
347
348static int sirfsoc_rtc_suspend(struct device *dev)
349{
350 struct platform_device *pdev = to_platform_device(dev);
351 struct sirfsoc_rtc_drv *rtcdrv = platform_get_drvdata(pdev);
352 rtcdrv->overflow_rtc =
353 sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_SW_VALUE);
354
355 rtcdrv->saved_counter =
356 sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
357 rtcdrv->saved_overflow_rtc = rtcdrv->overflow_rtc;
358 if (device_may_wakeup(&pdev->dev))
359 enable_irq_wake(rtcdrv->irq);
360
361 return 0;
362}
363
364static int sirfsoc_rtc_freeze(struct device *dev)
365{
366 sirfsoc_rtc_suspend(dev);
367
368 return 0;
369}
370
371static int sirfsoc_rtc_thaw(struct device *dev)
372{
373 u32 tmp;
374 struct sirfsoc_rtc_drv *rtcdrv;
375 rtcdrv = (struct sirfsoc_rtc_drv *)dev_get_drvdata(dev);
376
377 /*
378 * if resume from snapshot and the rtc power is losed,
379 * restroe the rtc settings
380 */
381 if (SIRFSOC_RTC_CLK != sirfsoc_rtc_iobrg_readl(
382 rtcdrv->rtc_base + RTC_CLOCK_SWITCH)) {
383 u32 rtc_div;
384 /* 0x3 -> RTC_CLK */
385 sirfsoc_rtc_iobrg_writel(SIRFSOC_RTC_CLK,
386 rtcdrv->rtc_base + RTC_CLOCK_SWITCH);
387 /*
388 * Set SYS_RTC counter in RTC_HZ HZ Units
389 * We are using 32K RTC crystal (32768 / RTC_HZ / 2) -1
390 * If 16HZ, therefore RTC_DIV = 1023;
391 */
392 rtc_div = ((32768 / RTC_HZ) / 2) - 1;
393
394 sirfsoc_rtc_iobrg_writel(rtc_div, rtcdrv->rtc_base + RTC_DIV);
395
396 /* reset SYS RTC ALARM0 */
397 sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM0);
398
399 /* reset SYS RTC ALARM1 */
400 sirfsoc_rtc_iobrg_writel(0x0, rtcdrv->rtc_base + RTC_ALARM1);
401 }
402 rtcdrv->overflow_rtc = rtcdrv->saved_overflow_rtc;
403
404 /*
405 * if current counter is small than previous,
406 * it means overflow in sleep
407 */
408 tmp = sirfsoc_rtc_iobrg_readl(rtcdrv->rtc_base + RTC_CN);
409 if (tmp <= rtcdrv->saved_counter)
410 rtcdrv->overflow_rtc++;
411 /*
412 *PWRC Value Be Changed When Suspend, Restore Overflow
413 * In Memory To Register
414 */
415 sirfsoc_rtc_iobrg_writel(rtcdrv->overflow_rtc,
416 rtcdrv->rtc_base + RTC_SW_VALUE);
417
418 return 0;
419}
420
421static int sirfsoc_rtc_resume(struct device *dev)
422{
423 struct platform_device *pdev = to_platform_device(dev);
424 struct sirfsoc_rtc_drv *rtcdrv = platform_get_drvdata(pdev);
425 sirfsoc_rtc_thaw(dev);
426 if (device_may_wakeup(&pdev->dev))
427 disable_irq_wake(rtcdrv->irq);
428
429 return 0;
430}
431
432static int sirfsoc_rtc_restore(struct device *dev)
433{
434 struct platform_device *pdev = to_platform_device(dev);
435 struct sirfsoc_rtc_drv *rtcdrv = platform_get_drvdata(pdev);
436
437 if (device_may_wakeup(&pdev->dev))
438 disable_irq_wake(rtcdrv->irq);
439 return 0;
440}
441
442#else
443#define sirfsoc_rtc_suspend NULL
444#define sirfsoc_rtc_resume NULL
445#define sirfsoc_rtc_freeze NULL
446#define sirfsoc_rtc_thaw NULL
447#define sirfsoc_rtc_restore NULL
448#endif
449
450static const struct dev_pm_ops sirfsoc_rtc_pm_ops = {
451 .suspend = sirfsoc_rtc_suspend,
452 .resume = sirfsoc_rtc_resume,
453 .freeze = sirfsoc_rtc_freeze,
454 .thaw = sirfsoc_rtc_thaw,
455 .restore = sirfsoc_rtc_restore,
456};
457
458static struct platform_driver sirfsoc_rtc_driver = {
459 .driver = {
460 .name = "sirfsoc-rtc",
461 .owner = THIS_MODULE,
462#ifdef CONFIG_PM
463 .pm = &sirfsoc_rtc_pm_ops,
464#endif
465 .of_match_table = of_match_ptr(sirfsoc_rtc_of_match),
466 },
467 .probe = sirfsoc_rtc_probe,
468 .remove = sirfsoc_rtc_remove,
469};
470module_platform_driver(sirfsoc_rtc_driver);
471
472MODULE_DESCRIPTION("SiRF SoC rtc driver");
473MODULE_AUTHOR("Xianglong Du <Xianglong.Du@csr.com>");
474MODULE_LICENSE("GPL v2");
475MODULE_ALIAS("platform:sirfsoc-rtc");
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index b04f09a1df2a..316a342115b2 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -294,11 +294,6 @@ static int snvs_rtc_probe(struct platform_device *pdev)
294 return 0; 294 return 0;
295} 295}
296 296
297static int snvs_rtc_remove(struct platform_device *pdev)
298{
299 return 0;
300}
301
302#ifdef CONFIG_PM_SLEEP 297#ifdef CONFIG_PM_SLEEP
303static int snvs_rtc_suspend(struct device *dev) 298static int snvs_rtc_suspend(struct device *dev)
304{ 299{
@@ -337,7 +332,6 @@ static struct platform_driver snvs_rtc_driver = {
337 .of_match_table = of_match_ptr(snvs_dt_ids), 332 .of_match_table = of_match_ptr(snvs_dt_ids),
338 }, 333 },
339 .probe = snvs_rtc_probe, 334 .probe = snvs_rtc_probe,
340 .remove = snvs_rtc_remove,
341}; 335};
342module_platform_driver(snvs_rtc_driver); 336module_platform_driver(snvs_rtc_driver);
343 337
diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
index 574359c48f65..c492cf0ab8cd 100644
--- a/drivers/rtc/rtc-spear.c
+++ b/drivers/rtc/rtc-spear.c
@@ -417,7 +417,6 @@ static int spear_rtc_probe(struct platform_device *pdev)
417 return 0; 417 return 0;
418 418
419err_disable_clock: 419err_disable_clock:
420 platform_set_drvdata(pdev, NULL);
421 clk_disable_unprepare(config->clk); 420 clk_disable_unprepare(config->clk);
422 421
423 return status; 422 return status;
diff --git a/drivers/rtc/rtc-starfire.c b/drivers/rtc/rtc-starfire.c
index 987b5ec0ae56..f7d8a6db8078 100644
--- a/drivers/rtc/rtc-starfire.c
+++ b/drivers/rtc/rtc-starfire.c
@@ -51,17 +51,11 @@ static int __init starfire_rtc_probe(struct platform_device *pdev)
51 return 0; 51 return 0;
52} 52}
53 53
54static int __exit starfire_rtc_remove(struct platform_device *pdev)
55{
56 return 0;
57}
58
59static struct platform_driver starfire_rtc_driver = { 54static struct platform_driver starfire_rtc_driver = {
60 .driver = { 55 .driver = {
61 .name = "rtc-starfire", 56 .name = "rtc-starfire",
62 .owner = THIS_MODULE, 57 .owner = THIS_MODULE,
63 }, 58 },
64 .remove = __exit_p(starfire_rtc_remove),
65}; 59};
66 60
67module_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe); 61module_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe);
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index 483ce086990b..90a3e864b8fe 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -225,7 +225,6 @@ static int stmp3xxx_rtc_remove(struct platform_device *pdev)
225 225
226 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 226 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
227 rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 227 rtc_data->io + STMP3XXX_RTC_CTRL_CLR);
228 platform_set_drvdata(pdev, NULL);
229 228
230 return 0; 229 return 0;
231} 230}
@@ -274,25 +273,19 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
274 273
275 rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name, 274 rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
276 &stmp3xxx_rtc_ops, THIS_MODULE); 275 &stmp3xxx_rtc_ops, THIS_MODULE);
277 if (IS_ERR(rtc_data->rtc)) { 276 if (IS_ERR(rtc_data->rtc))
278 err = PTR_ERR(rtc_data->rtc); 277 return PTR_ERR(rtc_data->rtc);
279 goto out;
280 }
281 278
282 err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm, 279 err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm,
283 stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev); 280 stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev);
284 if (err) { 281 if (err) {
285 dev_err(&pdev->dev, "Cannot claim IRQ%d\n", 282 dev_err(&pdev->dev, "Cannot claim IRQ%d\n",
286 rtc_data->irq_alarm); 283 rtc_data->irq_alarm);
287 goto out; 284 return err;
288 } 285 }
289 286
290 stmp3xxx_wdt_register(pdev); 287 stmp3xxx_wdt_register(pdev);
291 return 0; 288 return 0;
292
293out:
294 platform_set_drvdata(pdev, NULL);
295 return err;
296} 289}
297 290
298#ifdef CONFIG_PM_SLEEP 291#ifdef CONFIG_PM_SLEEP
diff --git a/drivers/rtc/rtc-sun4v.c b/drivers/rtc/rtc-sun4v.c
index ce42e5fa9e09..bc97ff91341d 100644
--- a/drivers/rtc/rtc-sun4v.c
+++ b/drivers/rtc/rtc-sun4v.c
@@ -92,17 +92,11 @@ static int __init sun4v_rtc_probe(struct platform_device *pdev)
92 return 0; 92 return 0;
93} 93}
94 94
95static int __exit sun4v_rtc_remove(struct platform_device *pdev)
96{
97 return 0;
98}
99
100static struct platform_driver sun4v_rtc_driver = { 95static struct platform_driver sun4v_rtc_driver = {
101 .driver = { 96 .driver = {
102 .name = "rtc-sun4v", 97 .name = "rtc-sun4v",
103 .owner = THIS_MODULE, 98 .owner = THIS_MODULE,
104 }, 99 },
105 .remove = __exit_p(sun4v_rtc_remove),
106}; 100};
107 101
108module_platform_driver_probe(sun4v_rtc_driver, sun4v_rtc_probe); 102module_platform_driver_probe(sun4v_rtc_driver, sun4v_rtc_probe);
diff --git a/drivers/rtc/rtc-sysfs.c b/drivers/rtc/rtc-sysfs.c
index b70e2bb63645..4b26f8672b2d 100644
--- a/drivers/rtc/rtc-sysfs.c
+++ b/drivers/rtc/rtc-sysfs.c
@@ -164,6 +164,7 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
164{ 164{
165 ssize_t retval; 165 ssize_t retval;
166 unsigned long now, alarm; 166 unsigned long now, alarm;
167 unsigned long push = 0;
167 struct rtc_wkalrm alm; 168 struct rtc_wkalrm alm;
168 struct rtc_device *rtc = to_rtc_device(dev); 169 struct rtc_device *rtc = to_rtc_device(dev);
169 char *buf_ptr; 170 char *buf_ptr;
@@ -180,13 +181,17 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
180 buf_ptr = (char *)buf; 181 buf_ptr = (char *)buf;
181 if (*buf_ptr == '+') { 182 if (*buf_ptr == '+') {
182 buf_ptr++; 183 buf_ptr++;
183 adjust = 1; 184 if (*buf_ptr == '=') {
185 buf_ptr++;
186 push = 1;
187 } else
188 adjust = 1;
184 } 189 }
185 alarm = simple_strtoul(buf_ptr, NULL, 0); 190 alarm = simple_strtoul(buf_ptr, NULL, 0);
186 if (adjust) { 191 if (adjust) {
187 alarm += now; 192 alarm += now;
188 } 193 }
189 if (alarm > now) { 194 if (alarm > now || push) {
190 /* Avoid accidentally clobbering active alarms; we can't 195 /* Avoid accidentally clobbering active alarms; we can't
191 * entirely prevent that here, without even the minimal 196 * entirely prevent that here, without even the minimal
192 * locking from the /dev/rtcN api. 197 * locking from the /dev/rtcN api.
@@ -194,9 +199,14 @@ rtc_sysfs_set_wakealarm(struct device *dev, struct device_attribute *attr,
194 retval = rtc_read_alarm(rtc, &alm); 199 retval = rtc_read_alarm(rtc, &alm);
195 if (retval < 0) 200 if (retval < 0)
196 return retval; 201 return retval;
197 if (alm.enabled) 202 if (alm.enabled) {
198 return -EBUSY; 203 if (push) {
199 204 rtc_tm_to_time(&alm.time, &push);
205 alarm += push;
206 } else
207 return -EBUSY;
208 } else if (push)
209 return -EINVAL;
200 alm.enabled = 1; 210 alm.enabled = 1;
201 } else { 211 } else {
202 alm.enabled = 0; 212 alm.enabled = 0;
diff --git a/drivers/rtc/rtc-tile.c b/drivers/rtc/rtc-tile.c
index fc3dee95f166..ff9632eb79f2 100644
--- a/drivers/rtc/rtc-tile.c
+++ b/drivers/rtc/rtc-tile.c
@@ -91,23 +91,12 @@ static int tile_rtc_probe(struct platform_device *dev)
91 return 0; 91 return 0;
92} 92}
93 93
94/*
95 * Device cleanup routine.
96 */
97static int tile_rtc_remove(struct platform_device *dev)
98{
99 platform_set_drvdata(dev, NULL);
100
101 return 0;
102}
103
104static struct platform_driver tile_rtc_platform_driver = { 94static struct platform_driver tile_rtc_platform_driver = {
105 .driver = { 95 .driver = {
106 .name = "rtc-tile", 96 .name = "rtc-tile",
107 .owner = THIS_MODULE, 97 .owner = THIS_MODULE,
108 }, 98 },
109 .probe = tile_rtc_probe, 99 .probe = tile_rtc_probe,
110 .remove = tile_rtc_remove,
111}; 100};
112 101
113/* 102/*
diff --git a/drivers/rtc/rtc-tps80031.c b/drivers/rtc/rtc-tps80031.c
index 72662eafb938..3e400dce2d06 100644
--- a/drivers/rtc/rtc-tps80031.c
+++ b/drivers/rtc/rtc-tps80031.c
@@ -298,11 +298,6 @@ static int tps80031_rtc_probe(struct platform_device *pdev)
298 return 0; 298 return 0;
299} 299}
300 300
301static int tps80031_rtc_remove(struct platform_device *pdev)
302{
303 return 0;
304}
305
306#ifdef CONFIG_PM_SLEEP 301#ifdef CONFIG_PM_SLEEP
307static int tps80031_rtc_suspend(struct device *dev) 302static int tps80031_rtc_suspend(struct device *dev)
308{ 303{
@@ -333,7 +328,6 @@ static struct platform_driver tps80031_rtc_driver = {
333 .pm = &tps80031_pm_ops, 328 .pm = &tps80031_pm_ops,
334 }, 329 },
335 .probe = tps80031_rtc_probe, 330 .probe = tps80031_rtc_probe,
336 .remove = tps80031_rtc_remove,
337}; 331};
338 332
339module_platform_driver(tps80031_rtc_driver); 333module_platform_driver(tps80031_rtc_driver);
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index b2eab34f38d9..02faf3c4e0d5 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -213,12 +213,24 @@ static int mask_rtc_irq_bit(unsigned char bit)
213 213
214static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled) 214static int twl_rtc_alarm_irq_enable(struct device *dev, unsigned enabled)
215{ 215{
216 struct platform_device *pdev = to_platform_device(dev);
217 int irq = platform_get_irq(pdev, 0);
218 static bool twl_rtc_wake_enabled;
216 int ret; 219 int ret;
217 220
218 if (enabled) 221 if (enabled) {
219 ret = set_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M); 222 ret = set_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
220 else 223 if (device_can_wakeup(dev) && !twl_rtc_wake_enabled) {
224 enable_irq_wake(irq);
225 twl_rtc_wake_enabled = true;
226 }
227 } else {
221 ret = mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M); 228 ret = mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_ALARM_M);
229 if (twl_rtc_wake_enabled) {
230 disable_irq_wake(irq);
231 twl_rtc_wake_enabled = false;
232 }
233 }
222 234
223 return ret; 235 return ret;
224} 236}
@@ -469,6 +481,12 @@ static int twl_rtc_probe(struct platform_device *pdev)
469 if (irq <= 0) 481 if (irq <= 0)
470 goto out1; 482 goto out1;
471 483
484 /* Initialize the register map */
485 if (twl_class_is_4030())
486 rtc_reg_map = (u8 *)twl4030_rtc_reg_map;
487 else
488 rtc_reg_map = (u8 *)twl6030_rtc_reg_map;
489
472 ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG); 490 ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
473 if (ret < 0) 491 if (ret < 0)
474 goto out1; 492 goto out1;
@@ -556,7 +574,6 @@ static int twl_rtc_remove(struct platform_device *pdev)
556 free_irq(irq, rtc); 574 free_irq(irq, rtc);
557 575
558 rtc_device_unregister(rtc); 576 rtc_device_unregister(rtc);
559 platform_set_drvdata(pdev, NULL);
560 return 0; 577 return 0;
561} 578}
562 579
@@ -609,22 +626,7 @@ static struct platform_driver twl4030rtc_driver = {
609 }, 626 },
610}; 627};
611 628
612static int __init twl_rtc_init(void) 629module_platform_driver(twl4030rtc_driver);
613{
614 if (twl_class_is_4030())
615 rtc_reg_map = (u8 *) twl4030_rtc_reg_map;
616 else
617 rtc_reg_map = (u8 *) twl6030_rtc_reg_map;
618
619 return platform_driver_register(&twl4030rtc_driver);
620}
621module_init(twl_rtc_init);
622
623static void __exit twl_rtc_exit(void)
624{
625 platform_driver_unregister(&twl4030rtc_driver);
626}
627module_exit(twl_rtc_exit);
628 630
629MODULE_AUTHOR("Texas Instruments, MontaVista Software"); 631MODULE_AUTHOR("Texas Instruments, MontaVista Software");
630MODULE_LICENSE("GPL"); 632MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index 6e0cba8f47d5..d07d89823020 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -16,7 +16,7 @@
16 * - Use the generic rtc class 16 * - Use the generic rtc class
17 * 17 *
18 * ??-???-2004: Someone at Compulab 18 * ??-???-2004: Someone at Compulab
19 * - Initial driver creation. 19 * - Initial driver creation.
20 * 20 *
21 */ 21 */
22#include <linux/platform_device.h> 22#include <linux/platform_device.h>
@@ -278,13 +278,13 @@ static int v3020_set_time(struct device *dev, struct rtc_time *dt)
278 dev_dbg(dev, "tm_year: %i\n", dt->tm_year); 278 dev_dbg(dev, "tm_year: %i\n", dt->tm_year);
279 279
280 /* Write all the values to ram... */ 280 /* Write all the values to ram... */
281 v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec)); 281 v3020_set_reg(chip, V3020_SECONDS, bin2bcd(dt->tm_sec));
282 v3020_set_reg(chip, V3020_MINUTES, bin2bcd(dt->tm_min)); 282 v3020_set_reg(chip, V3020_MINUTES, bin2bcd(dt->tm_min));
283 v3020_set_reg(chip, V3020_HOURS, bin2bcd(dt->tm_hour)); 283 v3020_set_reg(chip, V3020_HOURS, bin2bcd(dt->tm_hour));
284 v3020_set_reg(chip, V3020_MONTH_DAY, bin2bcd(dt->tm_mday)); 284 v3020_set_reg(chip, V3020_MONTH_DAY, bin2bcd(dt->tm_mday));
285 v3020_set_reg(chip, V3020_MONTH, bin2bcd(dt->tm_mon + 1)); 285 v3020_set_reg(chip, V3020_MONTH, bin2bcd(dt->tm_mon + 1));
286 v3020_set_reg(chip, V3020_WEEK_DAY, bin2bcd(dt->tm_wday)); 286 v3020_set_reg(chip, V3020_WEEK_DAY, bin2bcd(dt->tm_wday));
287 v3020_set_reg(chip, V3020_YEAR, bin2bcd(dt->tm_year % 100)); 287 v3020_set_reg(chip, V3020_YEAR, bin2bcd(dt->tm_year % 100));
288 288
289 /* ...and set the clock. */ 289 /* ...and set the clock. */
290 v3020_set_reg(chip, V3020_CMD_RAM2CLOCK, 0); 290 v3020_set_reg(chip, V3020_CMD_RAM2CLOCK, 0);
@@ -320,7 +320,7 @@ static int rtc_probe(struct platform_device *pdev)
320 320
321 retval = chip->ops->map_io(chip, pdev, pdata); 321 retval = chip->ops->map_io(chip, pdev, pdata);
322 if (retval) 322 if (retval)
323 goto err_chip; 323 return retval;
324 324
325 /* Make sure the v3020 expects a communication cycle 325 /* Make sure the v3020 expects a communication cycle
326 * by reading 8 times */ 326 * by reading 8 times */
@@ -364,7 +364,7 @@ static int rtc_probe(struct platform_device *pdev)
364 364
365err_io: 365err_io:
366 chip->ops->unmap_io(chip); 366 chip->ops->unmap_io(chip);
367err_chip: 367
368 return retval; 368 return retval;
369} 369}
370 370
diff --git a/drivers/rtc/rtc-vr41xx.c b/drivers/rtc/rtc-vr41xx.c
index f91be04b9050..54e104e197e3 100644
--- a/drivers/rtc/rtc-vr41xx.c
+++ b/drivers/rtc/rtc-vr41xx.c
@@ -103,7 +103,7 @@ static inline unsigned long read_elapsed_second(void)
103 second_mid = rtc1_read(ETIMEMREG); 103 second_mid = rtc1_read(ETIMEMREG);
104 second_high = rtc1_read(ETIMEHREG); 104 second_high = rtc1_read(ETIMEHREG);
105 } while (first_low != second_low || first_mid != second_mid || 105 } while (first_low != second_low || first_mid != second_mid ||
106 first_high != second_high); 106 first_high != second_high);
107 107
108 return (first_high << 17) | (first_mid << 1) | (first_low >> 15); 108 return (first_high << 17) | (first_mid << 1) | (first_low >> 15);
109} 109}
@@ -154,7 +154,7 @@ static int vr41xx_rtc_set_time(struct device *dev, struct rtc_time *time)
154 154
155 epoch_sec = mktime(epoch, 1, 1, 0, 0, 0); 155 epoch_sec = mktime(epoch, 1, 1, 0, 0, 0);
156 current_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, 156 current_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
157 time->tm_hour, time->tm_min, time->tm_sec); 157 time->tm_hour, time->tm_min, time->tm_sec);
158 158
159 write_elapsed_second(current_sec - epoch_sec); 159 write_elapsed_second(current_sec - epoch_sec);
160 160
@@ -186,7 +186,7 @@ static int vr41xx_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *wkalrm)
186 struct rtc_time *time = &wkalrm->time; 186 struct rtc_time *time = &wkalrm->time;
187 187
188 alarm_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday, 188 alarm_sec = mktime(time->tm_year + 1900, time->tm_mon + 1, time->tm_mday,
189 time->tm_hour, time->tm_min, time->tm_sec); 189 time->tm_hour, time->tm_min, time->tm_sec);
190 190
191 spin_lock_irq(&rtc_lock); 191 spin_lock_irq(&rtc_lock);
192 192
@@ -334,16 +334,18 @@ static int rtc_probe(struct platform_device *pdev)
334 } 334 }
335 335
336 retval = request_irq(aie_irq, elapsedtime_interrupt, 0, 336 retval = request_irq(aie_irq, elapsedtime_interrupt, 0,
337 "elapsed_time", pdev); 337 "elapsed_time", pdev);
338 if (retval < 0) 338 if (retval < 0)
339 goto err_device_unregister; 339 goto err_device_unregister;
340 340
341 pie_irq = platform_get_irq(pdev, 1); 341 pie_irq = platform_get_irq(pdev, 1);
342 if (pie_irq <= 0) 342 if (pie_irq <= 0) {
343 retval = -EBUSY;
343 goto err_free_irq; 344 goto err_free_irq;
345 }
344 346
345 retval = request_irq(pie_irq, rtclong1_interrupt, 0, 347 retval = request_irq(pie_irq, rtclong1_interrupt, 0,
346 "rtclong1", pdev); 348 "rtclong1", pdev);
347 if (retval < 0) 349 if (retval < 0)
348 goto err_free_irq; 350 goto err_free_irq;
349 351
@@ -381,8 +383,6 @@ static int rtc_remove(struct platform_device *pdev)
381 if (rtc) 383 if (rtc)
382 rtc_device_unregister(rtc); 384 rtc_device_unregister(rtc);
383 385
384 platform_set_drvdata(pdev, NULL);
385
386 free_irq(aie_irq, pdev); 386 free_irq(aie_irq, pdev);
387 free_irq(pie_irq, pdev); 387 free_irq(pie_irq, pdev);
388 if (rtc1_base) 388 if (rtc1_base)
diff --git a/drivers/rtc/rtc-vt8500.c b/drivers/rtc/rtc-vt8500.c
index d89efee6d29e..c2d6331fc712 100644
--- a/drivers/rtc/rtc-vt8500.c
+++ b/drivers/rtc/rtc-vt8500.c
@@ -282,8 +282,6 @@ static int vt8500_rtc_remove(struct platform_device *pdev)
282 /* Disable alarm matching */ 282 /* Disable alarm matching */
283 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS); 283 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS);
284 284
285 platform_set_drvdata(pdev, NULL);
286
287 return 0; 285 return 0;
288} 286}
289 287
diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index 8d65b94e5a7e..75aea4c4d334 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -460,11 +460,6 @@ err:
460 return ret; 460 return ret;
461} 461}
462 462
463static int wm831x_rtc_remove(struct platform_device *pdev)
464{
465 return 0;
466}
467
468static const struct dev_pm_ops wm831x_rtc_pm_ops = { 463static const struct dev_pm_ops wm831x_rtc_pm_ops = {
469 .suspend = wm831x_rtc_suspend, 464 .suspend = wm831x_rtc_suspend,
470 .resume = wm831x_rtc_resume, 465 .resume = wm831x_rtc_resume,
@@ -478,7 +473,6 @@ static const struct dev_pm_ops wm831x_rtc_pm_ops = {
478 473
479static struct platform_driver wm831x_rtc_driver = { 474static struct platform_driver wm831x_rtc_driver = {
480 .probe = wm831x_rtc_probe, 475 .probe = wm831x_rtc_probe,
481 .remove = wm831x_rtc_remove,
482 .driver = { 476 .driver = {
483 .name = "wm831x-rtc", 477 .name = "wm831x-rtc",
484 .pm = &wm831x_rtc_pm_ops, 478 .pm = &wm831x_rtc_pm_ops,
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index fa9b0679fb60..365dc6505148 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -4,7 +4,7 @@
4 * Copyright 2005 Alessandro Zummo 4 * Copyright 2005 Alessandro Zummo
5 * 5 *
6 * please send all reports to: 6 * please send all reports to:
7 * Karen Spearel <kas111 at gmail dot com> 7 * Karen Spearel <kas111 at gmail dot com>
8 * Alessandro Zummo <a.zummo@towertech.it> 8 * Alessandro Zummo <a.zummo@towertech.it>
9 * 9 *
10 * based on a lot of other RTC drivers. 10 * based on a lot of other RTC drivers.
@@ -215,12 +215,14 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
215 buf[i] |= 0x80; 215 buf[i] |= 0x80;
216 216
217 /* this sequence is required to unlock the chip */ 217 /* this sequence is required to unlock the chip */
218 if ((xfer = i2c_master_send(client, wel, 3)) != 3) { 218 xfer = i2c_master_send(client, wel, 3);
219 if (xfer != 3) {
219 dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer); 220 dev_err(&client->dev, "%s: wel - %d\n", __func__, xfer);
220 return -EIO; 221 return -EIO;
221 } 222 }
222 223
223 if ((xfer = i2c_master_send(client, rwel, 3)) != 3) { 224 xfer = i2c_master_send(client, rwel, 3);
225 if (xfer != 3) {
224 dev_err(&client->dev, "%s: rwel - %d\n", __func__, xfer); 226 dev_err(&client->dev, "%s: rwel - %d\n", __func__, xfer);
225 return -EIO; 227 return -EIO;
226 } 228 }
@@ -269,7 +271,8 @@ static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
269 } 271 }
270 272
271 /* disable further writes */ 273 /* disable further writes */
272 if ((xfer = i2c_master_send(client, diswe, 3)) != 3) { 274 xfer = i2c_master_send(client, diswe, 3);
275 if (xfer != 3) {
273 dev_err(&client->dev, "%s: diswe - %d\n", __func__, xfer); 276 dev_err(&client->dev, "%s: diswe - %d\n", __func__, xfer);
274 return -EIO; 277 return -EIO;
275 } 278 }
@@ -375,8 +378,7 @@ static int x1205_get_atrim(struct i2c_client *client, int *trim)
375 return 0; 378 return 0;
376} 379}
377 380
378struct x1205_limit 381struct x1205_limit {
379{
380 unsigned char reg, mask, min, max; 382 unsigned char reg, mask, min, max;
381}; 383};
382 384
@@ -430,7 +432,8 @@ static int x1205_validate_client(struct i2c_client *client)
430 }, 432 },
431 }; 433 };
432 434
433 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 435 xfer = i2c_transfer(client->adapter, msgs, 2);
436 if (xfer != 2) {
434 dev_err(&client->dev, 437 dev_err(&client->dev,
435 "%s: could not read register %x\n", 438 "%s: could not read register %x\n",
436 __func__, probe_zero_pattern[i]); 439 __func__, probe_zero_pattern[i]);
@@ -467,7 +470,8 @@ static int x1205_validate_client(struct i2c_client *client)
467 }, 470 },
468 }; 471 };
469 472
470 if ((xfer = i2c_transfer(client->adapter, msgs, 2)) != 2) { 473 xfer = i2c_transfer(client->adapter, msgs, 2);
474 if (xfer != 2) {
471 dev_err(&client->dev, 475 dev_err(&client->dev,
472 "%s: could not read register %x\n", 476 "%s: could not read register %x\n",
473 __func__, probe_limits_pattern[i].reg); 477 __func__, probe_limits_pattern[i].reg);
@@ -548,10 +552,12 @@ static int x1205_rtc_proc(struct device *dev, struct seq_file *seq)
548{ 552{
549 int err, dtrim, atrim; 553 int err, dtrim, atrim;
550 554
551 if ((err = x1205_get_dtrim(to_i2c_client(dev), &dtrim)) == 0) 555 err = x1205_get_dtrim(to_i2c_client(dev), &dtrim);
556 if (!err)
552 seq_printf(seq, "digital_trim\t: %d ppm\n", dtrim); 557 seq_printf(seq, "digital_trim\t: %d ppm\n", dtrim);
553 558
554 if ((err = x1205_get_atrim(to_i2c_client(dev), &atrim)) == 0) 559 err = x1205_get_atrim(to_i2c_client(dev), &atrim);
560 if (!err)
555 seq_printf(seq, "analog_trim\t: %d.%02d pF\n", 561 seq_printf(seq, "analog_trim\t: %d.%02d pF\n",
556 atrim / 1000, atrim % 1000); 562 atrim / 1000, atrim % 1000);
557 return 0; 563 return 0;
@@ -639,7 +645,8 @@ static int x1205_probe(struct i2c_client *client,
639 i2c_set_clientdata(client, rtc); 645 i2c_set_clientdata(client, rtc);
640 646
641 /* Check for power failures and eventually enable the osc */ 647 /* Check for power failures and eventually enable the osc */
642 if ((err = x1205_get_status(client, &sr)) == 0) { 648 err = x1205_get_status(client, &sr);
649 if (!err) {
643 if (sr & X1205_SR_RTCF) { 650 if (sr & X1205_SR_RTCF) {
644 dev_err(&client->dev, 651 dev_err(&client->dev,
645 "power failure detected, " 652 "power failure detected, "
@@ -647,9 +654,9 @@ static int x1205_probe(struct i2c_client *client,
647 udelay(50); 654 udelay(50);
648 x1205_fix_osc(client); 655 x1205_fix_osc(client);
649 } 656 }
650 } 657 } else {
651 else
652 dev_err(&client->dev, "couldn't read status\n"); 658 dev_err(&client->dev, "couldn't read status\n");
659 }
653 660
654 err = x1205_sysfs_register(&client->dev); 661 err = x1205_sysfs_register(&client->dev);
655 if (err) 662 if (err)
diff --git a/drivers/s390/net/qeth_l3_sys.c b/drivers/s390/net/qeth_l3_sys.c
index e70af2406ff9..d1c8025b0b03 100644
--- a/drivers/s390/net/qeth_l3_sys.c
+++ b/drivers/s390/net/qeth_l3_sys.c
@@ -315,10 +315,8 @@ static ssize_t qeth_l3_dev_hsuid_store(struct device *dev,
315 if (qeth_configure_cq(card, QETH_CQ_ENABLED)) 315 if (qeth_configure_cq(card, QETH_CQ_ENABLED))
316 return -EPERM; 316 return -EPERM;
317 317
318 for (i = 0; i < 8; i++) 318 snprintf(card->options.hsuid, sizeof(card->options.hsuid),
319 card->options.hsuid[i] = ' '; 319 "%-8s", tmp);
320 card->options.hsuid[8] = '\0';
321 strncpy(card->options.hsuid, tmp, strlen(tmp));
322 ASCEBC(card->options.hsuid, 8); 320 ASCEBC(card->options.hsuid, 8);
323 if (card->dev) 321 if (card->dev)
324 memcpy(card->dev->perm_addr, card->options.hsuid, 9); 322 memcpy(card->dev->perm_addr, card->options.hsuid, 9);
diff --git a/drivers/scsi/aacraid/commctrl.c b/drivers/scsi/aacraid/commctrl.c
index 1ef041bc60c8..d85ac1a9d2c0 100644
--- a/drivers/scsi/aacraid/commctrl.c
+++ b/drivers/scsi/aacraid/commctrl.c
@@ -318,7 +318,8 @@ return_fib:
318 kthread_stop(dev->thread); 318 kthread_stop(dev->thread);
319 ssleep(1); 319 ssleep(1);
320 dev->aif_thread = 0; 320 dev->aif_thread = 0;
321 dev->thread = kthread_run(aac_command_thread, dev, dev->name); 321 dev->thread = kthread_run(aac_command_thread, dev,
322 "%s", dev->name);
322 ssleep(1); 323 ssleep(1);
323 } 324 }
324 if (f.wait) { 325 if (f.wait) {
diff --git a/drivers/scsi/aacraid/commsup.c b/drivers/scsi/aacraid/commsup.c
index 1be0776a80c4..cab190af6345 100644
--- a/drivers/scsi/aacraid/commsup.c
+++ b/drivers/scsi/aacraid/commsup.c
@@ -1336,7 +1336,8 @@ static int _aac_reset_adapter(struct aac_dev *aac, int forced)
1336 if ((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(32)))) 1336 if ((retval = pci_set_dma_mask(aac->pdev, DMA_BIT_MASK(32))))
1337 goto out; 1337 goto out;
1338 if (jafo) { 1338 if (jafo) {
1339 aac->thread = kthread_run(aac_command_thread, aac, aac->name); 1339 aac->thread = kthread_run(aac_command_thread, aac, "%s",
1340 aac->name);
1340 if (IS_ERR(aac->thread)) { 1341 if (IS_ERR(aac->thread)) {
1341 retval = PTR_ERR(aac->thread); 1342 retval = PTR_ERR(aac->thread);
1342 goto out; 1343 goto out;
diff --git a/drivers/scsi/be2iscsi/be_main.c b/drivers/scsi/be2iscsi/be_main.c
index d24a2867bc21..a1f5ac7a9806 100644
--- a/drivers/scsi/be2iscsi/be_main.c
+++ b/drivers/scsi/be2iscsi/be_main.c
@@ -4996,7 +4996,7 @@ static int beiscsi_dev_probe(struct pci_dev *pcidev,
4996 4996
4997 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq", 4997 snprintf(phba->wq_name, sizeof(phba->wq_name), "beiscsi_%02x_wq",
4998 phba->shost->host_no); 4998 phba->shost->host_no);
4999 phba->wq = alloc_workqueue(phba->wq_name, WQ_MEM_RECLAIM, 1); 4999 phba->wq = alloc_workqueue("%s", WQ_MEM_RECLAIM, 1, phba->wq_name);
5000 if (!phba->wq) { 5000 if (!phba->wq) {
5001 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT, 5001 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
5002 "BM_%d : beiscsi_dev_probe-" 5002 "BM_%d : beiscsi_dev_probe-"
diff --git a/drivers/scsi/osd/osd_uld.c b/drivers/scsi/osd/osd_uld.c
index 0fab6b5c7b82..9d86947d67fe 100644
--- a/drivers/scsi/osd/osd_uld.c
+++ b/drivers/scsi/osd/osd_uld.c
@@ -485,7 +485,7 @@ static int osd_probe(struct device *dev)
485 oud->class_dev.class = &osd_uld_class; 485 oud->class_dev.class = &osd_uld_class;
486 oud->class_dev.parent = dev; 486 oud->class_dev.parent = dev;
487 oud->class_dev.release = __remove; 487 oud->class_dev.release = __remove;
488 error = dev_set_name(&oud->class_dev, disk->disk_name); 488 error = dev_set_name(&oud->class_dev, "%s", disk->disk_name);
489 if (error) { 489 if (error) {
490 OSD_ERR("dev_set_name failed => %d\n", error); 490 OSD_ERR("dev_set_name failed => %d\n", error);
491 goto err_put_cdev; 491 goto err_put_cdev;
diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
index 4d231c12463e..b246b3c26912 100644
--- a/drivers/scsi/qla4xxx/ql4_os.c
+++ b/drivers/scsi/qla4xxx/ql4_os.c
@@ -7060,8 +7060,8 @@ skip_retry_init:
7060 } 7060 }
7061 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc); 7061 INIT_WORK(&ha->dpc_work, qla4xxx_do_dpc);
7062 7062
7063 sprintf(buf, "qla4xxx_%lu_task", ha->host_no); 7063 ha->task_wq = alloc_workqueue("qla4xxx_%lu_task", WQ_MEM_RECLAIM, 1,
7064 ha->task_wq = alloc_workqueue(buf, WQ_MEM_RECLAIM, 1); 7064 ha->host_no);
7065 if (!ha->task_wq) { 7065 if (!ha->task_wq) {
7066 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n"); 7066 ql4_printk(KERN_WARNING, ha, "Unable to start task thread!\n");
7067 ret = -ENODEV; 7067 ret = -ENODEV;
diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
index e106c276aa00..4628fd5e0688 100644
--- a/drivers/scsi/scsi_transport_fc.c
+++ b/drivers/scsi/scsi_transport_fc.c
@@ -435,7 +435,7 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
435 435
436 snprintf(fc_host->work_q_name, sizeof(fc_host->work_q_name), 436 snprintf(fc_host->work_q_name, sizeof(fc_host->work_q_name),
437 "fc_wq_%d", shost->host_no); 437 "fc_wq_%d", shost->host_no);
438 fc_host->work_q = alloc_workqueue(fc_host->work_q_name, 0, 0); 438 fc_host->work_q = alloc_workqueue("%s", 0, 0, fc_host->work_q_name);
439 if (!fc_host->work_q) 439 if (!fc_host->work_q)
440 return -ENOMEM; 440 return -ENOMEM;
441 441
@@ -443,8 +443,8 @@ static int fc_host_setup(struct transport_container *tc, struct device *dev,
443 snprintf(fc_host->devloss_work_q_name, 443 snprintf(fc_host->devloss_work_q_name,
444 sizeof(fc_host->devloss_work_q_name), 444 sizeof(fc_host->devloss_work_q_name),
445 "fc_dl_%d", shost->host_no); 445 "fc_dl_%d", shost->host_no);
446 fc_host->devloss_work_q = 446 fc_host->devloss_work_q = alloc_workqueue("%s", 0, 0,
447 alloc_workqueue(fc_host->devloss_work_q_name, 0, 0); 447 fc_host->devloss_work_q_name);
448 if (!fc_host->devloss_work_q) { 448 if (!fc_host->devloss_work_q) {
449 destroy_workqueue(fc_host->work_q); 449 destroy_workqueue(fc_host->work_q);
450 fc_host->work_q = NULL; 450 fc_host->work_q = NULL;
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index c1c555242d0d..8fa3d0b73ad9 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2931,7 +2931,7 @@ static int sd_probe(struct device *dev)
2931 device_initialize(&sdkp->dev); 2931 device_initialize(&sdkp->dev);
2932 sdkp->dev.parent = dev; 2932 sdkp->dev.parent = dev;
2933 sdkp->dev.class = &sd_disk_class; 2933 sdkp->dev.class = &sd_disk_class;
2934 dev_set_name(&sdkp->dev, dev_name(dev)); 2934 dev_set_name(&sdkp->dev, "%s", dev_name(dev));
2935 2935
2936 if (device_add(&sdkp->dev)) 2936 if (device_add(&sdkp->dev))
2937 goto out_free_index; 2937 goto out_free_index;
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 095cfaded1c0..978dda2c5239 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -601,7 +601,7 @@ static int spi_init_queue(struct spi_master *master)
601 601
602 init_kthread_worker(&master->kworker); 602 init_kthread_worker(&master->kworker);
603 master->kworker_task = kthread_run(kthread_worker_fn, 603 master->kworker_task = kthread_run(kthread_worker_fn,
604 &master->kworker, 604 &master->kworker, "%s",
605 dev_name(&master->dev)); 605 dev_name(&master->dev));
606 if (IS_ERR(master->kworker_task)) { 606 if (IS_ERR(master->kworker_task)) {
607 dev_err(&master->dev, "failed to create message pump task\n"); 607 dev_err(&master->dev, "failed to create message pump task\n");
diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
index ec9e2ae2de0d..ee3a57f22832 100644
--- a/drivers/staging/android/timed_output.c
+++ b/drivers/staging/android/timed_output.c
@@ -78,7 +78,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
78 78
79 tdev->index = atomic_inc_return(&device_count); 79 tdev->index = atomic_inc_return(&device_count);
80 tdev->dev = device_create(timed_output_class, NULL, 80 tdev->dev = device_create(timed_output_class, NULL,
81 MKDEV(0, tdev->index), NULL, tdev->name); 81 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
82 if (IS_ERR(tdev->dev)) 82 if (IS_ERR(tdev->dev))
83 return PTR_ERR(tdev->dev); 83 return PTR_ERR(tdev->dev);
84 84
diff --git a/drivers/staging/dgrp/dgrp_sysfs.c b/drivers/staging/dgrp/dgrp_sysfs.c
index 7d1b36d1e75f..8cee9c8bc38b 100644
--- a/drivers/staging/dgrp/dgrp_sysfs.c
+++ b/drivers/staging/dgrp/dgrp_sysfs.c
@@ -273,7 +273,7 @@ void dgrp_create_node_class_sysfs_files(struct nd_struct *nd)
273 sprintf(name, "node%ld", nd->nd_major); 273 sprintf(name, "node%ld", nd->nd_major);
274 274
275 nd->nd_class_dev = device_create(dgrp_class, dgrp_class_nodes_dev, 275 nd->nd_class_dev = device_create(dgrp_class, dgrp_class_nodes_dev,
276 MKDEV(0, nd->nd_major), NULL, name); 276 MKDEV(0, nd->nd_major), NULL, "%s", name);
277 277
278 ret = sysfs_create_group(&nd->nd_class_dev->kobj, 278 ret = sysfs_create_group(&nd->nd_class_dev->kobj,
279 &dgrp_node_attribute_group); 279 &dgrp_node_attribute_group);
diff --git a/drivers/staging/rtl8712/os_intfs.c b/drivers/staging/rtl8712/os_intfs.c
index b65bf5e177a8..6e81ba0eaf1e 100644
--- a/drivers/staging/rtl8712/os_intfs.c
+++ b/drivers/staging/rtl8712/os_intfs.c
@@ -238,7 +238,7 @@ struct net_device *r8712_init_netdev(void)
238 238
239static u32 start_drv_threads(struct _adapter *padapter) 239static u32 start_drv_threads(struct _adapter *padapter)
240{ 240{
241 padapter->cmdThread = kthread_run(r8712_cmd_thread, padapter, 241 padapter->cmdThread = kthread_run(r8712_cmd_thread, padapter, "%s",
242 padapter->pnetdev->name); 242 padapter->pnetdev->name);
243 if (IS_ERR(padapter->cmdThread) < 0) 243 if (IS_ERR(padapter->cmdThread) < 0)
244 return _FAIL; 244 return _FAIL;
diff --git a/drivers/staging/tidspbridge/rmgr/drv_interface.c b/drivers/staging/tidspbridge/rmgr/drv_interface.c
index 9c020562c846..6d04eb48bfbc 100644
--- a/drivers/staging/tidspbridge/rmgr/drv_interface.c
+++ b/drivers/staging/tidspbridge/rmgr/drv_interface.c
@@ -421,12 +421,11 @@ static int omap3_bridge_startup(struct platform_device *pdev)
421 drv_datap->tc_wordswapon = tc_wordswapon; 421 drv_datap->tc_wordswapon = tc_wordswapon;
422 422
423 if (base_img) { 423 if (base_img) {
424 drv_datap->base_img = kmalloc(strlen(base_img) + 1, GFP_KERNEL); 424 drv_datap->base_img = kstrdup(base_img, GFP_KERNEL);
425 if (!drv_datap->base_img) { 425 if (!drv_datap->base_img) {
426 err = -ENOMEM; 426 err = -ENOMEM;
427 goto err2; 427 goto err2;
428 } 428 }
429 strncpy(drv_datap->base_img, base_img, strlen(base_img) + 1);
430 } 429 }
431 430
432 dev_set_drvdata(bridge, drv_datap); 431 dev_set_drvdata(bridge, drv_datap);
diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
index b645c47501b4..3b96f18593b3 100644
--- a/drivers/uio/uio.c
+++ b/drivers/uio/uio.c
@@ -677,7 +677,7 @@ static int uio_mmap(struct file *filep, struct vm_area_struct *vma)
677 if (mi < 0) 677 if (mi < 0)
678 return -EINVAL; 678 return -EINVAL;
679 679
680 requested_pages = (vma->vm_end - vma->vm_start) >> PAGE_SHIFT; 680 requested_pages = vma_pages(vma);
681 actual_pages = ((idev->info->mem[mi].addr & ~PAGE_MASK) 681 actual_pages = ((idev->info->mem[mi].addr & ~PAGE_MASK)
682 + idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT; 682 + idev->info->mem[mi].size + PAGE_SIZE -1) >> PAGE_SHIFT;
683 if (requested_pages > actual_pages) 683 if (requested_pages > actual_pages)
diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
index d3527dd8b90c..5e0d33a7da58 100644
--- a/drivers/usb/atm/usbatm.c
+++ b/drivers/usb/atm/usbatm.c
@@ -1020,7 +1020,7 @@ static int usbatm_heavy_init(struct usbatm_data *instance)
1020{ 1020{
1021 struct task_struct *t; 1021 struct task_struct *t;
1022 1022
1023 t = kthread_create(usbatm_do_heavy_init, instance, 1023 t = kthread_create(usbatm_do_heavy_init, instance, "%s",
1024 instance->driver->driver_name); 1024 instance->driver->driver_name);
1025 if (IS_ERR(t)) { 1025 if (IS_ERR(t)) {
1026 usb_err(instance, "%s: failed to create kernel_thread (%ld)!\n", 1026 usb_err(instance, "%s: failed to create kernel_thread (%ld)!\n",
@@ -1076,7 +1076,8 @@ int usbatm_usb_probe(struct usb_interface *intf, const struct usb_device_id *id,
1076 /* public fields */ 1076 /* public fields */
1077 1077
1078 instance->driver = driver; 1078 instance->driver = driver;
1079 snprintf(instance->driver_name, sizeof(instance->driver_name), driver->driver_name); 1079 strlcpy(instance->driver_name, driver->driver_name,
1080 sizeof(instance->driver_name));
1080 1081
1081 instance->usb_dev = usb_dev; 1082 instance->usb_dev = usb_dev;
1082 instance->usb_intf = intf; 1083 instance->usb_intf = intf;
diff --git a/drivers/uwb/lc-dev.c b/drivers/uwb/lc-dev.c
index 5241f1d0ef7a..9209eafc75b1 100644
--- a/drivers/uwb/lc-dev.c
+++ b/drivers/uwb/lc-dev.c
@@ -440,7 +440,7 @@ void uwbd_dev_onair(struct uwb_rc *rc, struct uwb_beca_e *bce)
440 uwb_dev_init(uwb_dev); /* This sets refcnt to one, we own it */ 440 uwb_dev_init(uwb_dev); /* This sets refcnt to one, we own it */
441 uwb_dev->mac_addr = *bce->mac_addr; 441 uwb_dev->mac_addr = *bce->mac_addr;
442 uwb_dev->dev_addr = bce->dev_addr; 442 uwb_dev->dev_addr = bce->dev_addr;
443 dev_set_name(&uwb_dev->dev, macbuf); 443 dev_set_name(&uwb_dev->dev, "%s", macbuf);
444 result = uwb_dev_add(uwb_dev, &rc->uwb_dev.dev, rc); 444 result = uwb_dev_add(uwb_dev, &rc->uwb_dev.dev, rc);
445 if (result < 0) { 445 if (result < 0) {
446 dev_err(dev, "new device %s: cannot instantiate device\n", 446 dev_err(dev, "new device %s: cannot instantiate device\n",
diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index a60d6afca97c..0393d827dd44 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -195,7 +195,6 @@ static int __init atmel_pwm_bl_probe(struct platform_device *pdev)
195 return 0; 195 return 0;
196 196
197err_free_bl_dev: 197err_free_bl_dev:
198 platform_set_drvdata(pdev, NULL);
199 backlight_device_unregister(bldev); 198 backlight_device_unregister(bldev);
200err_free_pwm: 199err_free_pwm:
201 pwm_channel_free(&pwmbl->pwmc); 200 pwm_channel_free(&pwmbl->pwmc);
@@ -212,7 +211,6 @@ static int __exit atmel_pwm_bl_remove(struct platform_device *pdev)
212 pwm_channel_disable(&pwmbl->pwmc); 211 pwm_channel_disable(&pwmbl->pwmc);
213 pwm_channel_free(&pwmbl->pwmc); 212 pwm_channel_free(&pwmbl->pwmc);
214 backlight_device_unregister(pwmbl->bldev); 213 backlight_device_unregister(pwmbl->bldev);
215 platform_set_drvdata(pdev, NULL);
216 214
217 return 0; 215 return 0;
218} 216}
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index c74e7aa46731..3fccb6d3c8c3 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -208,7 +208,8 @@ static ssize_t backlight_show_actual_brightness(struct device *dev,
208 208
209static struct class *backlight_class; 209static struct class *backlight_class;
210 210
211static int backlight_suspend(struct device *dev, pm_message_t state) 211#ifdef CONFIG_PM_SLEEP
212static int backlight_suspend(struct device *dev)
212{ 213{
213 struct backlight_device *bd = to_backlight_device(dev); 214 struct backlight_device *bd = to_backlight_device(dev);
214 215
@@ -235,6 +236,10 @@ static int backlight_resume(struct device *dev)
235 236
236 return 0; 237 return 0;
237} 238}
239#endif
240
241static SIMPLE_DEV_PM_OPS(backlight_class_dev_pm_ops, backlight_suspend,
242 backlight_resume);
238 243
239static void bl_device_release(struct device *dev) 244static void bl_device_release(struct device *dev)
240{ 245{
@@ -304,7 +309,7 @@ struct backlight_device *backlight_device_register(const char *name,
304 new_bd->dev.class = backlight_class; 309 new_bd->dev.class = backlight_class;
305 new_bd->dev.parent = parent; 310 new_bd->dev.parent = parent;
306 new_bd->dev.release = bl_device_release; 311 new_bd->dev.release = bl_device_release;
307 dev_set_name(&new_bd->dev, name); 312 dev_set_name(&new_bd->dev, "%s", name);
308 dev_set_drvdata(&new_bd->dev, devdata); 313 dev_set_drvdata(&new_bd->dev, devdata);
309 314
310 /* Set default properties */ 315 /* Set default properties */
@@ -370,6 +375,81 @@ void backlight_device_unregister(struct backlight_device *bd)
370} 375}
371EXPORT_SYMBOL(backlight_device_unregister); 376EXPORT_SYMBOL(backlight_device_unregister);
372 377
378static void devm_backlight_device_release(struct device *dev, void *res)
379{
380 struct backlight_device *backlight = *(struct backlight_device **)res;
381
382 backlight_device_unregister(backlight);
383}
384
385static int devm_backlight_device_match(struct device *dev, void *res,
386 void *data)
387{
388 struct backlight_device **r = res;
389
390 return *r == data;
391}
392
393/**
394 * devm_backlight_device_register - resource managed backlight_device_register()
395 * @dev: the device to register
396 * @name: the name of the device
397 * @parent: a pointer to the parent device
398 * @devdata: an optional pointer to be stored for private driver use
399 * @ops: the backlight operations structure
400 * @props: the backlight properties
401 *
402 * @return a struct backlight on success, or an ERR_PTR on error
403 *
404 * Managed backlight_device_register(). The backlight_device returned
405 * from this function are automatically freed on driver detach.
406 * See backlight_device_register() for more information.
407 */
408struct backlight_device *devm_backlight_device_register(struct device *dev,
409 const char *name, struct device *parent, void *devdata,
410 const struct backlight_ops *ops,
411 const struct backlight_properties *props)
412{
413 struct backlight_device **ptr, *backlight;
414
415 ptr = devres_alloc(devm_backlight_device_release, sizeof(*ptr),
416 GFP_KERNEL);
417 if (!ptr)
418 return ERR_PTR(-ENOMEM);
419
420 backlight = backlight_device_register(name, parent, devdata, ops,
421 props);
422 if (!IS_ERR(backlight)) {
423 *ptr = backlight;
424 devres_add(dev, ptr);
425 } else {
426 devres_free(ptr);
427 }
428
429 return backlight;
430}
431EXPORT_SYMBOL(devm_backlight_device_register);
432
433/**
434 * devm_backlight_device_unregister - resource managed backlight_device_unregister()
435 * @dev: the device to unregister
436 * @bd: the backlight device to unregister
437 *
438 * Deallocated a backlight allocated with devm_backlight_device_register().
439 * Normally this function will not need to be called and the resource management
440 * code will ensure that the resource is freed.
441 */
442void devm_backlight_device_unregister(struct device *dev,
443 struct backlight_device *bd)
444{
445 int rc;
446
447 rc = devres_release(dev, devm_backlight_device_release,
448 devm_backlight_device_match, bd);
449 WARN_ON(rc);
450}
451EXPORT_SYMBOL(devm_backlight_device_unregister);
452
373#ifdef CONFIG_OF 453#ifdef CONFIG_OF
374static int of_parent_match(struct device *dev, const void *data) 454static int of_parent_match(struct device *dev, const void *data)
375{ 455{
@@ -414,8 +494,7 @@ static int __init backlight_class_init(void)
414 } 494 }
415 495
416 backlight_class->dev_attrs = bl_device_attributes; 496 backlight_class->dev_attrs = bl_device_attributes;
417 backlight_class->suspend = backlight_suspend; 497 backlight_class->pm = &backlight_class_dev_pm_ops;
418 backlight_class->resume = backlight_resume;
419 return 0; 498 return 0;
420} 499}
421 500
diff --git a/drivers/video/backlight/ep93xx_bl.c b/drivers/video/backlight/ep93xx_bl.c
index 33455821dd31..018368ba4124 100644
--- a/drivers/video/backlight/ep93xx_bl.c
+++ b/drivers/video/backlight/ep93xx_bl.c
@@ -111,7 +111,6 @@ static int ep93xxbl_remove(struct platform_device *dev)
111 struct backlight_device *bl = platform_get_drvdata(dev); 111 struct backlight_device *bl = platform_get_drvdata(dev);
112 112
113 backlight_device_unregister(bl); 113 backlight_device_unregister(bl);
114 platform_set_drvdata(dev, NULL);
115 return 0; 114 return 0;
116} 115}
117 116
diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c
index 34fb6bd798c8..41964a71a036 100644
--- a/drivers/video/backlight/lcd.c
+++ b/drivers/video/backlight/lcd.c
@@ -219,7 +219,7 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,
219 new_ld->dev.class = lcd_class; 219 new_ld->dev.class = lcd_class;
220 new_ld->dev.parent = parent; 220 new_ld->dev.parent = parent;
221 new_ld->dev.release = lcd_device_release; 221 new_ld->dev.release = lcd_device_release;
222 dev_set_name(&new_ld->dev, name); 222 dev_set_name(&new_ld->dev, "%s", name);
223 dev_set_drvdata(&new_ld->dev, devdata); 223 dev_set_drvdata(&new_ld->dev, devdata);
224 224
225 rc = device_register(&new_ld->dev); 225 rc = device_register(&new_ld->dev);
@@ -260,6 +260,76 @@ void lcd_device_unregister(struct lcd_device *ld)
260} 260}
261EXPORT_SYMBOL(lcd_device_unregister); 261EXPORT_SYMBOL(lcd_device_unregister);
262 262
263static void devm_lcd_device_release(struct device *dev, void *res)
264{
265 struct lcd_device *lcd = *(struct lcd_device **)res;
266
267 lcd_device_unregister(lcd);
268}
269
270static int devm_lcd_device_match(struct device *dev, void *res, void *data)
271{
272 struct lcd_device **r = res;
273
274 return *r == data;
275}
276
277/**
278 * devm_lcd_device_register - resource managed lcd_device_register()
279 * @dev: the device to register
280 * @name: the name of the device
281 * @parent: a pointer to the parent device
282 * @devdata: an optional pointer to be stored for private driver use
283 * @ops: the lcd operations structure
284 *
285 * @return a struct lcd on success, or an ERR_PTR on error
286 *
287 * Managed lcd_device_register(). The lcd_device returned from this function
288 * are automatically freed on driver detach. See lcd_device_register()
289 * for more information.
290 */
291struct lcd_device *devm_lcd_device_register(struct device *dev,
292 const char *name, struct device *parent,
293 void *devdata, struct lcd_ops *ops)
294{
295 struct lcd_device **ptr, *lcd;
296
297 ptr = devres_alloc(devm_lcd_device_release, sizeof(*ptr), GFP_KERNEL);
298 if (!ptr)
299 return ERR_PTR(-ENOMEM);
300
301 lcd = lcd_device_register(name, parent, devdata, ops);
302 if (!IS_ERR(lcd)) {
303 *ptr = lcd;
304 devres_add(dev, ptr);
305 } else {
306 devres_free(ptr);
307 }
308
309 return lcd;
310}
311EXPORT_SYMBOL(devm_lcd_device_register);
312
313/**
314 * devm_lcd_device_unregister - resource managed lcd_device_unregister()
315 * @dev: the device to unregister
316 * @ld: the lcd device to unregister
317 *
318 * Deallocated a lcd allocated with devm_lcd_device_register(). Normally
319 * this function will not need to be called and the resource management
320 * code will ensure that the resource is freed.
321 */
322void devm_lcd_device_unregister(struct device *dev, struct lcd_device *ld)
323{
324 int rc;
325
326 rc = devres_release(dev, devm_lcd_device_release,
327 devm_lcd_device_match, ld);
328 WARN_ON(rc);
329}
330EXPORT_SYMBOL(devm_lcd_device_unregister);
331
332
263static void __exit lcd_class_exit(void) 333static void __exit lcd_class_exit(void)
264{ 334{
265 class_destroy(lcd_class); 335 class_destroy(lcd_class);
diff --git a/drivers/video/backlight/lp8788_bl.c b/drivers/video/backlight/lp8788_bl.c
index 4bb8b4f140cf..980855ec9bb1 100644
--- a/drivers/video/backlight/lp8788_bl.c
+++ b/drivers/video/backlight/lp8788_bl.c
@@ -312,7 +312,6 @@ static int lp8788_backlight_remove(struct platform_device *pdev)
312 backlight_update_status(bl_dev); 312 backlight_update_status(bl_dev);
313 sysfs_remove_group(&pdev->dev.kobj, &lp8788_attr_group); 313 sysfs_remove_group(&pdev->dev.kobj, &lp8788_attr_group);
314 lp8788_backlight_unregister(bl); 314 lp8788_backlight_unregister(bl);
315 platform_set_drvdata(pdev, NULL);
316 315
317 return 0; 316 return 0;
318} 317}
diff --git a/drivers/video/backlight/pcf50633-backlight.c b/drivers/video/backlight/pcf50633-backlight.c
index e87c7a3394f3..6ed76be18f19 100644
--- a/drivers/video/backlight/pcf50633-backlight.c
+++ b/drivers/video/backlight/pcf50633-backlight.c
@@ -153,8 +153,6 @@ static int pcf50633_bl_remove(struct platform_device *pdev)
153 153
154 backlight_device_unregister(pcf_bl->bl); 154 backlight_device_unregister(pcf_bl->bl);
155 155
156 platform_set_drvdata(pdev, NULL);
157
158 return 0; 156 return 0;
159} 157}
160 158
diff --git a/drivers/video/output.c b/drivers/video/output.c
index 0d6f2cda9369..6285b9718451 100644
--- a/drivers/video/output.c
+++ b/drivers/video/output.c
@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
97 new_dev->props = op; 97 new_dev->props = op;
98 new_dev->dev.class = &video_output_class; 98 new_dev->dev.class = &video_output_class;
99 new_dev->dev.parent = dev; 99 new_dev->dev.parent = dev;
100 dev_set_name(&new_dev->dev, name); 100 dev_set_name(&new_dev->dev, "%s", name);
101 dev_set_drvdata(&new_dev->dev, devdata); 101 dev_set_drvdata(&new_dev->dev, devdata);
102 ret_code = device_register(&new_dev->dev); 102 ret_code = device_register(&new_dev->dev);
103 if (ret_code) { 103 if (ret_code) {
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
index bd3ae324a1a2..0098810df69d 100644
--- a/drivers/virtio/virtio_balloon.c
+++ b/drivers/virtio/virtio_balloon.c
@@ -148,7 +148,7 @@ static void fill_balloon(struct virtio_balloon *vb, size_t num)
148 } 148 }
149 set_page_pfns(vb->pfns + vb->num_pfns, page); 149 set_page_pfns(vb->pfns + vb->num_pfns, page);
150 vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE; 150 vb->num_pages += VIRTIO_BALLOON_PAGES_PER_PAGE;
151 totalram_pages--; 151 adjust_managed_page_count(page, -1);
152 } 152 }
153 153
154 /* Did we get any? */ 154 /* Did we get any? */
@@ -163,8 +163,9 @@ static void release_pages_by_pfn(const u32 pfns[], unsigned int num)
163 163
164 /* Find pfns pointing at start of each page, get pages and free them. */ 164 /* Find pfns pointing at start of each page, get pages and free them. */
165 for (i = 0; i < num; i += VIRTIO_BALLOON_PAGES_PER_PAGE) { 165 for (i = 0; i < num; i += VIRTIO_BALLOON_PAGES_PER_PAGE) {
166 balloon_page_free(balloon_pfn_to_page(pfns[i])); 166 struct page *page = balloon_pfn_to_page(pfns[i]);
167 totalram_pages++; 167 balloon_page_free(page);
168 adjust_managed_page_count(page, 1);
168 } 169 }
169} 170}
170 171
diff --git a/drivers/w1/slaves/w1_ds2408.c b/drivers/w1/slaves/w1_ds2408.c
index 91cc2cdf02c0..cb8a8e5d9573 100644
--- a/drivers/w1/slaves/w1_ds2408.c
+++ b/drivers/w1/slaves/w1_ds2408.c
@@ -302,7 +302,33 @@ error:
302 return -EIO; 302 return -EIO;
303} 303}
304 304
305/*
306 * This is a special sequence we must do to ensure the P0 output is not stuck
307 * in test mode. This is described in rev 2 of the ds2408's datasheet
308 * (http://datasheets.maximintegrated.com/en/ds/DS2408.pdf) under
309 * "APPLICATION INFORMATION/Power-up timing".
310 */
311static int w1_f29_disable_test_mode(struct w1_slave *sl)
312{
313 int res;
314 u8 magic[10] = {0x96, };
315 u64 rn = le64_to_cpu(*((u64*)&sl->reg_num));
316
317 memcpy(&magic[1], &rn, 8);
318 magic[9] = 0x3C;
319
320 mutex_lock(&sl->master->bus_mutex);
305 321
322 res = w1_reset_bus(sl->master);
323 if (res)
324 goto out;
325 w1_write_block(sl->master, magic, ARRAY_SIZE(magic));
326
327 res = w1_reset_bus(sl->master);
328out:
329 mutex_unlock(&sl->master->bus_mutex);
330 return res;
331}
306 332
307static struct bin_attribute w1_f29_sysfs_bin_files[] = { 333static struct bin_attribute w1_f29_sysfs_bin_files[] = {
308 { 334 {
@@ -363,6 +389,10 @@ static int w1_f29_add_slave(struct w1_slave *sl)
363 int err = 0; 389 int err = 0;
364 int i; 390 int i;
365 391
392 err = w1_f29_disable_test_mode(sl);
393 if (err)
394 return err;
395
366 for (i = 0; i < ARRAY_SIZE(w1_f29_sysfs_bin_files) && !err; ++i) 396 for (i = 0; i < ARRAY_SIZE(w1_f29_sysfs_bin_files) && !err; ++i)
367 err = sysfs_create_bin_file( 397 err = sysfs_create_bin_file(
368 &sl->dev.kobj, 398 &sl->dev.kobj,
diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
index e33615335aa0..2a2ef97697b2 100644
--- a/drivers/xen/balloon.c
+++ b/drivers/xen/balloon.c
@@ -91,14 +91,6 @@ EXPORT_SYMBOL_GPL(balloon_stats);
91/* We increase/decrease in batches which fit in a page */ 91/* We increase/decrease in batches which fit in a page */
92static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)]; 92static xen_pfn_t frame_list[PAGE_SIZE / sizeof(unsigned long)];
93 93
94#ifdef CONFIG_HIGHMEM
95#define inc_totalhigh_pages() (totalhigh_pages++)
96#define dec_totalhigh_pages() (totalhigh_pages--)
97#else
98#define inc_totalhigh_pages() do {} while (0)
99#define dec_totalhigh_pages() do {} while (0)
100#endif
101
102/* List of ballooned pages, threaded through the mem_map array. */ 94/* List of ballooned pages, threaded through the mem_map array. */
103static LIST_HEAD(ballooned_pages); 95static LIST_HEAD(ballooned_pages);
104 96
@@ -134,9 +126,7 @@ static void __balloon_append(struct page *page)
134static void balloon_append(struct page *page) 126static void balloon_append(struct page *page)
135{ 127{
136 __balloon_append(page); 128 __balloon_append(page);
137 if (PageHighMem(page)) 129 adjust_managed_page_count(page, -1);
138 dec_totalhigh_pages();
139 totalram_pages--;
140} 130}
141 131
142/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */ 132/* balloon_retrieve: rescue a page from the balloon, if it is not empty. */
@@ -153,13 +143,12 @@ static struct page *balloon_retrieve(bool prefer_highmem)
153 page = list_entry(ballooned_pages.next, struct page, lru); 143 page = list_entry(ballooned_pages.next, struct page, lru);
154 list_del(&page->lru); 144 list_del(&page->lru);
155 145
156 if (PageHighMem(page)) { 146 if (PageHighMem(page))
157 balloon_stats.balloon_high--; 147 balloon_stats.balloon_high--;
158 inc_totalhigh_pages(); 148 else
159 } else
160 balloon_stats.balloon_low--; 149 balloon_stats.balloon_low--;
161 150
162 totalram_pages++; 151 adjust_managed_page_count(page, 1);
163 152
164 return page; 153 return page;
165} 154}
@@ -374,9 +363,7 @@ static enum bp_state increase_reservation(unsigned long nr_pages)
374#endif 363#endif
375 364
376 /* Relinquish the page back to the allocator. */ 365 /* Relinquish the page back to the allocator. */
377 ClearPageReserved(page); 366 __free_reserved_page(page);
378 init_page_count(page);
379 __free_page(page);
380 } 367 }
381 368
382 balloon_stats.current_pages += rc; 369 balloon_stats.current_pages += rc;
diff --git a/drivers/xen/xenbus/xenbus_probe.c b/drivers/xen/xenbus/xenbus_probe.c
index cb1afc00c96d..38e92b770e91 100644
--- a/drivers/xen/xenbus/xenbus_probe.c
+++ b/drivers/xen/xenbus/xenbus_probe.c
@@ -449,7 +449,7 @@ int xenbus_probe_node(struct xen_bus_type *bus,
449 if (err) 449 if (err)
450 goto fail; 450 goto fail;
451 451
452 dev_set_name(&xendev->dev, devname); 452 dev_set_name(&xendev->dev, "%s", devname);
453 453
454 /* Register with generic device framework. */ 454 /* Register with generic device framework. */
455 err = device_register(&xendev->dev); 455 err = device_register(&xendev->dev);