aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 22:47:50 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 22:47:50 -0400
commit56847d857cb0c3ee78c22ce776a26f88d9ffd4d4 (patch)
treea85bcf204a53e45d26f6a3984f16ddd525eef3e7 /drivers
parent191a712090bb8a10e6f129360eeed2d68f3d4c9a (diff)
parent8d564368a9a3197f43e56dadf4a18c5738849f94 (diff)
Merge branch 'akpm' (incoming from Andrew)
Merge second batch of fixes from Andrew Morton: - various misc bits - some printk updates - a new "SRAM" driver. - MAINTAINERS updates - the backlight driver queue - checkpatch updates - a few init/ changes - a huge number of drivers/rtc changes - fatfs updates - some lib/idr.c work - some renaming of the random driver interfaces * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (285 commits) net: rename random32 to prandom net/core: remove duplicate statements by do-while loop net/core: rename random32() to prandom_u32() net/netfilter: rename random32() to prandom_u32() net/sched: rename random32() to prandom_u32() net/sunrpc: rename random32() to prandom_u32() scsi: rename random32() to prandom_u32() lguest: rename random32() to prandom_u32() uwb: rename random32() to prandom_u32() video/uvesafb: rename random32() to prandom_u32() mmc: rename random32() to prandom_u32() drbd: rename random32() to prandom_u32() kernel/: rename random32() to prandom_u32() mm/: rename random32() to prandom_u32() lib/: rename random32() to prandom_u32() x86: rename random32() to prandom_u32() x86: pageattr-test: remove srandom32 call uuid: use prandom_bytes() raid6test: use prandom_bytes() sctp: convert sctp_assoc_set_id() to use idr_alloc_cyclic() ...
Diffstat (limited to 'drivers')
-rw-r--r--drivers/block/drbd/drbd_receiver.c5
-rw-r--r--drivers/infiniband/hw/amso1100/c2.h1
-rw-r--r--drivers/infiniband/hw/amso1100/c2_qp.c3
-rw-r--r--drivers/infiniband/hw/mlx4/cm.c4
-rw-r--r--drivers/lguest/page_tables.c2
-rw-r--r--drivers/media/platform/Kconfig1
-rw-r--r--drivers/media/platform/coda.c45
-rw-r--r--drivers/misc/Kconfig9
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/sram.c121
-rw-r--r--drivers/mmc/core/core.c4
-rw-r--r--drivers/rpmsg/virtio_rpmsg_bus.c4
-rw-r--r--drivers/rtc/class.c70
-rw-r--r--drivers/rtc/rtc-88pm80x.c5
-rw-r--r--drivers/rtc/rtc-88pm860x.c29
-rw-r--r--drivers/rtc/rtc-ab3100.c21
-rw-r--r--drivers/rtc/rtc-ab8500.c18
-rw-r--r--drivers/rtc/rtc-at32ap700x.c39
-rw-r--r--drivers/rtc/rtc-at91rm9200.c50
-rw-r--r--drivers/rtc/rtc-at91sam9.c57
-rw-r--r--drivers/rtc/rtc-au1xxx.c18
-rw-r--r--drivers/rtc/rtc-bfin.c34
-rw-r--r--drivers/rtc/rtc-bq32k.c5
-rw-r--r--drivers/rtc/rtc-bq4802.c29
-rw-r--r--drivers/rtc/rtc-cmos.c4
-rw-r--r--drivers/rtc/rtc-coh901331.c42
-rw-r--r--drivers/rtc/rtc-da9052.c5
-rw-r--r--drivers/rtc/rtc-da9055.c5
-rw-r--r--drivers/rtc/rtc-davinci.c24
-rw-r--r--drivers/rtc/rtc-dm355evm.c7
-rw-r--r--drivers/rtc/rtc-ds1216.c44
-rw-r--r--drivers/rtc/rtc-ds1286.c49
-rw-r--r--drivers/rtc/rtc-ds1302.c22
-rw-r--r--drivers/rtc/rtc-ds1305.c35
-rw-r--r--drivers/rtc/rtc-ds1307.c74
-rw-r--r--drivers/rtc/rtc-ds1374.c35
-rw-r--r--drivers/rtc/rtc-ds1390.c15
-rw-r--r--drivers/rtc/rtc-ds1511.c8
-rw-r--r--drivers/rtc/rtc-ds1553.c6
-rw-r--r--drivers/rtc/rtc-ds1672.c8
-rw-r--r--drivers/rtc/rtc-ds1742.c8
-rw-r--r--drivers/rtc/rtc-ds2404.c12
-rw-r--r--drivers/rtc/rtc-ds3232.c25
-rw-r--r--drivers/rtc/rtc-ds3234.c9
-rw-r--r--drivers/rtc/rtc-efi.c19
-rw-r--r--drivers/rtc/rtc-em3027.c7
-rw-r--r--drivers/rtc/rtc-ep93xx.c11
-rw-r--r--drivers/rtc/rtc-fm3130.c11
-rw-r--r--drivers/rtc/rtc-generic.c21
-rw-r--r--drivers/rtc/rtc-hid-sensor-time.c7
-rw-r--r--drivers/rtc/rtc-imxdi.c23
-rw-r--r--drivers/rtc/rtc-isl12022.c30
-rw-r--r--drivers/rtc/rtc-lp8788.c5
-rw-r--r--drivers/rtc/rtc-lpc32xx.c5
-rw-r--r--drivers/rtc/rtc-ls1x.c5
-rw-r--r--drivers/rtc/rtc-m41t80.c16
-rw-r--r--drivers/rtc/rtc-m41t93.c11
-rw-r--r--drivers/rtc/rtc-m41t94.c11
-rw-r--r--drivers/rtc/rtc-m48t35.c42
-rw-r--r--drivers/rtc/rtc-m48t86.c11
-rw-r--r--drivers/rtc/rtc-max6900.c9
-rw-r--r--drivers/rtc/rtc-max6902.c29
-rw-r--r--drivers/rtc/rtc-max77686.c73
-rw-r--r--drivers/rtc/rtc-max8907.c20
-rw-r--r--drivers/rtc/rtc-max8925.c26
-rw-r--r--drivers/rtc/rtc-max8997.c17
-rw-r--r--drivers/rtc/rtc-max8998.c18
-rw-r--r--drivers/rtc/rtc-mc13xxx.c23
-rw-r--r--drivers/rtc/rtc-msm6242.c45
-rw-r--r--drivers/rtc/rtc-mv.c23
-rw-r--r--drivers/rtc/rtc-mxc.c15
-rw-r--r--drivers/rtc/rtc-nuc900.c72
-rw-r--r--drivers/rtc/rtc-omap.c81
-rw-r--r--drivers/rtc/rtc-palmas.c19
-rw-r--r--drivers/rtc/rtc-pcap.c53
-rw-r--r--drivers/rtc/rtc-pcf2123.c12
-rw-r--r--drivers/rtc/rtc-pcf50633.c15
-rw-r--r--drivers/rtc/rtc-pcf8523.c6
-rw-r--r--drivers/rtc/rtc-pcf8563.c28
-rw-r--r--drivers/rtc/rtc-pcf8583.c24
-rw-r--r--drivers/rtc/rtc-ps3.c16
-rw-r--r--drivers/rtc/rtc-puv3.c27
-rw-r--r--drivers/rtc/rtc-pxa.c24
-rw-r--r--drivers/rtc/rtc-r9701.c9
-rw-r--r--drivers/rtc/rtc-rc5t583.c19
-rw-r--r--drivers/rtc/rtc-rp5c01.c39
-rw-r--r--drivers/rtc/rtc-rs5c313.c6
-rw-r--r--drivers/rtc/rtc-rs5c348.c12
-rw-r--r--drivers/rtc/rtc-rs5c372.c30
-rw-r--r--drivers/rtc/rtc-rv3029c2.c16
-rw-r--r--drivers/rtc/rtc-rx4581.c9
-rw-r--r--drivers/rtc/rtc-rx8581.c8
-rw-r--r--drivers/rtc/rtc-s35390a.c14
-rw-r--r--drivers/rtc/rtc-s3c.c37
-rw-r--r--drivers/rtc/rtc-sa1100.c29
-rw-r--r--drivers/rtc/rtc-sh.c22
-rw-r--r--drivers/rtc/rtc-snvs.c6
-rw-r--r--drivers/rtc/rtc-spear.c23
-rw-r--r--drivers/rtc/rtc-starfire.c23
-rw-r--r--drivers/rtc/rtc-stk17ta8.c6
-rw-r--r--drivers/rtc/rtc-stmp3xxx.c51
-rw-r--r--drivers/rtc/rtc-sun4v.c22
-rw-r--r--drivers/rtc/rtc-tegra.c64
-rw-r--r--drivers/rtc/rtc-test.c10
-rw-r--r--drivers/rtc/rtc-tile.c9
-rw-r--r--drivers/rtc/rtc-tps6586x.c14
-rw-r--r--drivers/rtc/rtc-tps65910.c13
-rw-r--r--drivers/rtc/rtc-tps80031.c11
-rw-r--r--drivers/rtc/rtc-twl.c16
-rw-r--r--drivers/rtc/rtc-tx4939.c19
-rw-r--r--drivers/rtc/rtc-v3020.c13
-rw-r--r--drivers/rtc/rtc-vt8500.c8
-rw-r--r--drivers/rtc/rtc-wm831x.c6
-rw-r--r--drivers/rtc/rtc-wm8350.c19
-rw-r--r--drivers/rtc/rtc-x1205.c14
-rw-r--r--drivers/scsi/fcoe/fcoe_ctlr.c4
-rw-r--r--drivers/scsi/lpfc/lpfc_hbadisc.c6
-rw-r--r--drivers/uwb/rsv.c4
-rw-r--r--drivers/video/backlight/Kconfig9
-rw-r--r--drivers/video/backlight/Makefile1
-rw-r--r--drivers/video/backlight/adp5520_bl.c28
-rw-r--r--drivers/video/backlight/adp8860_bl.c23
-rw-r--r--drivers/video/backlight/adp8870_bl.c33
-rw-r--r--drivers/video/backlight/ams369fg06.c21
-rw-r--r--drivers/video/backlight/as3711_bl.c118
-rw-r--r--drivers/video/backlight/atmel-pwm-bl.c14
-rw-r--r--drivers/video/backlight/corgi_lcd.c18
-rw-r--r--drivers/video/backlight/da903x_bl.c30
-rw-r--r--drivers/video/backlight/ep93xx_bl.c20
-rw-r--r--drivers/video/backlight/generic_bl.c6
-rw-r--r--drivers/video/backlight/hp680_bl.c18
-rw-r--r--drivers/video/backlight/ili922x.c555
-rw-r--r--drivers/video/backlight/ili9320.c26
-rw-r--r--drivers/video/backlight/ili9320.h2
-rw-r--r--drivers/video/backlight/jornada720_bl.c18
-rw-r--r--drivers/video/backlight/jornada720_lcd.c21
-rw-r--r--drivers/video/backlight/kb3886_bl.c18
-rw-r--r--drivers/video/backlight/l4f00242t03.c27
-rw-r--r--drivers/video/backlight/ld9040.c20
-rw-r--r--drivers/video/backlight/lm3533_bl.c22
-rw-r--r--drivers/video/backlight/lms501kf03.c22
-rw-r--r--drivers/video/backlight/locomolcd.c16
-rw-r--r--drivers/video/backlight/lp855x_bl.c105
-rw-r--r--drivers/video/backlight/ltv350qv.c18
-rw-r--r--drivers/video/backlight/omap1_bl.c26
-rw-r--r--drivers/video/backlight/platform_lcd.c12
-rw-r--r--drivers/video/backlight/s6e63m0.c20
-rw-r--r--drivers/video/backlight/tdo24m.c18
-rw-r--r--drivers/video/backlight/tosa_bl.c18
-rw-r--r--drivers/video/backlight/tosa_lcd.c18
-rw-r--r--drivers/video/backlight/tps65217_bl.c15
-rw-r--r--drivers/video/backlight/vgg2432a4.c18
-rw-r--r--drivers/video/uvesafb.c2
153 files changed, 1977 insertions, 1912 deletions
diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
index a9eccfc6079b..83c5ae0ed56b 100644
--- a/drivers/block/drbd/drbd_receiver.c
+++ b/drivers/block/drbd/drbd_receiver.c
@@ -757,7 +757,8 @@ static struct socket *drbd_wait_for_connect(struct drbd_tconn *tconn, struct acc
757 rcu_read_unlock(); 757 rcu_read_unlock();
758 758
759 timeo = connect_int * HZ; 759 timeo = connect_int * HZ;
760 timeo += (random32() & 1) ? timeo / 7 : -timeo / 7; /* 28.5% random jitter */ 760 /* 28.5% random jitter */
761 timeo += (prandom_u32() & 1) ? timeo / 7 : -timeo / 7;
761 762
762 err = wait_for_completion_interruptible_timeout(&ad->door_bell, timeo); 763 err = wait_for_completion_interruptible_timeout(&ad->door_bell, timeo);
763 if (err <= 0) 764 if (err <= 0)
@@ -953,7 +954,7 @@ retry:
953 conn_warn(tconn, "Error receiving initial packet\n"); 954 conn_warn(tconn, "Error receiving initial packet\n");
954 sock_release(s); 955 sock_release(s);
955randomize: 956randomize:
956 if (random32() & 1) 957 if (prandom_u32() & 1)
957 goto retry; 958 goto retry;
958 } 959 }
959 } 960 }
diff --git a/drivers/infiniband/hw/amso1100/c2.h b/drivers/infiniband/hw/amso1100/c2.h
index ba7a1208ff9e..d619d735838b 100644
--- a/drivers/infiniband/hw/amso1100/c2.h
+++ b/drivers/infiniband/hw/amso1100/c2.h
@@ -265,7 +265,6 @@ struct c2_pd_table {
265struct c2_qp_table { 265struct c2_qp_table {
266 struct idr idr; 266 struct idr idr;
267 spinlock_t lock; 267 spinlock_t lock;
268 int last;
269}; 268};
270 269
271struct c2_element { 270struct c2_element {
diff --git a/drivers/infiniband/hw/amso1100/c2_qp.c b/drivers/infiniband/hw/amso1100/c2_qp.c
index 0ab826b280b2..86708dee58b1 100644
--- a/drivers/infiniband/hw/amso1100/c2_qp.c
+++ b/drivers/infiniband/hw/amso1100/c2_qp.c
@@ -385,8 +385,7 @@ static int c2_alloc_qpn(struct c2_dev *c2dev, struct c2_qp *qp)
385 idr_preload(GFP_KERNEL); 385 idr_preload(GFP_KERNEL);
386 spin_lock_irq(&c2dev->qp_table.lock); 386 spin_lock_irq(&c2dev->qp_table.lock);
387 387
388 ret = idr_alloc(&c2dev->qp_table.idr, qp, c2dev->qp_table.last++, 0, 388 ret = idr_alloc_cyclic(&c2dev->qp_table.idr, qp, 0, 0, GFP_NOWAIT);
389 GFP_NOWAIT);
390 if (ret >= 0) 389 if (ret >= 0)
391 qp->qpn = ret; 390 qp->qpn = ret;
392 391
diff --git a/drivers/infiniband/hw/mlx4/cm.c b/drivers/infiniband/hw/mlx4/cm.c
index add98d01476c..d1f5f1dd77b0 100644
--- a/drivers/infiniband/hw/mlx4/cm.c
+++ b/drivers/infiniband/hw/mlx4/cm.c
@@ -204,7 +204,6 @@ static struct id_map_entry *
204id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id) 204id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id)
205{ 205{
206 int ret; 206 int ret;
207 static int next_id;
208 struct id_map_entry *ent; 207 struct id_map_entry *ent;
209 struct mlx4_ib_sriov *sriov = &to_mdev(ibdev)->sriov; 208 struct mlx4_ib_sriov *sriov = &to_mdev(ibdev)->sriov;
210 209
@@ -223,9 +222,8 @@ id_map_alloc(struct ib_device *ibdev, int slave_id, u32 sl_cm_id)
223 idr_preload(GFP_KERNEL); 222 idr_preload(GFP_KERNEL);
224 spin_lock(&to_mdev(ibdev)->sriov.id_map_lock); 223 spin_lock(&to_mdev(ibdev)->sriov.id_map_lock);
225 224
226 ret = idr_alloc(&sriov->pv_id_table, ent, next_id, 0, GFP_NOWAIT); 225 ret = idr_alloc_cyclic(&sriov->pv_id_table, ent, 0, 0, GFP_NOWAIT);
227 if (ret >= 0) { 226 if (ret >= 0) {
228 next_id = max(ret + 1, 0);
229 ent->pv_cm_id = (u32)ret; 227 ent->pv_cm_id = (u32)ret;
230 sl_id_map_add(ibdev, ent); 228 sl_id_map_add(ibdev, ent);
231 list_add_tail(&ent->list, &sriov->cm_list); 229 list_add_tail(&ent->list, &sriov->cm_list);
diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
index 3b62be160a6e..864baabaee25 100644
--- a/drivers/lguest/page_tables.c
+++ b/drivers/lguest/page_tables.c
@@ -686,7 +686,7 @@ static unsigned int new_pgdir(struct lg_cpu *cpu,
686 * We pick one entry at random to throw out. Choosing the Least 686 * We pick one entry at random to throw out. Choosing the Least
687 * Recently Used might be better, but this is easy. 687 * Recently Used might be better, but this is easy.
688 */ 688 */
689 next = random32() % ARRAY_SIZE(cpu->lg->pgdirs); 689 next = prandom_u32() % ARRAY_SIZE(cpu->lg->pgdirs);
690 /* If it's never been allocated at all before, try now. */ 690 /* If it's never been allocated at all before, try now. */
691 if (!cpu->lg->pgdirs[next].pgdir) { 691 if (!cpu->lg->pgdirs[next].pgdir) {
692 cpu->lg->pgdirs[next].pgdir = 692 cpu->lg->pgdirs[next].pgdir =
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index a0639e779973..26500094de7c 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -145,7 +145,6 @@ config VIDEO_CODA
145 depends on VIDEO_DEV && VIDEO_V4L2 && ARCH_MXC 145 depends on VIDEO_DEV && VIDEO_V4L2 && ARCH_MXC
146 select VIDEOBUF2_DMA_CONTIG 146 select VIDEOBUF2_DMA_CONTIG
147 select V4L2_MEM2MEM_DEV 147 select V4L2_MEM2MEM_DEV
148 select IRAM_ALLOC if SOC_IMX53
149 ---help--- 148 ---help---
150 Coda is a range of video codec IPs that supports 149 Coda is a range of video codec IPs that supports
151 H.264, MPEG-4, and other video formats. 150 H.264, MPEG-4, and other video formats.
diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index 20827ba168fc..b931c2a5c7fc 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -14,6 +14,7 @@
14#include <linux/clk.h> 14#include <linux/clk.h>
15#include <linux/delay.h> 15#include <linux/delay.h>
16#include <linux/firmware.h> 16#include <linux/firmware.h>
17#include <linux/genalloc.h>
17#include <linux/interrupt.h> 18#include <linux/interrupt.h>
18#include <linux/io.h> 19#include <linux/io.h>
19#include <linux/irq.h> 20#include <linux/irq.h>
@@ -23,7 +24,7 @@
23#include <linux/slab.h> 24#include <linux/slab.h>
24#include <linux/videodev2.h> 25#include <linux/videodev2.h>
25#include <linux/of.h> 26#include <linux/of.h>
26#include <linux/platform_data/imx-iram.h> 27#include <linux/platform_data/coda.h>
27 28
28#include <media/v4l2-ctrls.h> 29#include <media/v4l2-ctrls.h>
29#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
@@ -43,6 +44,7 @@
43#define CODA7_WORK_BUF_SIZE (512 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024) 44#define CODA7_WORK_BUF_SIZE (512 * 1024 + CODA_FMO_BUF_SIZE * 8 * 1024)
44#define CODA_PARA_BUF_SIZE (10 * 1024) 45#define CODA_PARA_BUF_SIZE (10 * 1024)
45#define CODA_ISRAM_SIZE (2048 * 2) 46#define CODA_ISRAM_SIZE (2048 * 2)
47#define CODADX6_IRAM_SIZE 0xb000
46#define CODA7_IRAM_SIZE 0x14000 /* 81920 bytes */ 48#define CODA7_IRAM_SIZE 0x14000 /* 81920 bytes */
47 49
48#define CODA_MAX_FRAMEBUFFERS 2 50#define CODA_MAX_FRAMEBUFFERS 2
@@ -128,7 +130,10 @@ struct coda_dev {
128 130
129 struct coda_aux_buf codebuf; 131 struct coda_aux_buf codebuf;
130 struct coda_aux_buf workbuf; 132 struct coda_aux_buf workbuf;
133 struct gen_pool *iram_pool;
134 long unsigned int iram_vaddr;
131 long unsigned int iram_paddr; 135 long unsigned int iram_paddr;
136 unsigned long iram_size;
132 137
133 spinlock_t irqlock; 138 spinlock_t irqlock;
134 struct mutex dev_mutex; 139 struct mutex dev_mutex;
@@ -1926,6 +1931,9 @@ static int coda_probe(struct platform_device *pdev)
1926 const struct of_device_id *of_id = 1931 const struct of_device_id *of_id =
1927 of_match_device(of_match_ptr(coda_dt_ids), &pdev->dev); 1932 of_match_device(of_match_ptr(coda_dt_ids), &pdev->dev);
1928 const struct platform_device_id *pdev_id; 1933 const struct platform_device_id *pdev_id;
1934 struct coda_platform_data *pdata = pdev->dev.platform_data;
1935 struct device_node *np = pdev->dev.of_node;
1936 struct gen_pool *pool;
1929 struct coda_dev *dev; 1937 struct coda_dev *dev;
1930 struct resource *res; 1938 struct resource *res;
1931 int ret, irq; 1939 int ret, irq;
@@ -1988,6 +1996,16 @@ static int coda_probe(struct platform_device *pdev)
1988 return -ENOENT; 1996 return -ENOENT;
1989 } 1997 }
1990 1998
1999 /* Get IRAM pool from device tree or platform data */
2000 pool = of_get_named_gen_pool(np, "iram", 0);
2001 if (!pool && pdata)
2002 pool = dev_get_gen_pool(pdata->iram_dev);
2003 if (!pool) {
2004 dev_err(&pdev->dev, "iram pool not available\n");
2005 return -ENOMEM;
2006 }
2007 dev->iram_pool = pool;
2008
1991 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev); 2009 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
1992 if (ret) 2010 if (ret)
1993 return ret; 2011 return ret;
@@ -2022,18 +2040,17 @@ static int coda_probe(struct platform_device *pdev)
2022 return -ENOMEM; 2040 return -ENOMEM;
2023 } 2041 }
2024 2042
2025 if (dev->devtype->product == CODA_DX6) { 2043 if (dev->devtype->product == CODA_DX6)
2026 dev->iram_paddr = 0xffff4c00; 2044 dev->iram_size = CODADX6_IRAM_SIZE;
2027 } else { 2045 else
2028 void __iomem *iram_vaddr; 2046 dev->iram_size = CODA7_IRAM_SIZE;
2029 2047 dev->iram_vaddr = gen_pool_alloc(dev->iram_pool, dev->iram_size);
2030 iram_vaddr = iram_alloc(CODA7_IRAM_SIZE, 2048 if (!dev->iram_vaddr) {
2031 &dev->iram_paddr); 2049 dev_err(&pdev->dev, "unable to alloc iram\n");
2032 if (!iram_vaddr) { 2050 return -ENOMEM;
2033 dev_err(&pdev->dev, "unable to alloc iram\n");
2034 return -ENOMEM;
2035 }
2036 } 2051 }
2052 dev->iram_paddr = gen_pool_virt_to_phys(dev->iram_pool,
2053 dev->iram_vaddr);
2037 2054
2038 platform_set_drvdata(pdev, dev); 2055 platform_set_drvdata(pdev, dev);
2039 2056
@@ -2050,8 +2067,8 @@ static int coda_remove(struct platform_device *pdev)
2050 if (dev->alloc_ctx) 2067 if (dev->alloc_ctx)
2051 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx); 2068 vb2_dma_contig_cleanup_ctx(dev->alloc_ctx);
2052 v4l2_device_unregister(&dev->v4l2_dev); 2069 v4l2_device_unregister(&dev->v4l2_dev);
2053 if (dev->iram_paddr) 2070 if (dev->iram_vaddr)
2054 iram_free(dev->iram_paddr, CODA7_IRAM_SIZE); 2071 gen_pool_free(dev->iram_pool, dev->iram_vaddr, dev->iram_size);
2055 if (dev->codebuf.vaddr) 2072 if (dev->codebuf.vaddr)
2056 dma_free_coherent(&pdev->dev, dev->codebuf.size, 2073 dma_free_coherent(&pdev->dev, dev->codebuf.size,
2057 &dev->codebuf.vaddr, dev->codebuf.paddr); 2074 &dev->codebuf.vaddr, dev->codebuf.paddr);
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index e29e7980a359..3659d00efdc5 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -518,6 +518,15 @@ config LATTICE_ECP3_CONFIG
518 518
519 If unsure, say N. 519 If unsure, say N.
520 520
521config SRAM
522 bool "Generic on-chip SRAM driver"
523 depends on HAS_IOMEM
524 select GENERIC_ALLOCATOR
525 help
526 This driver allows you to declare a memory region to be managed by
527 the genalloc API. It is supposed to be used for small on-chip SRAM
528 areas found on many SoCs.
529
521source "drivers/misc/c2port/Kconfig" 530source "drivers/misc/c2port/Kconfig"
522source "drivers/misc/eeprom/Kconfig" 531source "drivers/misc/eeprom/Kconfig"
523source "drivers/misc/cb710/Kconfig" 532source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index 865cbc6a7ae1..c235d5b68311 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -52,3 +52,4 @@ obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
52obj-$(CONFIG_INTEL_MEI) += mei/ 52obj-$(CONFIG_INTEL_MEI) += mei/
53obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/ 53obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
54obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o 54obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
55obj-$(CONFIG_SRAM) += sram.o
diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c
new file mode 100644
index 000000000000..437192e43006
--- /dev/null
+++ b/drivers/misc/sram.c
@@ -0,0 +1,121 @@
1/*
2 * Generic on-chip SRAM allocation driver
3 *
4 * Copyright (C) 2012 Philipp Zabel, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
19 */
20
21#include <linux/kernel.h>
22#include <linux/init.h>
23#include <linux/clk.h>
24#include <linux/err.h>
25#include <linux/io.h>
26#include <linux/of.h>
27#include <linux/platform_device.h>
28#include <linux/slab.h>
29#include <linux/spinlock.h>
30#include <linux/genalloc.h>
31
32#define SRAM_GRANULARITY 32
33
34struct sram_dev {
35 struct gen_pool *pool;
36 struct clk *clk;
37};
38
39static int sram_probe(struct platform_device *pdev)
40{
41 void __iomem *virt_base;
42 struct sram_dev *sram;
43 struct resource *res;
44 unsigned long size;
45 int ret;
46
47 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
48 if (!res)
49 return -EINVAL;
50
51 size = resource_size(res);
52
53 virt_base = devm_request_and_ioremap(&pdev->dev, res);
54 if (!virt_base)
55 return -EADDRNOTAVAIL;
56
57 sram = devm_kzalloc(&pdev->dev, sizeof(*sram), GFP_KERNEL);
58 if (!sram)
59 return -ENOMEM;
60
61 sram->clk = devm_clk_get(&pdev->dev, NULL);
62 if (IS_ERR(sram->clk))
63 sram->clk = NULL;
64 else
65 clk_prepare_enable(sram->clk);
66
67 sram->pool = devm_gen_pool_create(&pdev->dev, ilog2(SRAM_GRANULARITY), -1);
68 if (!sram->pool)
69 return -ENOMEM;
70
71 ret = gen_pool_add_virt(sram->pool, (unsigned long)virt_base,
72 res->start, size, -1);
73 if (ret < 0) {
74 gen_pool_destroy(sram->pool);
75 return ret;
76 }
77
78 platform_set_drvdata(pdev, sram);
79
80 dev_dbg(&pdev->dev, "SRAM pool: %ld KiB @ 0x%p\n", size / 1024, virt_base);
81
82 return 0;
83}
84
85static int sram_remove(struct platform_device *pdev)
86{
87 struct sram_dev *sram = platform_get_drvdata(pdev);
88
89 if (gen_pool_avail(sram->pool) < gen_pool_size(sram->pool))
90 dev_dbg(&pdev->dev, "removed while SRAM allocated\n");
91
92 gen_pool_destroy(sram->pool);
93
94 if (sram->clk)
95 clk_disable_unprepare(sram->clk);
96
97 return 0;
98}
99
100#ifdef CONFIG_OF
101static struct of_device_id sram_dt_ids[] = {
102 { .compatible = "mmio-sram" },
103 {}
104};
105#endif
106
107static struct platform_driver sram_driver = {
108 .driver = {
109 .name = "sram",
110 .of_match_table = of_match_ptr(sram_dt_ids),
111 },
112 .probe = sram_probe,
113 .remove = sram_remove,
114};
115
116static int __init sram_init(void)
117{
118 return platform_driver_register(&sram_driver);
119}
120
121postcore_initcall(sram_init);
diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c
index 08a3cf2a7610..9290bb51a06a 100644
--- a/drivers/mmc/core/core.c
+++ b/drivers/mmc/core/core.c
@@ -120,8 +120,8 @@ static void mmc_should_fail_request(struct mmc_host *host,
120 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks)) 120 !should_fail(&host->fail_mmc_request, data->blksz * data->blocks))
121 return; 121 return;
122 122
123 data->error = data_errors[random32() % ARRAY_SIZE(data_errors)]; 123 data->error = data_errors[prandom_u32() % ARRAY_SIZE(data_errors)];
124 data->bytes_xfered = (random32() % (data->bytes_xfered >> 9)) << 9; 124 data->bytes_xfered = (prandom_u32() % (data->bytes_xfered >> 9)) << 9;
125} 125}
126 126
127#else /* CONFIG_FAIL_MMC_REQUEST */ 127#else /* CONFIG_FAIL_MMC_REQUEST */
diff --git a/drivers/rpmsg/virtio_rpmsg_bus.c b/drivers/rpmsg/virtio_rpmsg_bus.c
index a59684b5fc68..7861f1119b7d 100644
--- a/drivers/rpmsg/virtio_rpmsg_bus.c
+++ b/drivers/rpmsg/virtio_rpmsg_bus.c
@@ -951,8 +951,10 @@ static int rpmsg_probe(struct virtio_device *vdev)
951 bufs_va = dma_alloc_coherent(vdev->dev.parent->parent, 951 bufs_va = dma_alloc_coherent(vdev->dev.parent->parent,
952 RPMSG_TOTAL_BUF_SPACE, 952 RPMSG_TOTAL_BUF_SPACE,
953 &vrp->bufs_dma, GFP_KERNEL); 953 &vrp->bufs_dma, GFP_KERNEL);
954 if (!bufs_va) 954 if (!bufs_va) {
955 err = -ENOMEM;
955 goto vqs_del; 956 goto vqs_del;
957 }
956 958
957 dev_dbg(&vdev->dev, "buffers: va %p, dma 0x%llx\n", bufs_va, 959 dev_dbg(&vdev->dev, "buffers: va %p, dma 0x%llx\n", bufs_va,
958 (unsigned long long)vrp->bufs_dma); 960 (unsigned long long)vrp->bufs_dma);
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c
index 9b742d3ffb94..66385402d20e 100644
--- a/drivers/rtc/class.c
+++ b/drivers/rtc/class.c
@@ -259,6 +259,76 @@ void rtc_device_unregister(struct rtc_device *rtc)
259} 259}
260EXPORT_SYMBOL_GPL(rtc_device_unregister); 260EXPORT_SYMBOL_GPL(rtc_device_unregister);
261 261
262static void devm_rtc_device_release(struct device *dev, void *res)
263{
264 struct rtc_device *rtc = *(struct rtc_device **)res;
265
266 rtc_device_unregister(rtc);
267}
268
269static int devm_rtc_device_match(struct device *dev, void *res, void *data)
270{
271 struct rtc **r = res;
272
273 return *r == data;
274}
275
276/**
277 * devm_rtc_device_register - resource managed rtc_device_register()
278 * @dev: the device to register
279 * @name: the name of the device
280 * @ops: the rtc operations structure
281 * @owner: the module owner
282 *
283 * @return a struct rtc on success, or an ERR_PTR on error
284 *
285 * Managed rtc_device_register(). The rtc_device returned from this function
286 * are automatically freed on driver detach. See rtc_device_register()
287 * for more information.
288 */
289
290struct rtc_device *devm_rtc_device_register(struct device *dev,
291 const char *name,
292 const struct rtc_class_ops *ops,
293 struct module *owner)
294{
295 struct rtc_device **ptr, *rtc;
296
297 ptr = devres_alloc(devm_rtc_device_release, sizeof(*ptr), GFP_KERNEL);
298 if (!ptr)
299 return ERR_PTR(-ENOMEM);
300
301 rtc = rtc_device_register(name, dev, ops, owner);
302 if (!IS_ERR(rtc)) {
303 *ptr = rtc;
304 devres_add(dev, ptr);
305 } else {
306 devres_free(ptr);
307 }
308
309 return rtc;
310}
311EXPORT_SYMBOL_GPL(devm_rtc_device_register);
312
313/**
314 * devm_rtc_device_unregister - resource managed devm_rtc_device_unregister()
315 * @dev: the device to unregister
316 * @rtc: the RTC class device to unregister
317 *
318 * Deallocated a rtc allocated with devm_rtc_device_register(). Normally this
319 * function will not need to be called and the resource management code will
320 * ensure that the resource is freed.
321 */
322void devm_rtc_device_unregister(struct device *dev, struct rtc_device *rtc)
323{
324 int rc;
325
326 rc = devres_release(dev, devm_rtc_device_release,
327 devm_rtc_device_match, rtc);
328 WARN_ON(rc);
329}
330EXPORT_SYMBOL_GPL(devm_rtc_device_unregister);
331
262static int __init rtc_init(void) 332static int __init rtc_init(void)
263{ 333{
264 rtc_class = class_create(THIS_MODULE, "rtc"); 334 rtc_class = class_create(THIS_MODULE, "rtc");
diff --git a/drivers/rtc/rtc-88pm80x.c b/drivers/rtc/rtc-88pm80x.c
index 63b17ebe90e8..f3742f364eb8 100644
--- a/drivers/rtc/rtc-88pm80x.c
+++ b/drivers/rtc/rtc-88pm80x.c
@@ -234,7 +234,7 @@ static const struct rtc_class_ops pm80x_rtc_ops = {
234 .alarm_irq_enable = pm80x_rtc_alarm_irq_enable, 234 .alarm_irq_enable = pm80x_rtc_alarm_irq_enable,
235}; 235};
236 236
237#ifdef CONFIG_PM 237#ifdef CONFIG_PM_SLEEP
238static int pm80x_rtc_suspend(struct device *dev) 238static int pm80x_rtc_suspend(struct device *dev)
239{ 239{
240 return pm80x_dev_suspend(dev); 240 return pm80x_dev_suspend(dev);
@@ -312,7 +312,7 @@ static int pm80x_rtc_probe(struct platform_device *pdev)
312 } 312 }
313 rtc_tm_to_time(&tm, &ticks); 313 rtc_tm_to_time(&tm, &ticks);
314 314
315 info->rtc_dev = rtc_device_register("88pm80x-rtc", &pdev->dev, 315 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm80x-rtc",
316 &pm80x_rtc_ops, THIS_MODULE); 316 &pm80x_rtc_ops, THIS_MODULE);
317 if (IS_ERR(info->rtc_dev)) { 317 if (IS_ERR(info->rtc_dev)) {
318 ret = PTR_ERR(info->rtc_dev); 318 ret = PTR_ERR(info->rtc_dev);
@@ -346,7 +346,6 @@ static 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); 348 platform_set_drvdata(pdev, NULL);
349 rtc_device_unregister(info->rtc_dev);
350 pm80x_free_irq(info->chip, info->irq, info); 349 pm80x_free_irq(info->chip, info->irq, info);
351 return 0; 350 return 0;
352} 351}
diff --git a/drivers/rtc/rtc-88pm860x.c b/drivers/rtc/rtc-88pm860x.c
index f663746f4603..0f2b91bfee37 100644
--- a/drivers/rtc/rtc-88pm860x.c
+++ b/drivers/rtc/rtc-88pm860x.c
@@ -318,14 +318,14 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
318 318
319 pdata = pdev->dev.platform_data; 319 pdata = pdev->dev.platform_data;
320 320
321 info = kzalloc(sizeof(struct pm860x_rtc_info), GFP_KERNEL); 321 info = devm_kzalloc(&pdev->dev, sizeof(struct pm860x_rtc_info),
322 GFP_KERNEL);
322 if (!info) 323 if (!info)
323 return -ENOMEM; 324 return -ENOMEM;
324 info->irq = platform_get_irq(pdev, 0); 325 info->irq = platform_get_irq(pdev, 0);
325 if (info->irq < 0) { 326 if (info->irq < 0) {
326 dev_err(&pdev->dev, "No IRQ resource!\n"); 327 dev_err(&pdev->dev, "No IRQ resource!\n");
327 ret = -EINVAL; 328 return info->irq;
328 goto out;
329 } 329 }
330 330
331 info->chip = chip; 331 info->chip = chip;
@@ -333,12 +333,13 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
333 info->dev = &pdev->dev; 333 info->dev = &pdev->dev;
334 dev_set_drvdata(&pdev->dev, info); 334 dev_set_drvdata(&pdev->dev, info);
335 335
336 ret = request_threaded_irq(info->irq, NULL, rtc_update_handler, 336 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
337 IRQF_ONESHOT, "rtc", info); 337 rtc_update_handler, IRQF_ONESHOT, "rtc",
338 info);
338 if (ret < 0) { 339 if (ret < 0) {
339 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", 340 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
340 info->irq, ret); 341 info->irq, ret);
341 goto out; 342 return ret;
342 } 343 }
343 344
344 /* set addresses of 32-bit base value for RTC time */ 345 /* set addresses of 32-bit base value for RTC time */
@@ -350,7 +351,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
350 ret = pm860x_rtc_read_time(&pdev->dev, &tm); 351 ret = pm860x_rtc_read_time(&pdev->dev, &tm);
351 if (ret < 0) { 352 if (ret < 0) {
352 dev_err(&pdev->dev, "Failed to read initial time.\n"); 353 dev_err(&pdev->dev, "Failed to read initial time.\n");
353 goto out_rtc; 354 return ret;
354 } 355 }
355 if ((tm.tm_year < 70) || (tm.tm_year > 138)) { 356 if ((tm.tm_year < 70) || (tm.tm_year > 138)) {
356 tm.tm_year = 70; 357 tm.tm_year = 70;
@@ -362,7 +363,7 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
362 ret = pm860x_rtc_set_time(&pdev->dev, &tm); 363 ret = pm860x_rtc_set_time(&pdev->dev, &tm);
363 if (ret < 0) { 364 if (ret < 0) {
364 dev_err(&pdev->dev, "Failed to set initial time.\n"); 365 dev_err(&pdev->dev, "Failed to set initial time.\n");
365 goto out_rtc; 366 return ret;
366 } 367 }
367 } 368 }
368 rtc_tm_to_time(&tm, &ticks); 369 rtc_tm_to_time(&tm, &ticks);
@@ -373,12 +374,12 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
373 } 374 }
374 } 375 }
375 376
376 info->rtc_dev = rtc_device_register("88pm860x-rtc", &pdev->dev, 377 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "88pm860x-rtc",
377 &pm860x_rtc_ops, THIS_MODULE); 378 &pm860x_rtc_ops, THIS_MODULE);
378 ret = PTR_ERR(info->rtc_dev); 379 ret = PTR_ERR(info->rtc_dev);
379 if (IS_ERR(info->rtc_dev)) { 380 if (IS_ERR(info->rtc_dev)) {
380 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret); 381 dev_err(&pdev->dev, "Failed to register RTC device: %d\n", ret);
381 goto out_rtc; 382 return ret;
382 } 383 }
383 384
384 /* 385 /*
@@ -405,11 +406,6 @@ static int pm860x_rtc_probe(struct platform_device *pdev)
405 device_init_wakeup(&pdev->dev, 1); 406 device_init_wakeup(&pdev->dev, 1);
406 407
407 return 0; 408 return 0;
408out_rtc:
409 free_irq(info->irq, info);
410out:
411 kfree(info);
412 return ret;
413} 409}
414 410
415static int pm860x_rtc_remove(struct platform_device *pdev) 411static int pm860x_rtc_remove(struct platform_device *pdev)
@@ -423,9 +419,6 @@ static int pm860x_rtc_remove(struct platform_device *pdev)
423#endif /* VRTC_CALIBRATION */ 419#endif /* VRTC_CALIBRATION */
424 420
425 platform_set_drvdata(pdev, NULL); 421 platform_set_drvdata(pdev, NULL);
426 rtc_device_unregister(info->rtc_dev);
427 free_irq(info->irq, info);
428 kfree(info);
429 return 0; 422 return 0;
430} 423}
431 424
diff --git a/drivers/rtc/rtc-ab3100.c b/drivers/rtc/rtc-ab3100.c
index 261a07e0fb24..47a4f2c4d30e 100644
--- a/drivers/rtc/rtc-ab3100.c
+++ b/drivers/rtc/rtc-ab3100.c
@@ -229,8 +229,8 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
229 /* Ignore any error on this write */ 229 /* Ignore any error on this write */
230 } 230 }
231 231
232 rtc = rtc_device_register("ab3100-rtc", &pdev->dev, &ab3100_rtc_ops, 232 rtc = devm_rtc_device_register(&pdev->dev, "ab3100-rtc",
233 THIS_MODULE); 233 &ab3100_rtc_ops, THIS_MODULE);
234 if (IS_ERR(rtc)) { 234 if (IS_ERR(rtc)) {
235 err = PTR_ERR(rtc); 235 err = PTR_ERR(rtc);
236 return err; 236 return err;
@@ -242,9 +242,6 @@ static int __init ab3100_rtc_probe(struct platform_device *pdev)
242 242
243static int __exit ab3100_rtc_remove(struct platform_device *pdev) 243static int __exit ab3100_rtc_remove(struct platform_device *pdev)
244{ 244{
245 struct rtc_device *rtc = platform_get_drvdata(pdev);
246
247 rtc_device_unregister(rtc);
248 platform_set_drvdata(pdev, NULL); 245 platform_set_drvdata(pdev, NULL);
249 return 0; 246 return 0;
250} 247}
@@ -257,19 +254,7 @@ static struct platform_driver ab3100_rtc_driver = {
257 .remove = __exit_p(ab3100_rtc_remove), 254 .remove = __exit_p(ab3100_rtc_remove),
258}; 255};
259 256
260static int __init ab3100_rtc_init(void) 257module_platform_driver_probe(ab3100_rtc_driver, ab3100_rtc_probe);
261{
262 return platform_driver_probe(&ab3100_rtc_driver,
263 ab3100_rtc_probe);
264}
265
266static void __exit ab3100_rtc_exit(void)
267{
268 platform_driver_unregister(&ab3100_rtc_driver);
269}
270
271module_init(ab3100_rtc_init);
272module_exit(ab3100_rtc_exit);
273 258
274MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>"); 259MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
275MODULE_DESCRIPTION("AB3100 RTC Driver"); 260MODULE_DESCRIPTION("AB3100 RTC Driver");
diff --git a/drivers/rtc/rtc-ab8500.c b/drivers/rtc/rtc-ab8500.c
index 57cde2b061e6..63cfa314a39f 100644
--- a/drivers/rtc/rtc-ab8500.c
+++ b/drivers/rtc/rtc-ab8500.c
@@ -422,20 +422,19 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
422 422
423 device_init_wakeup(&pdev->dev, true); 423 device_init_wakeup(&pdev->dev, true);
424 424
425 rtc = rtc_device_register("ab8500-rtc", &pdev->dev, &ab8500_rtc_ops, 425 rtc = devm_rtc_device_register(&pdev->dev, "ab8500-rtc",
426 THIS_MODULE); 426 &ab8500_rtc_ops, THIS_MODULE);
427 if (IS_ERR(rtc)) { 427 if (IS_ERR(rtc)) {
428 dev_err(&pdev->dev, "Registration failed\n"); 428 dev_err(&pdev->dev, "Registration failed\n");
429 err = PTR_ERR(rtc); 429 err = PTR_ERR(rtc);
430 return err; 430 return err;
431 } 431 }
432 432
433 err = request_threaded_irq(irq, NULL, rtc_alarm_handler, 433 err = devm_request_threaded_irq(&pdev->dev, irq, NULL,
434 IRQF_NO_SUSPEND | IRQF_ONESHOT, "ab8500-rtc", rtc); 434 rtc_alarm_handler, IRQF_NO_SUSPEND | IRQF_ONESHOT,
435 if (err < 0) { 435 "ab8500-rtc", rtc);
436 rtc_device_unregister(rtc); 436 if (err < 0)
437 return err; 437 return err;
438 }
439 438
440 platform_set_drvdata(pdev, rtc); 439 platform_set_drvdata(pdev, rtc);
441 440
@@ -450,13 +449,8 @@ static int ab8500_rtc_probe(struct platform_device *pdev)
450 449
451static int ab8500_rtc_remove(struct platform_device *pdev) 450static int ab8500_rtc_remove(struct platform_device *pdev)
452{ 451{
453 struct rtc_device *rtc = platform_get_drvdata(pdev);
454 int irq = platform_get_irq_byname(pdev, "ALARM");
455
456 ab8500_sysfs_rtc_unregister(&pdev->dev); 452 ab8500_sysfs_rtc_unregister(&pdev->dev);
457 453
458 free_irq(irq, rtc);
459 rtc_device_unregister(rtc);
460 platform_set_drvdata(pdev, NULL); 454 platform_set_drvdata(pdev, NULL);
461 455
462 return 0; 456 return 0;
diff --git a/drivers/rtc/rtc-at32ap700x.c b/drivers/rtc/rtc-at32ap700x.c
index 8dd08305aae1..f47fbb5eee8b 100644
--- a/drivers/rtc/rtc-at32ap700x.c
+++ b/drivers/rtc/rtc-at32ap700x.c
@@ -202,7 +202,8 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
202 int irq; 202 int irq;
203 int ret; 203 int ret;
204 204
205 rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL); 205 rtc = devm_kzalloc(&pdev->dev, sizeof(struct rtc_at32ap700x),
206 GFP_KERNEL);
206 if (!rtc) { 207 if (!rtc) {
207 dev_dbg(&pdev->dev, "out of memory\n"); 208 dev_dbg(&pdev->dev, "out of memory\n");
208 return -ENOMEM; 209 return -ENOMEM;
@@ -223,7 +224,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
223 } 224 }
224 225
225 rtc->irq = irq; 226 rtc->irq = irq;
226 rtc->regs = ioremap(regs->start, resource_size(regs)); 227 rtc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
227 if (!rtc->regs) { 228 if (!rtc->regs) {
228 ret = -ENOMEM; 229 ret = -ENOMEM;
229 dev_dbg(&pdev->dev, "could not map I/O memory\n"); 230 dev_dbg(&pdev->dev, "could not map I/O memory\n");
@@ -244,20 +245,21 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
244 | RTC_BIT(CTRL_EN)); 245 | RTC_BIT(CTRL_EN));
245 } 246 }
246 247
247 ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc); 248 ret = devm_request_irq(&pdev->dev, irq, at32_rtc_interrupt, IRQF_SHARED,
249 "rtc", rtc);
248 if (ret) { 250 if (ret) {
249 dev_dbg(&pdev->dev, "could not request irq %d\n", irq); 251 dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
250 goto out_iounmap; 252 goto out;
251 } 253 }
252 254
253 platform_set_drvdata(pdev, rtc); 255 platform_set_drvdata(pdev, rtc);
254 256
255 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 257 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
256 &at32_rtc_ops, THIS_MODULE); 258 &at32_rtc_ops, THIS_MODULE);
257 if (IS_ERR(rtc->rtc)) { 259 if (IS_ERR(rtc->rtc)) {
258 dev_dbg(&pdev->dev, "could not register rtc device\n"); 260 dev_dbg(&pdev->dev, "could not register rtc device\n");
259 ret = PTR_ERR(rtc->rtc); 261 ret = PTR_ERR(rtc->rtc);
260 goto out_free_irq; 262 goto out;
261 } 263 }
262 264
263 device_init_wakeup(&pdev->dev, 1); 265 device_init_wakeup(&pdev->dev, 1);
@@ -267,26 +269,15 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
267 269
268 return 0; 270 return 0;
269 271
270out_free_irq:
271 platform_set_drvdata(pdev, NULL);
272 free_irq(irq, rtc);
273out_iounmap:
274 iounmap(rtc->regs);
275out: 272out:
276 kfree(rtc); 273 platform_set_drvdata(pdev, NULL);
277 return ret; 274 return ret;
278} 275}
279 276
280static int __exit at32_rtc_remove(struct platform_device *pdev) 277static int __exit at32_rtc_remove(struct platform_device *pdev)
281{ 278{
282 struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
283
284 device_init_wakeup(&pdev->dev, 0); 279 device_init_wakeup(&pdev->dev, 0);
285 280
286 free_irq(rtc->irq, rtc);
287 iounmap(rtc->regs);
288 rtc_device_unregister(rtc->rtc);
289 kfree(rtc);
290 platform_set_drvdata(pdev, NULL); 281 platform_set_drvdata(pdev, NULL);
291 282
292 return 0; 283 return 0;
@@ -302,17 +293,7 @@ static struct platform_driver at32_rtc_driver = {
302 }, 293 },
303}; 294};
304 295
305static int __init at32_rtc_init(void) 296module_platform_driver_probe(at32_rtc_driver, at32_rtc_probe);
306{
307 return platform_driver_probe(&at32_rtc_driver, at32_rtc_probe);
308}
309module_init(at32_rtc_init);
310
311static void __exit at32_rtc_exit(void)
312{
313 platform_driver_unregister(&at32_rtc_driver);
314}
315module_exit(at32_rtc_exit);
316 297
317MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>"); 298MODULE_AUTHOR("Hans-Christian Egtvedt <hcegtvedt@atmel.com>");
318MODULE_DESCRIPTION("Real time clock for AVR32 AT32AP700x"); 299MODULE_DESCRIPTION("Real time clock for AVR32 AT32AP700x");
diff --git a/drivers/rtc/rtc-at91rm9200.c b/drivers/rtc/rtc-at91rm9200.c
index 434ebc3a99dc..0eab77b22340 100644
--- a/drivers/rtc/rtc-at91rm9200.c
+++ b/drivers/rtc/rtc-at91rm9200.c
@@ -28,6 +28,8 @@
28#include <linux/ioctl.h> 28#include <linux/ioctl.h>
29#include <linux/completion.h> 29#include <linux/completion.h>
30#include <linux/io.h> 30#include <linux/io.h>
31#include <linux/of.h>
32#include <linux/of_device.h>
31 33
32#include <asm/uaccess.h> 34#include <asm/uaccess.h>
33 35
@@ -297,7 +299,7 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
297 "at91_rtc", pdev); 299 "at91_rtc", pdev);
298 if (ret) { 300 if (ret) {
299 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq); 301 dev_err(&pdev->dev, "IRQ %d already in use.\n", irq);
300 return ret; 302 goto err_unmap;
301 } 303 }
302 304
303 /* cpu init code should really have flagged this device as 305 /* cpu init code should really have flagged this device as
@@ -309,13 +311,20 @@ static int __init at91_rtc_probe(struct platform_device *pdev)
309 rtc = rtc_device_register(pdev->name, &pdev->dev, 311 rtc = rtc_device_register(pdev->name, &pdev->dev,
310 &at91_rtc_ops, THIS_MODULE); 312 &at91_rtc_ops, THIS_MODULE);
311 if (IS_ERR(rtc)) { 313 if (IS_ERR(rtc)) {
312 free_irq(irq, pdev); 314 ret = PTR_ERR(rtc);
313 return PTR_ERR(rtc); 315 goto err_free_irq;
314 } 316 }
315 platform_set_drvdata(pdev, rtc); 317 platform_set_drvdata(pdev, rtc);
316 318
317 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n"); 319 dev_info(&pdev->dev, "AT91 Real Time Clock driver.\n");
318 return 0; 320 return 0;
321
322err_free_irq:
323 free_irq(irq, pdev);
324err_unmap:
325 iounmap(at91_rtc_regs);
326
327 return ret;
319} 328}
320 329
321/* 330/*
@@ -332,12 +341,13 @@ static int __exit at91_rtc_remove(struct platform_device *pdev)
332 free_irq(irq, pdev); 341 free_irq(irq, pdev);
333 342
334 rtc_device_unregister(rtc); 343 rtc_device_unregister(rtc);
344 iounmap(at91_rtc_regs);
335 platform_set_drvdata(pdev, NULL); 345 platform_set_drvdata(pdev, NULL);
336 346
337 return 0; 347 return 0;
338} 348}
339 349
340#ifdef CONFIG_PM 350#ifdef CONFIG_PM_SLEEP
341 351
342/* AT91RM9200 RTC Power management control */ 352/* AT91RM9200 RTC Power management control */
343 353
@@ -369,39 +379,27 @@ static int at91_rtc_resume(struct device *dev)
369 } 379 }
370 return 0; 380 return 0;
371} 381}
382#endif
372 383
373static const struct dev_pm_ops at91_rtc_pm = { 384static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
374 .suspend = at91_rtc_suspend,
375 .resume = at91_rtc_resume,
376};
377
378#define at91_rtc_pm_ptr &at91_rtc_pm
379 385
380#else 386static const struct of_device_id at91_rtc_dt_ids[] = {
381#define at91_rtc_pm_ptr NULL 387 { .compatible = "atmel,at91rm9200-rtc" },
382#endif 388 { /* sentinel */ }
389};
390MODULE_DEVICE_TABLE(of, at91_rtc_dt_ids);
383 391
384static struct platform_driver at91_rtc_driver = { 392static struct platform_driver at91_rtc_driver = {
385 .remove = __exit_p(at91_rtc_remove), 393 .remove = __exit_p(at91_rtc_remove),
386 .driver = { 394 .driver = {
387 .name = "at91_rtc", 395 .name = "at91_rtc",
388 .owner = THIS_MODULE, 396 .owner = THIS_MODULE,
389 .pm = at91_rtc_pm_ptr, 397 .pm = &at91_rtc_pm_ops,
398 .of_match_table = of_match_ptr(at91_rtc_dt_ids),
390 }, 399 },
391}; 400};
392 401
393static int __init at91_rtc_init(void) 402module_platform_driver_probe(at91_rtc_driver, at91_rtc_probe);
394{
395 return platform_driver_probe(&at91_rtc_driver, at91_rtc_probe);
396}
397
398static void __exit at91_rtc_exit(void)
399{
400 platform_driver_unregister(&at91_rtc_driver);
401}
402
403module_init(at91_rtc_init);
404module_exit(at91_rtc_exit);
405 403
406MODULE_AUTHOR("Rick Bronson"); 404MODULE_AUTHOR("Rick Bronson");
407MODULE_DESCRIPTION("RTC driver for Atmel AT91RM9200"); 405MODULE_DESCRIPTION("RTC driver for Atmel AT91RM9200");
diff --git a/drivers/rtc/rtc-at91sam9.c b/drivers/rtc/rtc-at91sam9.c
index 39cfd2ee0042..b60a34cb145a 100644
--- a/drivers/rtc/rtc-at91sam9.c
+++ b/drivers/rtc/rtc-at91sam9.c
@@ -20,6 +20,7 @@
20#include <linux/ioctl.h> 20#include <linux/ioctl.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/platform_data/atmel.h> 22#include <linux/platform_data/atmel.h>
23#include <linux/io.h>
23 24
24#include <mach/at91_rtt.h> 25#include <mach/at91_rtt.h>
25#include <mach/cpu.h> 26#include <mach/cpu.h>
@@ -309,7 +310,7 @@ static int at91_rtc_probe(struct platform_device *pdev)
309 return irq; 310 return irq;
310 } 311 }
311 312
312 rtc = kzalloc(sizeof *rtc, GFP_KERNEL); 313 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
313 if (!rtc) 314 if (!rtc)
314 return -ENOMEM; 315 return -ENOMEM;
315 316
@@ -320,18 +321,19 @@ static int at91_rtc_probe(struct platform_device *pdev)
320 device_init_wakeup(&pdev->dev, 1); 321 device_init_wakeup(&pdev->dev, 1);
321 322
322 platform_set_drvdata(pdev, rtc); 323 platform_set_drvdata(pdev, rtc);
323 rtc->rtt = ioremap(r->start, resource_size(r)); 324 rtc->rtt = devm_ioremap(&pdev->dev, r->start, resource_size(r));
324 if (!rtc->rtt) { 325 if (!rtc->rtt) {
325 dev_err(&pdev->dev, "failed to map registers, aborting.\n"); 326 dev_err(&pdev->dev, "failed to map registers, aborting.\n");
326 ret = -ENOMEM; 327 ret = -ENOMEM;
327 goto fail; 328 goto fail;
328 } 329 }
329 330
330 rtc->gpbr = ioremap(r_gpbr->start, resource_size(r_gpbr)); 331 rtc->gpbr = devm_ioremap(&pdev->dev, r_gpbr->start,
332 resource_size(r_gpbr));
331 if (!rtc->gpbr) { 333 if (!rtc->gpbr) {
332 dev_err(&pdev->dev, "failed to map gpbr registers, aborting.\n"); 334 dev_err(&pdev->dev, "failed to map gpbr registers, aborting.\n");
333 ret = -ENOMEM; 335 ret = -ENOMEM;
334 goto fail_gpbr; 336 goto fail;
335 } 337 }
336 338
337 mr = rtt_readl(rtc, MR); 339 mr = rtt_readl(rtc, MR);
@@ -346,20 +348,19 @@ static int at91_rtc_probe(struct platform_device *pdev)
346 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); 348 mr &= ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
347 rtt_writel(rtc, MR, mr); 349 rtt_writel(rtc, MR, mr);
348 350
349 rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev, 351 rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
350 &at91_rtc_ops, THIS_MODULE); 352 &at91_rtc_ops, THIS_MODULE);
351 if (IS_ERR(rtc->rtcdev)) { 353 if (IS_ERR(rtc->rtcdev)) {
352 ret = PTR_ERR(rtc->rtcdev); 354 ret = PTR_ERR(rtc->rtcdev);
353 goto fail_register; 355 goto fail;
354 } 356 }
355 357
356 /* register irq handler after we know what name we'll use */ 358 /* register irq handler after we know what name we'll use */
357 ret = request_irq(rtc->irq, at91_rtc_interrupt, IRQF_SHARED, 359 ret = devm_request_irq(&pdev->dev, rtc->irq, at91_rtc_interrupt,
358 dev_name(&rtc->rtcdev->dev), rtc); 360 IRQF_SHARED, dev_name(&rtc->rtcdev->dev), rtc);
359 if (ret) { 361 if (ret) {
360 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq); 362 dev_dbg(&pdev->dev, "can't share IRQ %d?\n", rtc->irq);
361 rtc_device_unregister(rtc->rtcdev); 363 goto fail;
362 goto fail_register;
363 } 364 }
364 365
365 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the 366 /* NOTE: sam9260 rev A silicon has a ROM bug which resets the
@@ -374,13 +375,8 @@ static int at91_rtc_probe(struct platform_device *pdev)
374 375
375 return 0; 376 return 0;
376 377
377fail_register:
378 iounmap(rtc->gpbr);
379fail_gpbr:
380 iounmap(rtc->rtt);
381fail: 378fail:
382 platform_set_drvdata(pdev, NULL); 379 platform_set_drvdata(pdev, NULL);
383 kfree(rtc);
384 return ret; 380 return ret;
385} 381}
386 382
@@ -394,14 +390,8 @@ static int at91_rtc_remove(struct platform_device *pdev)
394 390
395 /* disable all interrupts */ 391 /* disable all interrupts */
396 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN)); 392 rtt_writel(rtc, MR, mr & ~(AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN));
397 free_irq(rtc->irq, rtc);
398
399 rtc_device_unregister(rtc->rtcdev);
400 393
401 iounmap(rtc->gpbr);
402 iounmap(rtc->rtt);
403 platform_set_drvdata(pdev, NULL); 394 platform_set_drvdata(pdev, NULL);
404 kfree(rtc);
405 return 0; 395 return 0;
406} 396}
407 397
@@ -414,14 +404,13 @@ static void at91_rtc_shutdown(struct platform_device *pdev)
414 rtt_writel(rtc, MR, mr & ~rtc->imr); 404 rtt_writel(rtc, MR, mr & ~rtc->imr);
415} 405}
416 406
417#ifdef CONFIG_PM 407#ifdef CONFIG_PM_SLEEP
418 408
419/* AT91SAM9 RTC Power management control */ 409/* AT91SAM9 RTC Power management control */
420 410
421static int at91_rtc_suspend(struct platform_device *pdev, 411static int at91_rtc_suspend(struct device *dev)
422 pm_message_t state)
423{ 412{
424 struct sam9_rtc *rtc = platform_get_drvdata(pdev); 413 struct sam9_rtc *rtc = dev_get_drvdata(dev);
425 u32 mr = rtt_readl(rtc, MR); 414 u32 mr = rtt_readl(rtc, MR);
426 415
427 /* 416 /*
@@ -430,7 +419,7 @@ static int at91_rtc_suspend(struct platform_device *pdev,
430 */ 419 */
431 rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN); 420 rtc->imr = mr & (AT91_RTT_ALMIEN | AT91_RTT_RTTINCIEN);
432 if (rtc->imr) { 421 if (rtc->imr) {
433 if (device_may_wakeup(&pdev->dev) && (mr & AT91_RTT_ALMIEN)) { 422 if (device_may_wakeup(dev) && (mr & AT91_RTT_ALMIEN)) {
434 enable_irq_wake(rtc->irq); 423 enable_irq_wake(rtc->irq);
435 /* don't let RTTINC cause wakeups */ 424 /* don't let RTTINC cause wakeups */
436 if (mr & AT91_RTT_RTTINCIEN) 425 if (mr & AT91_RTT_RTTINCIEN)
@@ -442,13 +431,13 @@ static int at91_rtc_suspend(struct platform_device *pdev,
442 return 0; 431 return 0;
443} 432}
444 433
445static int at91_rtc_resume(struct platform_device *pdev) 434static int at91_rtc_resume(struct device *dev)
446{ 435{
447 struct sam9_rtc *rtc = platform_get_drvdata(pdev); 436 struct sam9_rtc *rtc = dev_get_drvdata(dev);
448 u32 mr; 437 u32 mr;
449 438
450 if (rtc->imr) { 439 if (rtc->imr) {
451 if (device_may_wakeup(&pdev->dev)) 440 if (device_may_wakeup(dev))
452 disable_irq_wake(rtc->irq); 441 disable_irq_wake(rtc->irq);
453 mr = rtt_readl(rtc, MR); 442 mr = rtt_readl(rtc, MR);
454 rtt_writel(rtc, MR, mr | rtc->imr); 443 rtt_writel(rtc, MR, mr | rtc->imr);
@@ -456,20 +445,18 @@ static int at91_rtc_resume(struct platform_device *pdev)
456 445
457 return 0; 446 return 0;
458} 447}
459#else
460#define at91_rtc_suspend NULL
461#define at91_rtc_resume NULL
462#endif 448#endif
463 449
450static SIMPLE_DEV_PM_OPS(at91_rtc_pm_ops, at91_rtc_suspend, at91_rtc_resume);
451
464static struct platform_driver at91_rtc_driver = { 452static struct platform_driver at91_rtc_driver = {
465 .probe = at91_rtc_probe, 453 .probe = at91_rtc_probe,
466 .remove = at91_rtc_remove, 454 .remove = at91_rtc_remove,
467 .shutdown = at91_rtc_shutdown, 455 .shutdown = at91_rtc_shutdown,
468 .suspend = at91_rtc_suspend,
469 .resume = at91_rtc_resume,
470 .driver = { 456 .driver = {
471 .name = "rtc-at91sam9", 457 .name = "rtc-at91sam9",
472 .owner = THIS_MODULE, 458 .owner = THIS_MODULE,
459 .pm = &at91_rtc_pm_ops,
473 }, 460 },
474}; 461};
475 462
diff --git a/drivers/rtc/rtc-au1xxx.c b/drivers/rtc/rtc-au1xxx.c
index b309da4ec745..7995abc391fc 100644
--- a/drivers/rtc/rtc-au1xxx.c
+++ b/drivers/rtc/rtc-au1xxx.c
@@ -101,7 +101,7 @@ static int au1xtoy_rtc_probe(struct platform_device *pdev)
101 while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S) 101 while (au_readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_C0S)
102 msleep(1); 102 msleep(1);
103 103
104 rtcdev = rtc_device_register("rtc-au1xxx", &pdev->dev, 104 rtcdev = devm_rtc_device_register(&pdev->dev, "rtc-au1xxx",
105 &au1xtoy_rtc_ops, THIS_MODULE); 105 &au1xtoy_rtc_ops, THIS_MODULE);
106 if (IS_ERR(rtcdev)) { 106 if (IS_ERR(rtcdev)) {
107 ret = PTR_ERR(rtcdev); 107 ret = PTR_ERR(rtcdev);
@@ -118,9 +118,6 @@ out_err:
118 118
119static int au1xtoy_rtc_remove(struct platform_device *pdev) 119static int au1xtoy_rtc_remove(struct platform_device *pdev)
120{ 120{
121 struct rtc_device *rtcdev = platform_get_drvdata(pdev);
122
123 rtc_device_unregister(rtcdev);
124 platform_set_drvdata(pdev, NULL); 121 platform_set_drvdata(pdev, NULL);
125 122
126 return 0; 123 return 0;
@@ -134,18 +131,7 @@ static struct platform_driver au1xrtc_driver = {
134 .remove = au1xtoy_rtc_remove, 131 .remove = au1xtoy_rtc_remove,
135}; 132};
136 133
137static int __init au1xtoy_rtc_init(void) 134module_platform_driver_probe(au1xrtc_driver, au1xtoy_rtc_probe);
138{
139 return platform_driver_probe(&au1xrtc_driver, au1xtoy_rtc_probe);
140}
141
142static void __exit au1xtoy_rtc_exit(void)
143{
144 platform_driver_unregister(&au1xrtc_driver);
145}
146
147module_init(au1xtoy_rtc_init);
148module_exit(au1xtoy_rtc_exit);
149 135
150MODULE_DESCRIPTION("Au1xxx TOY-counter-based RTC driver"); 136MODULE_DESCRIPTION("Au1xxx TOY-counter-based RTC driver");
151MODULE_AUTHOR("Manuel Lauss <manuel.lauss@gmail.com>"); 137MODULE_AUTHOR("Manuel Lauss <manuel.lauss@gmail.com>");
diff --git a/drivers/rtc/rtc-bfin.c b/drivers/rtc/rtc-bfin.c
index 4ec614b0954d..ad44ec5dc29a 100644
--- a/drivers/rtc/rtc-bfin.c
+++ b/drivers/rtc/rtc-bfin.c
@@ -352,14 +352,14 @@ static int bfin_rtc_probe(struct platform_device *pdev)
352 dev_dbg_stamp(dev); 352 dev_dbg_stamp(dev);
353 353
354 /* Allocate memory for our RTC struct */ 354 /* Allocate memory for our RTC struct */
355 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 355 rtc = devm_kzalloc(dev, sizeof(*rtc), GFP_KERNEL);
356 if (unlikely(!rtc)) 356 if (unlikely(!rtc))
357 return -ENOMEM; 357 return -ENOMEM;
358 platform_set_drvdata(pdev, rtc); 358 platform_set_drvdata(pdev, rtc);
359 device_init_wakeup(dev, 1); 359 device_init_wakeup(dev, 1);
360 360
361 /* Register our RTC with the RTC framework */ 361 /* Register our RTC with the RTC framework */
362 rtc->rtc_dev = rtc_device_register(pdev->name, dev, &bfin_rtc_ops, 362 rtc->rtc_dev = devm_rtc_device_register(dev, pdev->name, &bfin_rtc_ops,
363 THIS_MODULE); 363 THIS_MODULE);
364 if (unlikely(IS_ERR(rtc->rtc_dev))) { 364 if (unlikely(IS_ERR(rtc->rtc_dev))) {
365 ret = PTR_ERR(rtc->rtc_dev); 365 ret = PTR_ERR(rtc->rtc_dev);
@@ -367,9 +367,10 @@ static int bfin_rtc_probe(struct platform_device *pdev)
367 } 367 }
368 368
369 /* Grab the IRQ and init the hardware */ 369 /* Grab the IRQ and init the hardware */
370 ret = request_irq(IRQ_RTC, bfin_rtc_interrupt, 0, pdev->name, dev); 370 ret = devm_request_irq(dev, IRQ_RTC, bfin_rtc_interrupt, 0,
371 pdev->name, dev);
371 if (unlikely(ret)) 372 if (unlikely(ret))
372 goto err_reg; 373 goto err;
373 /* sometimes the bootloader touched things, but the write complete was not 374 /* sometimes the bootloader touched things, but the write complete was not
374 * enabled, so let's just do a quick timeout here since the IRQ will not fire ... 375 * enabled, so let's just do a quick timeout here since the IRQ will not fire ...
375 */ 376 */
@@ -381,32 +382,23 @@ static int bfin_rtc_probe(struct platform_device *pdev)
381 382
382 return 0; 383 return 0;
383 384
384err_reg:
385 rtc_device_unregister(rtc->rtc_dev);
386err: 385err:
387 kfree(rtc);
388 return ret; 386 return ret;
389} 387}
390 388
391static int bfin_rtc_remove(struct platform_device *pdev) 389static int bfin_rtc_remove(struct platform_device *pdev)
392{ 390{
393 struct bfin_rtc *rtc = platform_get_drvdata(pdev);
394 struct device *dev = &pdev->dev; 391 struct device *dev = &pdev->dev;
395 392
396 bfin_rtc_reset(dev, 0); 393 bfin_rtc_reset(dev, 0);
397 free_irq(IRQ_RTC, dev);
398 rtc_device_unregister(rtc->rtc_dev);
399 platform_set_drvdata(pdev, NULL); 394 platform_set_drvdata(pdev, NULL);
400 kfree(rtc);
401 395
402 return 0; 396 return 0;
403} 397}
404 398
405#ifdef CONFIG_PM 399#ifdef CONFIG_PM_SLEEP
406static int bfin_rtc_suspend(struct platform_device *pdev, pm_message_t state) 400static int bfin_rtc_suspend(struct device *dev)
407{ 401{
408 struct device *dev = &pdev->dev;
409
410 dev_dbg_stamp(dev); 402 dev_dbg_stamp(dev);
411 403
412 if (device_may_wakeup(dev)) { 404 if (device_may_wakeup(dev)) {
@@ -418,10 +410,8 @@ static int bfin_rtc_suspend(struct platform_device *pdev, pm_message_t state)
418 return 0; 410 return 0;
419} 411}
420 412
421static int bfin_rtc_resume(struct platform_device *pdev) 413static int bfin_rtc_resume(struct device *dev)
422{ 414{
423 struct device *dev = &pdev->dev;
424
425 dev_dbg_stamp(dev); 415 dev_dbg_stamp(dev);
426 416
427 if (device_may_wakeup(dev)) 417 if (device_may_wakeup(dev))
@@ -440,20 +430,18 @@ static int bfin_rtc_resume(struct platform_device *pdev)
440 430
441 return 0; 431 return 0;
442} 432}
443#else
444# define bfin_rtc_suspend NULL
445# define bfin_rtc_resume NULL
446#endif 433#endif
447 434
435static SIMPLE_DEV_PM_OPS(bfin_rtc_pm_ops, bfin_rtc_suspend, bfin_rtc_resume);
436
448static struct platform_driver bfin_rtc_driver = { 437static struct platform_driver bfin_rtc_driver = {
449 .driver = { 438 .driver = {
450 .name = "rtc-bfin", 439 .name = "rtc-bfin",
451 .owner = THIS_MODULE, 440 .owner = THIS_MODULE,
441 .pm = &bfin_rtc_pm_ops,
452 }, 442 },
453 .probe = bfin_rtc_probe, 443 .probe = bfin_rtc_probe,
454 .remove = bfin_rtc_remove, 444 .remove = bfin_rtc_remove,
455 .suspend = bfin_rtc_suspend,
456 .resume = bfin_rtc_resume,
457}; 445};
458 446
459module_platform_driver(bfin_rtc_driver); 447module_platform_driver(bfin_rtc_driver);
diff --git a/drivers/rtc/rtc-bq32k.c b/drivers/rtc/rtc-bq32k.c
index 036cb89f8188..fea78bc713ca 100644
--- a/drivers/rtc/rtc-bq32k.c
+++ b/drivers/rtc/rtc-bq32k.c
@@ -153,7 +153,7 @@ static int bq32k_probe(struct i2c_client *client,
153 if (error) 153 if (error)
154 return error; 154 return error;
155 155
156 rtc = rtc_device_register(bq32k_driver.driver.name, &client->dev, 156 rtc = devm_rtc_device_register(&client->dev, bq32k_driver.driver.name,
157 &bq32k_rtc_ops, THIS_MODULE); 157 &bq32k_rtc_ops, THIS_MODULE);
158 if (IS_ERR(rtc)) 158 if (IS_ERR(rtc))
159 return PTR_ERR(rtc); 159 return PTR_ERR(rtc);
@@ -165,9 +165,6 @@ static int bq32k_probe(struct i2c_client *client,
165 165
166static int bq32k_remove(struct i2c_client *client) 166static int bq32k_remove(struct i2c_client *client)
167{ 167{
168 struct rtc_device *rtc = i2c_get_clientdata(client);
169
170 rtc_device_unregister(rtc);
171 return 0; 168 return 0;
172} 169}
173 170
diff --git a/drivers/rtc/rtc-bq4802.c b/drivers/rtc/rtc-bq4802.c
index 693be71b5b18..af2886784a7b 100644
--- a/drivers/rtc/rtc-bq4802.c
+++ b/drivers/rtc/rtc-bq4802.c
@@ -142,7 +142,7 @@ static const struct rtc_class_ops bq4802_ops = {
142 142
143static int bq4802_probe(struct platform_device *pdev) 143static int bq4802_probe(struct platform_device *pdev)
144{ 144{
145 struct bq4802 *p = kzalloc(sizeof(*p), GFP_KERNEL); 145 struct bq4802 *p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL);
146 int err = -ENOMEM; 146 int err = -ENOMEM;
147 147
148 if (!p) 148 if (!p)
@@ -155,54 +155,41 @@ static int bq4802_probe(struct platform_device *pdev)
155 p->r = platform_get_resource(pdev, IORESOURCE_IO, 0); 155 p->r = platform_get_resource(pdev, IORESOURCE_IO, 0);
156 err = -EINVAL; 156 err = -EINVAL;
157 if (!p->r) 157 if (!p->r)
158 goto out_free; 158 goto out;
159 } 159 }
160 if (p->r->flags & IORESOURCE_IO) { 160 if (p->r->flags & IORESOURCE_IO) {
161 p->ioport = p->r->start; 161 p->ioport = p->r->start;
162 p->read = bq4802_read_io; 162 p->read = bq4802_read_io;
163 p->write = bq4802_write_io; 163 p->write = bq4802_write_io;
164 } else if (p->r->flags & IORESOURCE_MEM) { 164 } else if (p->r->flags & IORESOURCE_MEM) {
165 p->regs = ioremap(p->r->start, resource_size(p->r)); 165 p->regs = devm_ioremap(&pdev->dev, p->r->start,
166 resource_size(p->r));
166 p->read = bq4802_read_mem; 167 p->read = bq4802_read_mem;
167 p->write = bq4802_write_mem; 168 p->write = bq4802_write_mem;
168 } else { 169 } else {
169 err = -EINVAL; 170 err = -EINVAL;
170 goto out_free; 171 goto out;
171 } 172 }
172 173
173 platform_set_drvdata(pdev, p); 174 platform_set_drvdata(pdev, p);
174 175
175 p->rtc = rtc_device_register("bq4802", &pdev->dev, 176 p->rtc = devm_rtc_device_register(&pdev->dev, "bq4802",
176 &bq4802_ops, THIS_MODULE); 177 &bq4802_ops, THIS_MODULE);
177 if (IS_ERR(p->rtc)) { 178 if (IS_ERR(p->rtc)) {
178 err = PTR_ERR(p->rtc); 179 err = PTR_ERR(p->rtc);
179 goto out_iounmap; 180 goto out;
180 } 181 }
181 182
182 err = 0; 183 err = 0;
183out: 184out:
184 return err; 185 return err;
185 186
186out_iounmap:
187 if (p->r->flags & IORESOURCE_MEM)
188 iounmap(p->regs);
189out_free:
190 kfree(p);
191 goto out;
192} 187}
193 188
194static int bq4802_remove(struct platform_device *pdev) 189static int bq4802_remove(struct platform_device *pdev)
195{ 190{
196 struct bq4802 *p = platform_get_drvdata(pdev);
197
198 rtc_device_unregister(p->rtc);
199 if (p->r->flags & IORESOURCE_MEM)
200 iounmap(p->regs);
201
202 platform_set_drvdata(pdev, NULL); 191 platform_set_drvdata(pdev, NULL);
203 192
204 kfree(p);
205
206 return 0; 193 return 0;
207} 194}
208 195
diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
index af97c94e8a3a..cc5bea9c4b1c 100644
--- a/drivers/rtc/rtc-cmos.c
+++ b/drivers/rtc/rtc-cmos.c
@@ -804,9 +804,8 @@ static int cmos_suspend(struct device *dev)
804 mask = RTC_IRQMASK; 804 mask = RTC_IRQMASK;
805 tmp &= ~mask; 805 tmp &= ~mask;
806 CMOS_WRITE(tmp, RTC_CONTROL); 806 CMOS_WRITE(tmp, RTC_CONTROL);
807 hpet_mask_rtc_irq_bit(mask);
807 808
808 /* shut down hpet emulation - we don't need it for alarm */
809 hpet_mask_rtc_irq_bit(RTC_PIE|RTC_AIE|RTC_UIE);
810 cmos_checkintr(cmos, tmp); 809 cmos_checkintr(cmos, tmp);
811 } 810 }
812 spin_unlock_irq(&rtc_lock); 811 spin_unlock_irq(&rtc_lock);
@@ -870,6 +869,7 @@ static int cmos_resume(struct device *dev)
870 rtc_update_irq(cmos->rtc, 1, mask); 869 rtc_update_irq(cmos->rtc, 1, mask);
871 tmp &= ~RTC_AIE; 870 tmp &= ~RTC_AIE;
872 hpet_mask_rtc_irq_bit(RTC_AIE); 871 hpet_mask_rtc_irq_bit(RTC_AIE);
872 hpet_rtc_timer_init();
873 } while (mask & RTC_AIE); 873 } while (mask & RTC_AIE);
874 spin_unlock_irq(&rtc_lock); 874 spin_unlock_irq(&rtc_lock);
875 } 875 }
diff --git a/drivers/rtc/rtc-coh901331.c b/drivers/rtc/rtc-coh901331.c
index 2d28ec1aa1cd..93c06588ddca 100644
--- a/drivers/rtc/rtc-coh901331.c
+++ b/drivers/rtc/rtc-coh901331.c
@@ -47,7 +47,7 @@ struct coh901331_port {
47 u32 physize; 47 u32 physize;
48 void __iomem *virtbase; 48 void __iomem *virtbase;
49 int irq; 49 int irq;
50#ifdef CONFIG_PM 50#ifdef CONFIG_PM_SLEEP
51 u32 irqmaskstore; 51 u32 irqmaskstore;
52#endif 52#endif
53}; 53};
@@ -155,7 +155,6 @@ static int __exit coh901331_remove(struct platform_device *pdev)
155 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 155 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev);
156 156
157 if (rtap) { 157 if (rtap) {
158 rtc_device_unregister(rtap->rtc);
159 clk_unprepare(rtap->clk); 158 clk_unprepare(rtap->clk);
160 platform_set_drvdata(pdev, NULL); 159 platform_set_drvdata(pdev, NULL);
161 } 160 }
@@ -211,8 +210,8 @@ static int __init coh901331_probe(struct platform_device *pdev)
211 clk_disable(rtap->clk); 210 clk_disable(rtap->clk);
212 211
213 platform_set_drvdata(pdev, rtap); 212 platform_set_drvdata(pdev, rtap);
214 rtap->rtc = rtc_device_register("coh901331", &pdev->dev, &coh901331_ops, 213 rtap->rtc = devm_rtc_device_register(&pdev->dev, "coh901331",
215 THIS_MODULE); 214 &coh901331_ops, THIS_MODULE);
216 if (IS_ERR(rtap->rtc)) { 215 if (IS_ERR(rtap->rtc)) {
217 ret = PTR_ERR(rtap->rtc); 216 ret = PTR_ERR(rtap->rtc);
218 goto out_no_rtc; 217 goto out_no_rtc;
@@ -226,17 +225,17 @@ static int __init coh901331_probe(struct platform_device *pdev)
226 return ret; 225 return ret;
227} 226}
228 227
229#ifdef CONFIG_PM 228#ifdef CONFIG_PM_SLEEP
230static int coh901331_suspend(struct platform_device *pdev, pm_message_t state) 229static int coh901331_suspend(struct device *dev)
231{ 230{
232 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 231 struct coh901331_port *rtap = dev_get_drvdata(dev);
233 232
234 /* 233 /*
235 * If this RTC alarm will be used for waking the system up, 234 * If this RTC alarm will be used for waking the system up,
236 * don't disable it of course. Else we just disable the alarm 235 * don't disable it of course. Else we just disable the alarm
237 * and await suspension. 236 * and await suspension.
238 */ 237 */
239 if (device_may_wakeup(&pdev->dev)) { 238 if (device_may_wakeup(dev)) {
240 enable_irq_wake(rtap->irq); 239 enable_irq_wake(rtap->irq);
241 } else { 240 } else {
242 clk_enable(rtap->clk); 241 clk_enable(rtap->clk);
@@ -248,12 +247,12 @@ static int coh901331_suspend(struct platform_device *pdev, pm_message_t state)
248 return 0; 247 return 0;
249} 248}
250 249
251static int coh901331_resume(struct platform_device *pdev) 250static int coh901331_resume(struct device *dev)
252{ 251{
253 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 252 struct coh901331_port *rtap = dev_get_drvdata(dev);
254 253
255 clk_prepare(rtap->clk); 254 clk_prepare(rtap->clk);
256 if (device_may_wakeup(&pdev->dev)) { 255 if (device_may_wakeup(dev)) {
257 disable_irq_wake(rtap->irq); 256 disable_irq_wake(rtap->irq);
258 } else { 257 } else {
259 clk_enable(rtap->clk); 258 clk_enable(rtap->clk);
@@ -262,11 +261,10 @@ static int coh901331_resume(struct platform_device *pdev)
262 } 261 }
263 return 0; 262 return 0;
264} 263}
265#else
266#define coh901331_suspend NULL
267#define coh901331_resume NULL
268#endif 264#endif
269 265
266static SIMPLE_DEV_PM_OPS(coh901331_pm_ops, coh901331_suspend, coh901331_resume);
267
270static void coh901331_shutdown(struct platform_device *pdev) 268static void coh901331_shutdown(struct platform_device *pdev)
271{ 269{
272 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev); 270 struct coh901331_port *rtap = dev_get_drvdata(&pdev->dev);
@@ -280,25 +278,13 @@ static struct platform_driver coh901331_driver = {
280 .driver = { 278 .driver = {
281 .name = "rtc-coh901331", 279 .name = "rtc-coh901331",
282 .owner = THIS_MODULE, 280 .owner = THIS_MODULE,
281 .pm = &coh901331_pm_ops,
283 }, 282 },
284 .remove = __exit_p(coh901331_remove), 283 .remove = __exit_p(coh901331_remove),
285 .suspend = coh901331_suspend,
286 .resume = coh901331_resume,
287 .shutdown = coh901331_shutdown, 284 .shutdown = coh901331_shutdown,
288}; 285};
289 286
290static int __init coh901331_init(void) 287module_platform_driver_probe(coh901331_driver, coh901331_probe);
291{
292 return platform_driver_probe(&coh901331_driver, coh901331_probe);
293}
294
295static void __exit coh901331_exit(void)
296{
297 platform_driver_unregister(&coh901331_driver);
298}
299
300module_init(coh901331_init);
301module_exit(coh901331_exit);
302 288
303MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>"); 289MODULE_AUTHOR("Linus Walleij <linus.walleij@stericsson.com>");
304MODULE_DESCRIPTION("ST-Ericsson AB COH 901 331 RTC Driver"); 290MODULE_DESCRIPTION("ST-Ericsson AB COH 901 331 RTC Driver");
diff --git a/drivers/rtc/rtc-da9052.c b/drivers/rtc/rtc-da9052.c
index 969abbad7fe3..7286b279cf2d 100644
--- a/drivers/rtc/rtc-da9052.c
+++ b/drivers/rtc/rtc-da9052.c
@@ -247,7 +247,7 @@ static int da9052_rtc_probe(struct platform_device *pdev)
247 return ret; 247 return ret;
248 } 248 }
249 249
250 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 250 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
251 &da9052_rtc_ops, THIS_MODULE); 251 &da9052_rtc_ops, THIS_MODULE);
252 if (IS_ERR(rtc->rtc)) 252 if (IS_ERR(rtc->rtc))
253 return PTR_ERR(rtc->rtc); 253 return PTR_ERR(rtc->rtc);
@@ -257,9 +257,6 @@ static int da9052_rtc_probe(struct platform_device *pdev)
257 257
258static int da9052_rtc_remove(struct platform_device *pdev) 258static int da9052_rtc_remove(struct platform_device *pdev)
259{ 259{
260 struct da9052_rtc *rtc = pdev->dev.platform_data;
261
262 rtc_device_unregister(rtc->rtc);
263 platform_set_drvdata(pdev, NULL); 260 platform_set_drvdata(pdev, NULL);
264 261
265 return 0; 262 return 0;
diff --git a/drivers/rtc/rtc-da9055.c b/drivers/rtc/rtc-da9055.c
index 8f0dcfedb83c..73858ca9709a 100644
--- a/drivers/rtc/rtc-da9055.c
+++ b/drivers/rtc/rtc-da9055.c
@@ -294,7 +294,7 @@ static int da9055_rtc_probe(struct platform_device *pdev)
294 294
295 device_init_wakeup(&pdev->dev, 1); 295 device_init_wakeup(&pdev->dev, 1);
296 296
297 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 297 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
298 &da9055_rtc_ops, THIS_MODULE); 298 &da9055_rtc_ops, THIS_MODULE);
299 if (IS_ERR(rtc->rtc)) { 299 if (IS_ERR(rtc->rtc)) {
300 ret = PTR_ERR(rtc->rtc); 300 ret = PTR_ERR(rtc->rtc);
@@ -317,9 +317,6 @@ err_rtc:
317 317
318static int da9055_rtc_remove(struct platform_device *pdev) 318static int da9055_rtc_remove(struct platform_device *pdev)
319{ 319{
320 struct da9055_rtc *rtc = pdev->dev.platform_data;
321
322 rtc_device_unregister(rtc->rtc);
323 platform_set_drvdata(pdev, NULL); 320 platform_set_drvdata(pdev, NULL);
324 321
325 return 0; 322 return 0;
diff --git a/drivers/rtc/rtc-davinci.c b/drivers/rtc/rtc-davinci.c
index 56b73089bb29..a55048c3e26f 100644
--- a/drivers/rtc/rtc-davinci.c
+++ b/drivers/rtc/rtc-davinci.c
@@ -523,7 +523,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
523 523
524 platform_set_drvdata(pdev, davinci_rtc); 524 platform_set_drvdata(pdev, davinci_rtc);
525 525
526 davinci_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 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); 529 ret = PTR_ERR(davinci_rtc->rtc);
@@ -543,7 +543,7 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
543 0, "davinci_rtc", davinci_rtc); 543 0, "davinci_rtc", davinci_rtc);
544 if (ret < 0) { 544 if (ret < 0) {
545 dev_err(dev, "unable to register davinci RTC interrupt\n"); 545 dev_err(dev, "unable to register davinci RTC interrupt\n");
546 goto fail2; 546 goto fail1;
547 } 547 }
548 548
549 /* Enable interrupts */ 549 /* Enable interrupts */
@@ -557,14 +557,12 @@ static int __init davinci_rtc_probe(struct platform_device *pdev)
557 557
558 return 0; 558 return 0;
559 559
560fail2:
561 rtc_device_unregister(davinci_rtc->rtc);
562fail1: 560fail1:
563 platform_set_drvdata(pdev, NULL); 561 platform_set_drvdata(pdev, NULL);
564 return ret; 562 return ret;
565} 563}
566 564
567static int davinci_rtc_remove(struct platform_device *pdev) 565static int __exit davinci_rtc_remove(struct platform_device *pdev)
568{ 566{
569 struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev); 567 struct davinci_rtc *davinci_rtc = platform_get_drvdata(pdev);
570 568
@@ -572,8 +570,6 @@ static int davinci_rtc_remove(struct platform_device *pdev)
572 570
573 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN); 571 rtcif_write(davinci_rtc, 0, PRTCIF_INTEN);
574 572
575 rtc_device_unregister(davinci_rtc->rtc);
576
577 platform_set_drvdata(pdev, NULL); 573 platform_set_drvdata(pdev, NULL);
578 574
579 return 0; 575 return 0;
@@ -581,24 +577,14 @@ static int davinci_rtc_remove(struct platform_device *pdev)
581 577
582static struct platform_driver davinci_rtc_driver = { 578static struct platform_driver davinci_rtc_driver = {
583 .probe = davinci_rtc_probe, 579 .probe = davinci_rtc_probe,
584 .remove = davinci_rtc_remove, 580 .remove = __exit_p(davinci_rtc_remove),
585 .driver = { 581 .driver = {
586 .name = "rtc_davinci", 582 .name = "rtc_davinci",
587 .owner = THIS_MODULE, 583 .owner = THIS_MODULE,
588 }, 584 },
589}; 585};
590 586
591static int __init rtc_init(void) 587module_platform_driver_probe(davinci_rtc_driver, davinci_rtc_probe);
592{
593 return platform_driver_probe(&davinci_rtc_driver, davinci_rtc_probe);
594}
595module_init(rtc_init);
596
597static void __exit rtc_exit(void)
598{
599 platform_driver_unregister(&davinci_rtc_driver);
600}
601module_exit(rtc_exit);
602 588
603MODULE_AUTHOR("Miguel Aguilar <miguel.aguilar@ridgerun.com>"); 589MODULE_AUTHOR("Miguel Aguilar <miguel.aguilar@ridgerun.com>");
604MODULE_DESCRIPTION("Texas Instruments DaVinci PRTC Driver"); 590MODULE_DESCRIPTION("Texas Instruments DaVinci PRTC Driver");
diff --git a/drivers/rtc/rtc-dm355evm.c b/drivers/rtc/rtc-dm355evm.c
index b2ed2c94b081..1e1ca63d58a9 100644
--- a/drivers/rtc/rtc-dm355evm.c
+++ b/drivers/rtc/rtc-dm355evm.c
@@ -127,8 +127,8 @@ static int dm355evm_rtc_probe(struct platform_device *pdev)
127{ 127{
128 struct rtc_device *rtc; 128 struct rtc_device *rtc;
129 129
130 rtc = rtc_device_register(pdev->name, 130 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
131 &pdev->dev, &dm355evm_rtc_ops, THIS_MODULE); 131 &dm355evm_rtc_ops, THIS_MODULE);
132 if (IS_ERR(rtc)) { 132 if (IS_ERR(rtc)) {
133 dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 133 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
134 PTR_ERR(rtc)); 134 PTR_ERR(rtc));
@@ -141,9 +141,6 @@ static int dm355evm_rtc_probe(struct platform_device *pdev)
141 141
142static int dm355evm_rtc_remove(struct platform_device *pdev) 142static int dm355evm_rtc_remove(struct platform_device *pdev)
143{ 143{
144 struct rtc_device *rtc = platform_get_drvdata(pdev);
145
146 rtc_device_unregister(rtc);
147 platform_set_drvdata(pdev, NULL); 144 platform_set_drvdata(pdev, NULL);
148 return 0; 145 return 0;
149} 146}
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c
index 45cd8c9f5a39..c7702b7269f7 100644
--- a/drivers/rtc/rtc-ds1216.c
+++ b/drivers/rtc/rtc-ds1216.c
@@ -30,8 +30,6 @@ struct ds1216_regs {
30struct ds1216_priv { 30struct ds1216_priv {
31 struct rtc_device *rtc; 31 struct rtc_device *rtc;
32 void __iomem *ioaddr; 32 void __iomem *ioaddr;
33 size_t size;
34 unsigned long baseaddr;
35}; 33};
36 34
37static const u8 magic[] = { 35static const u8 magic[] = {
@@ -144,57 +142,33 @@ static int __init ds1216_rtc_probe(struct platform_device *pdev)
144{ 142{
145 struct resource *res; 143 struct resource *res;
146 struct ds1216_priv *priv; 144 struct ds1216_priv *priv;
147 int ret = 0;
148 u8 dummy[8]; 145 u8 dummy[8];
149 146
150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 147 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!res) 148 if (!res)
152 return -ENODEV; 149 return -ENODEV;
153 priv = kzalloc(sizeof *priv, GFP_KERNEL); 150 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
154 if (!priv) 151 if (!priv)
155 return -ENOMEM; 152 return -ENOMEM;
156 153
157 platform_set_drvdata(pdev, priv); 154 platform_set_drvdata(pdev, priv);
158 155
159 priv->size = resource_size(res); 156 priv->ioaddr = devm_ioremap_resource(&pdev->dev, res);
160 if (!request_mem_region(res->start, priv->size, pdev->name)) { 157 if (IS_ERR(priv->ioaddr))
161 ret = -EBUSY; 158 return PTR_ERR(priv->ioaddr);
162 goto out; 159
163 } 160 priv->rtc = devm_rtc_device_register(&pdev->dev, "ds1216",
164 priv->baseaddr = res->start; 161 &ds1216_rtc_ops, THIS_MODULE);
165 priv->ioaddr = ioremap(priv->baseaddr, priv->size); 162 if (IS_ERR(priv->rtc))
166 if (!priv->ioaddr) { 163 return PTR_ERR(priv->rtc);
167 ret = -ENOMEM;
168 goto out;
169 }
170 priv->rtc = rtc_device_register("ds1216", &pdev->dev,
171 &ds1216_rtc_ops, THIS_MODULE);
172 if (IS_ERR(priv->rtc)) {
173 ret = PTR_ERR(priv->rtc);
174 goto out;
175 }
176 164
177 /* dummy read to get clock into a known state */ 165 /* dummy read to get clock into a known state */
178 ds1216_read(priv->ioaddr, dummy); 166 ds1216_read(priv->ioaddr, dummy);
179 return 0; 167 return 0;
180
181out:
182 if (priv->ioaddr)
183 iounmap(priv->ioaddr);
184 if (priv->baseaddr)
185 release_mem_region(priv->baseaddr, priv->size);
186 kfree(priv);
187 return ret;
188} 168}
189 169
190static int __exit ds1216_rtc_remove(struct platform_device *pdev) 170static int __exit ds1216_rtc_remove(struct platform_device *pdev)
191{ 171{
192 struct ds1216_priv *priv = platform_get_drvdata(pdev);
193
194 rtc_device_unregister(priv->rtc);
195 iounmap(priv->ioaddr);
196 release_mem_region(priv->baseaddr, priv->size);
197 kfree(priv);
198 return 0; 172 return 0;
199} 173}
200 174
diff --git a/drivers/rtc/rtc-ds1286.c b/drivers/rtc/rtc-ds1286.c
index d989412a348a..398c96a98fc4 100644
--- a/drivers/rtc/rtc-ds1286.c
+++ b/drivers/rtc/rtc-ds1286.c
@@ -25,8 +25,6 @@
25struct ds1286_priv { 25struct ds1286_priv {
26 struct rtc_device *rtc; 26 struct rtc_device *rtc;
27 u32 __iomem *rtcregs; 27 u32 __iomem *rtcregs;
28 size_t size;
29 unsigned long baseaddr;
30 spinlock_t lock; 28 spinlock_t lock;
31}; 29};
32 30
@@ -270,7 +268,6 @@ static int ds1286_set_time(struct device *dev, struct rtc_time *tm)
270static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm) 268static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
271{ 269{
272 struct ds1286_priv *priv = dev_get_drvdata(dev); 270 struct ds1286_priv *priv = dev_get_drvdata(dev);
273 unsigned char cmd;
274 unsigned long flags; 271 unsigned long flags;
275 272
276 /* 273 /*
@@ -281,7 +278,7 @@ static int ds1286_read_alarm(struct device *dev, struct rtc_wkalrm *alm)
281 alm->time.tm_min = ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x7f; 278 alm->time.tm_min = ds1286_rtc_read(priv, RTC_MINUTES_ALARM) & 0x7f;
282 alm->time.tm_hour = ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x1f; 279 alm->time.tm_hour = ds1286_rtc_read(priv, RTC_HOURS_ALARM) & 0x1f;
283 alm->time.tm_wday = ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x07; 280 alm->time.tm_wday = ds1286_rtc_read(priv, RTC_DAY_ALARM) & 0x07;
284 cmd = ds1286_rtc_read(priv, RTC_CMD); 281 ds1286_rtc_read(priv, RTC_CMD);
285 spin_unlock_irqrestore(&priv->lock, flags); 282 spin_unlock_irqrestore(&priv->lock, flags);
286 283
287 alm->time.tm_min = bcd2bin(alm->time.tm_min); 284 alm->time.tm_min = bcd2bin(alm->time.tm_min);
@@ -334,56 +331,30 @@ static int ds1286_probe(struct platform_device *pdev)
334 struct rtc_device *rtc; 331 struct rtc_device *rtc;
335 struct resource *res; 332 struct resource *res;
336 struct ds1286_priv *priv; 333 struct ds1286_priv *priv;
337 int ret = 0;
338 334
339 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 335 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
340 if (!res) 336 if (!res)
341 return -ENODEV; 337 return -ENODEV;
342 priv = kzalloc(sizeof(struct ds1286_priv), GFP_KERNEL); 338 priv = devm_kzalloc(&pdev->dev, sizeof(struct ds1286_priv), GFP_KERNEL);
343 if (!priv) 339 if (!priv)
344 return -ENOMEM; 340 return -ENOMEM;
345 341
346 priv->size = resource_size(res); 342 priv->rtcregs = devm_ioremap_resource(&pdev->dev, res);
347 if (!request_mem_region(res->start, priv->size, pdev->name)) { 343 if (IS_ERR(priv->rtcregs))
348 ret = -EBUSY; 344 return PTR_ERR(priv->rtcregs);
349 goto out; 345
350 }
351 priv->baseaddr = res->start;
352 priv->rtcregs = ioremap(priv->baseaddr, priv->size);
353 if (!priv->rtcregs) {
354 ret = -ENOMEM;
355 goto out;
356 }
357 spin_lock_init(&priv->lock); 346 spin_lock_init(&priv->lock);
358 platform_set_drvdata(pdev, priv); 347 platform_set_drvdata(pdev, priv);
359 rtc = rtc_device_register("ds1286", &pdev->dev, 348 rtc = devm_rtc_device_register(&pdev->dev, "ds1286", &ds1286_ops,
360 &ds1286_ops, THIS_MODULE); 349 THIS_MODULE);
361 if (IS_ERR(rtc)) { 350 if (IS_ERR(rtc))
362 ret = PTR_ERR(rtc); 351 return PTR_ERR(rtc);
363 goto out;
364 }
365 priv->rtc = rtc; 352 priv->rtc = rtc;
366 return 0; 353 return 0;
367
368out:
369 if (priv->rtc)
370 rtc_device_unregister(priv->rtc);
371 if (priv->rtcregs)
372 iounmap(priv->rtcregs);
373 if (priv->baseaddr)
374 release_mem_region(priv->baseaddr, priv->size);
375 kfree(priv);
376 return ret;
377} 354}
378 355
379static int ds1286_remove(struct platform_device *pdev) 356static int ds1286_remove(struct platform_device *pdev)
380{ 357{
381 struct ds1286_priv *priv = platform_get_drvdata(pdev);
382
383 rtc_device_unregister(priv->rtc);
384 iounmap(priv->rtcregs);
385 release_mem_region(priv->baseaddr, priv->size);
386 kfree(priv);
387 return 0; 358 return 0;
388} 359}
389 360
diff --git a/drivers/rtc/rtc-ds1302.c b/drivers/rtc/rtc-ds1302.c
index fdbcdb289d60..d13954346286 100644
--- a/drivers/rtc/rtc-ds1302.c
+++ b/drivers/rtc/rtc-ds1302.c
@@ -224,7 +224,7 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev)
224 return -ENODEV; 224 return -ENODEV;
225 } 225 }
226 226
227 rtc = rtc_device_register("ds1302", &pdev->dev, 227 rtc = devm_rtc_device_register(&pdev->dev, "ds1302",
228 &ds1302_rtc_ops, THIS_MODULE); 228 &ds1302_rtc_ops, THIS_MODULE);
229 if (IS_ERR(rtc)) 229 if (IS_ERR(rtc))
230 return PTR_ERR(rtc); 230 return PTR_ERR(rtc);
@@ -234,11 +234,8 @@ static int __init ds1302_rtc_probe(struct platform_device *pdev)
234 return 0; 234 return 0;
235} 235}
236 236
237static int ds1302_rtc_remove(struct platform_device *pdev) 237static int __exit ds1302_rtc_remove(struct platform_device *pdev)
238{ 238{
239 struct rtc_device *rtc = platform_get_drvdata(pdev);
240
241 rtc_device_unregister(rtc);
242 platform_set_drvdata(pdev, NULL); 239 platform_set_drvdata(pdev, NULL);
243 240
244 return 0; 241 return 0;
@@ -249,21 +246,10 @@ static struct platform_driver ds1302_platform_driver = {
249 .name = DRV_NAME, 246 .name = DRV_NAME,
250 .owner = THIS_MODULE, 247 .owner = THIS_MODULE,
251 }, 248 },
252 .remove = ds1302_rtc_remove, 249 .remove = __exit_p(ds1302_rtc_remove),
253}; 250};
254 251
255static int __init ds1302_rtc_init(void) 252module_platform_driver_probe(ds1302_platform_driver, ds1302_rtc_probe);
256{
257 return platform_driver_probe(&ds1302_platform_driver, ds1302_rtc_probe);
258}
259
260static void __exit ds1302_rtc_exit(void)
261{
262 platform_driver_unregister(&ds1302_platform_driver);
263}
264
265module_init(ds1302_rtc_init);
266module_exit(ds1302_rtc_exit);
267 253
268MODULE_DESCRIPTION("Dallas DS1302 RTC driver"); 254MODULE_DESCRIPTION("Dallas DS1302 RTC driver");
269MODULE_VERSION(DRV_VERSION); 255MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c
index b05a6dc96405..bb5f13f63630 100644
--- a/drivers/rtc/rtc-ds1305.c
+++ b/drivers/rtc/rtc-ds1305.c
@@ -619,7 +619,7 @@ static int ds1305_probe(struct spi_device *spi)
619 return -EINVAL; 619 return -EINVAL;
620 620
621 /* set up driver data */ 621 /* set up driver data */
622 ds1305 = kzalloc(sizeof *ds1305, GFP_KERNEL); 622 ds1305 = devm_kzalloc(&spi->dev, sizeof(*ds1305), GFP_KERNEL);
623 if (!ds1305) 623 if (!ds1305)
624 return -ENOMEM; 624 return -ENOMEM;
625 ds1305->spi = spi; 625 ds1305->spi = spi;
@@ -632,7 +632,7 @@ static int ds1305_probe(struct spi_device *spi)
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);
635 goto fail0; 635 return status;
636 } 636 }
637 637
638 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl); 638 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl);
@@ -644,8 +644,7 @@ static int ds1305_probe(struct spi_device *spi)
644 */ 644 */
645 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) { 645 if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) {
646 dev_dbg(&spi->dev, "RTC chip is not present\n"); 646 dev_dbg(&spi->dev, "RTC chip is not present\n");
647 status = -ENODEV; 647 return -ENODEV;
648 goto fail0;
649 } 648 }
650 if (ds1305->ctrl[2] == 0) 649 if (ds1305->ctrl[2] == 0)
651 dev_dbg(&spi->dev, "chip may not be present\n"); 650 dev_dbg(&spi->dev, "chip may not be present\n");
@@ -664,7 +663,7 @@ static int ds1305_probe(struct spi_device *spi)
664 663
665 dev_dbg(&spi->dev, "clear WP --> %d\n", status); 664 dev_dbg(&spi->dev, "clear WP --> %d\n", status);
666 if (status < 0) 665 if (status < 0)
667 goto fail0; 666 return status;
668 } 667 }
669 668
670 /* on DS1305, maybe start oscillator; like most low power 669 /* on DS1305, maybe start oscillator; like most low power
@@ -718,7 +717,7 @@ static int ds1305_probe(struct spi_device *spi)
718 if (status < 0) { 717 if (status < 0) {
719 dev_dbg(&spi->dev, "can't %s, %d\n", 718 dev_dbg(&spi->dev, "can't %s, %d\n",
720 "write", status); 719 "write", status);
721 goto fail0; 720 return status;
722 } 721 }
723 722
724 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl); 723 dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl);
@@ -730,7 +729,7 @@ static int ds1305_probe(struct spi_device *spi)
730 &value, sizeof value); 729 &value, sizeof value);
731 if (status < 0) { 730 if (status < 0) {
732 dev_dbg(&spi->dev, "read HOUR --> %d\n", status); 731 dev_dbg(&spi->dev, "read HOUR --> %d\n", status);
733 goto fail0; 732 return status;
734 } 733 }
735 734
736 ds1305->hr12 = (DS1305_HR_12 & value) != 0; 735 ds1305->hr12 = (DS1305_HR_12 & value) != 0;
@@ -738,12 +737,12 @@ static int ds1305_probe(struct spi_device *spi)
738 dev_dbg(&spi->dev, "AM/PM\n"); 737 dev_dbg(&spi->dev, "AM/PM\n");
739 738
740 /* register RTC ... from here on, ds1305->ctrl needs locking */ 739 /* register RTC ... from here on, ds1305->ctrl needs locking */
741 ds1305->rtc = rtc_device_register("ds1305", &spi->dev, 740 ds1305->rtc = devm_rtc_device_register(&spi->dev, "ds1305",
742 &ds1305_ops, THIS_MODULE); 741 &ds1305_ops, THIS_MODULE);
743 if (IS_ERR(ds1305->rtc)) { 742 if (IS_ERR(ds1305->rtc)) {
744 status = PTR_ERR(ds1305->rtc); 743 status = PTR_ERR(ds1305->rtc);
745 dev_dbg(&spi->dev, "register rtc --> %d\n", status); 744 dev_dbg(&spi->dev, "register rtc --> %d\n", status);
746 goto fail0; 745 return status;
747 } 746 }
748 747
749 /* Maybe set up alarm IRQ; be ready to handle it triggering right 748 /* Maybe set up alarm IRQ; be ready to handle it triggering right
@@ -754,12 +753,12 @@ static int ds1305_probe(struct spi_device *spi)
754 */ 753 */
755 if (spi->irq) { 754 if (spi->irq) {
756 INIT_WORK(&ds1305->work, ds1305_work); 755 INIT_WORK(&ds1305->work, ds1305_work);
757 status = request_irq(spi->irq, ds1305_irq, 756 status = devm_request_irq(&spi->dev, spi->irq, ds1305_irq,
758 0, dev_name(&ds1305->rtc->dev), ds1305); 757 0, dev_name(&ds1305->rtc->dev), ds1305);
759 if (status < 0) { 758 if (status < 0) {
760 dev_dbg(&spi->dev, "request_irq %d --> %d\n", 759 dev_dbg(&spi->dev, "request_irq %d --> %d\n",
761 spi->irq, status); 760 spi->irq, status);
762 goto fail1; 761 return status;
763 } 762 }
764 763
765 device_set_wakeup_capable(&spi->dev, 1); 764 device_set_wakeup_capable(&spi->dev, 1);
@@ -769,18 +768,10 @@ static int ds1305_probe(struct spi_device *spi)
769 status = sysfs_create_bin_file(&spi->dev.kobj, &nvram); 768 status = sysfs_create_bin_file(&spi->dev.kobj, &nvram);
770 if (status < 0) { 769 if (status < 0) {
771 dev_dbg(&spi->dev, "register nvram --> %d\n", status); 770 dev_dbg(&spi->dev, "register nvram --> %d\n", status);
772 goto fail2; 771 return status;
773 } 772 }
774 773
775 return 0; 774 return 0;
776
777fail2:
778 free_irq(spi->irq, ds1305);
779fail1:
780 rtc_device_unregister(ds1305->rtc);
781fail0:
782 kfree(ds1305);
783 return status;
784} 775}
785 776
786static int ds1305_remove(struct spi_device *spi) 777static int ds1305_remove(struct spi_device *spi)
@@ -792,13 +783,11 @@ static int ds1305_remove(struct spi_device *spi)
792 /* carefully shut down irq and workqueue, if present */ 783 /* carefully shut down irq and workqueue, if present */
793 if (spi->irq) { 784 if (spi->irq) {
794 set_bit(FLAG_EXITING, &ds1305->flags); 785 set_bit(FLAG_EXITING, &ds1305->flags);
795 free_irq(spi->irq, ds1305); 786 devm_free_irq(&spi->dev, spi->irq, ds1305);
796 cancel_work_sync(&ds1305->work); 787 cancel_work_sync(&ds1305->work);
797 } 788 }
798 789
799 rtc_device_unregister(ds1305->rtc);
800 spi_set_drvdata(spi, NULL); 790 spi_set_drvdata(spi, NULL);
801 kfree(ds1305);
802 return 0; 791 return 0;
803} 792}
804 793
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
index 970a236b147a..b53992ab3090 100644
--- a/drivers/rtc/rtc-ds1307.c
+++ b/drivers/rtc/rtc-ds1307.c
@@ -4,6 +4,7 @@
4 * Copyright (C) 2005 James Chapman (ds1337 core) 4 * Copyright (C) 2005 James Chapman (ds1337 core)
5 * Copyright (C) 2006 David Brownell 5 * Copyright (C) 2006 David Brownell
6 * Copyright (C) 2009 Matthias Fuchs (rx8025 support) 6 * Copyright (C) 2009 Matthias Fuchs (rx8025 support)
7 * Copyright (C) 2012 Bertrand Achard (nvram access fixes)
7 * 8 *
8 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as 10 * it under the terms of the GNU General Public License version 2 as
@@ -196,7 +197,7 @@ static s32 ds1307_read_block_data_once(const struct i2c_client *client,
196static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command, 197static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command,
197 u8 length, u8 *values) 198 u8 length, u8 *values)
198{ 199{
199 u8 oldvalues[I2C_SMBUS_BLOCK_MAX]; 200 u8 oldvalues[255];
200 s32 ret; 201 s32 ret;
201 int tries = 0; 202 int tries = 0;
202 203
@@ -222,7 +223,7 @@ static s32 ds1307_read_block_data(const struct i2c_client *client, u8 command,
222static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command, 223static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command,
223 u8 length, const u8 *values) 224 u8 length, const u8 *values)
224{ 225{
225 u8 currvalues[I2C_SMBUS_BLOCK_MAX]; 226 u8 currvalues[255];
226 int tries = 0; 227 int tries = 0;
227 228
228 dev_dbg(&client->dev, "ds1307_write_block_data (length=%d)\n", length); 229 dev_dbg(&client->dev, "ds1307_write_block_data (length=%d)\n", length);
@@ -250,6 +251,57 @@ static s32 ds1307_write_block_data(const struct i2c_client *client, u8 command,
250 251
251/*----------------------------------------------------------------------*/ 252/*----------------------------------------------------------------------*/
252 253
254/* These RTC devices are not designed to be connected to a SMbus adapter.
255 SMbus limits block operations length to 32 bytes, whereas it's not
256 limited on I2C buses. As a result, accesses may exceed 32 bytes;
257 in that case, split them into smaller blocks */
258
259static s32 ds1307_native_smbus_write_block_data(const struct i2c_client *client,
260 u8 command, u8 length, const u8 *values)
261{
262 u8 suboffset = 0;
263
264 if (length <= I2C_SMBUS_BLOCK_MAX)
265 return i2c_smbus_write_i2c_block_data(client,
266 command, length, values);
267
268 while (suboffset < length) {
269 s32 retval = i2c_smbus_write_i2c_block_data(client,
270 command + suboffset,
271 min(I2C_SMBUS_BLOCK_MAX, length - suboffset),
272 values + suboffset);
273 if (retval < 0)
274 return retval;
275
276 suboffset += I2C_SMBUS_BLOCK_MAX;
277 }
278 return length;
279}
280
281static s32 ds1307_native_smbus_read_block_data(const struct i2c_client *client,
282 u8 command, u8 length, u8 *values)
283{
284 u8 suboffset = 0;
285
286 if (length <= I2C_SMBUS_BLOCK_MAX)
287 return i2c_smbus_read_i2c_block_data(client,
288 command, length, values);
289
290 while (suboffset < length) {
291 s32 retval = i2c_smbus_read_i2c_block_data(client,
292 command + suboffset,
293 min(I2C_SMBUS_BLOCK_MAX, length - suboffset),
294 values + suboffset);
295 if (retval < 0)
296 return retval;
297
298 suboffset += I2C_SMBUS_BLOCK_MAX;
299 }
300 return length;
301}
302
303/*----------------------------------------------------------------------*/
304
253/* 305/*
254 * The IRQ logic includes a "real" handler running in IRQ context just 306 * The IRQ logic includes a "real" handler running in IRQ context just
255 * long enough to schedule this workqueue entry. We need a task context 307 * long enough to schedule this workqueue entry. We need a task context
@@ -646,8 +698,8 @@ static int ds1307_probe(struct i2c_client *client,
646 698
647 buf = ds1307->regs; 699 buf = ds1307->regs;
648 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) { 700 if (i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) {
649 ds1307->read_block_data = i2c_smbus_read_i2c_block_data; 701 ds1307->read_block_data = ds1307_native_smbus_read_block_data;
650 ds1307->write_block_data = i2c_smbus_write_i2c_block_data; 702 ds1307->write_block_data = ds1307_native_smbus_write_block_data;
651 } else { 703 } else {
652 ds1307->read_block_data = ds1307_read_block_data; 704 ds1307->read_block_data = ds1307_read_block_data;
653 ds1307->write_block_data = ds1307_write_block_data; 705 ds1307->write_block_data = ds1307_write_block_data;
@@ -661,7 +713,7 @@ static int ds1307_probe(struct i2c_client *client,
661 tmp = ds1307->read_block_data(ds1307->client, 713 tmp = ds1307->read_block_data(ds1307->client,
662 DS1337_REG_CONTROL, 2, buf); 714 DS1337_REG_CONTROL, 2, buf);
663 if (tmp != 2) { 715 if (tmp != 2) {
664 pr_debug("read error %d\n", tmp); 716 dev_dbg(&client->dev, "read error %d\n", tmp);
665 err = -EIO; 717 err = -EIO;
666 goto exit_free; 718 goto exit_free;
667 } 719 }
@@ -700,7 +752,7 @@ static int ds1307_probe(struct i2c_client *client,
700 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, 752 tmp = i2c_smbus_read_i2c_block_data(ds1307->client,
701 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); 753 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf);
702 if (tmp != 2) { 754 if (tmp != 2) {
703 pr_debug("read error %d\n", tmp); 755 dev_dbg(&client->dev, "read error %d\n", tmp);
704 err = -EIO; 756 err = -EIO;
705 goto exit_free; 757 goto exit_free;
706 } 758 }
@@ -744,7 +796,7 @@ static int ds1307_probe(struct i2c_client *client,
744 tmp = i2c_smbus_read_i2c_block_data(ds1307->client, 796 tmp = i2c_smbus_read_i2c_block_data(ds1307->client,
745 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf); 797 RX8025_REG_CTRL1 << 4 | 0x08, 2, buf);
746 if (tmp != 2) { 798 if (tmp != 2) {
747 pr_debug("read error %d\n", tmp); 799 dev_dbg(&client->dev, "read error %d\n", tmp);
748 err = -EIO; 800 err = -EIO;
749 goto exit_free; 801 goto exit_free;
750 } 802 }
@@ -772,7 +824,7 @@ read_rtc:
772 /* read RTC registers */ 824 /* read RTC registers */
773 tmp = ds1307->read_block_data(ds1307->client, ds1307->offset, 8, buf); 825 tmp = ds1307->read_block_data(ds1307->client, ds1307->offset, 8, buf);
774 if (tmp != 8) { 826 if (tmp != 8) {
775 pr_debug("read error %d\n", tmp); 827 dev_dbg(&client->dev, "read error %d\n", tmp);
776 err = -EIO; 828 err = -EIO;
777 goto exit_free; 829 goto exit_free;
778 } 830 }
@@ -814,7 +866,7 @@ read_rtc:
814 866
815 tmp = i2c_smbus_read_byte_data(client, DS1340_REG_FLAG); 867 tmp = i2c_smbus_read_byte_data(client, DS1340_REG_FLAG);
816 if (tmp < 0) { 868 if (tmp < 0) {
817 pr_debug("read error %d\n", tmp); 869 dev_dbg(&client->dev, "read error %d\n", tmp);
818 err = -EIO; 870 err = -EIO;
819 goto exit_free; 871 goto exit_free;
820 } 872 }
@@ -908,8 +960,8 @@ read_rtc:
908 ds1307->nvram->attr.name = "nvram"; 960 ds1307->nvram->attr.name = "nvram";
909 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; 961 ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR;
910 sysfs_bin_attr_init(ds1307->nvram); 962 sysfs_bin_attr_init(ds1307->nvram);
911 ds1307->nvram->read = ds1307_nvram_read, 963 ds1307->nvram->read = ds1307_nvram_read;
912 ds1307->nvram->write = ds1307_nvram_write, 964 ds1307->nvram->write = ds1307_nvram_write;
913 ds1307->nvram->size = chip->nvram_size; 965 ds1307->nvram->size = chip->nvram_size;
914 ds1307->nvram_offset = chip->nvram_offset; 966 ds1307->nvram_offset = chip->nvram_offset;
915 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram); 967 err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram);
diff --git a/drivers/rtc/rtc-ds1374.c b/drivers/rtc/rtc-ds1374.c
index fef76868aae0..94366e12f40f 100644
--- a/drivers/rtc/rtc-ds1374.c
+++ b/drivers/rtc/rtc-ds1374.c
@@ -347,7 +347,7 @@ static int ds1374_probe(struct i2c_client *client,
347 struct ds1374 *ds1374; 347 struct ds1374 *ds1374;
348 int ret; 348 int ret;
349 349
350 ds1374 = kzalloc(sizeof(struct ds1374), GFP_KERNEL); 350 ds1374 = devm_kzalloc(&client->dev, sizeof(struct ds1374), GFP_KERNEL);
351 if (!ds1374) 351 if (!ds1374)
352 return -ENOMEM; 352 return -ENOMEM;
353 353
@@ -359,36 +359,27 @@ static int ds1374_probe(struct i2c_client *client,
359 359
360 ret = ds1374_check_rtc_status(client); 360 ret = ds1374_check_rtc_status(client);
361 if (ret) 361 if (ret)
362 goto out_free; 362 return ret;
363 363
364 if (client->irq > 0) { 364 if (client->irq > 0) {
365 ret = request_irq(client->irq, ds1374_irq, 0, 365 ret = devm_request_irq(&client->dev, client->irq, ds1374_irq, 0,
366 "ds1374", client); 366 "ds1374", client);
367 if (ret) { 367 if (ret) {
368 dev_err(&client->dev, "unable to request IRQ\n"); 368 dev_err(&client->dev, "unable to request IRQ\n");
369 goto out_free; 369 return ret;
370 } 370 }
371 371
372 device_set_wakeup_capable(&client->dev, 1); 372 device_set_wakeup_capable(&client->dev, 1);
373 } 373 }
374 374
375 ds1374->rtc = rtc_device_register(client->name, &client->dev, 375 ds1374->rtc = devm_rtc_device_register(&client->dev, client->name,
376 &ds1374_rtc_ops, THIS_MODULE); 376 &ds1374_rtc_ops, THIS_MODULE);
377 if (IS_ERR(ds1374->rtc)) { 377 if (IS_ERR(ds1374->rtc)) {
378 ret = PTR_ERR(ds1374->rtc);
379 dev_err(&client->dev, "unable to register the class device\n"); 378 dev_err(&client->dev, "unable to register the class device\n");
380 goto out_irq; 379 return PTR_ERR(ds1374->rtc);
381 } 380 }
382 381
383 return 0; 382 return 0;
384
385out_irq:
386 if (client->irq > 0)
387 free_irq(client->irq, client);
388
389out_free:
390 kfree(ds1374);
391 return ret;
392} 383}
393 384
394static int ds1374_remove(struct i2c_client *client) 385static int ds1374_remove(struct i2c_client *client)
@@ -400,16 +391,14 @@ static int ds1374_remove(struct i2c_client *client)
400 ds1374->exiting = 1; 391 ds1374->exiting = 1;
401 mutex_unlock(&ds1374->mutex); 392 mutex_unlock(&ds1374->mutex);
402 393
403 free_irq(client->irq, client); 394 devm_free_irq(&client->dev, client->irq, client);
404 cancel_work_sync(&ds1374->work); 395 cancel_work_sync(&ds1374->work);
405 } 396 }
406 397
407 rtc_device_unregister(ds1374->rtc);
408 kfree(ds1374);
409 return 0; 398 return 0;
410} 399}
411 400
412#ifdef CONFIG_PM 401#ifdef CONFIG_PM_SLEEP
413static int ds1374_suspend(struct device *dev) 402static int ds1374_suspend(struct device *dev)
414{ 403{
415 struct i2c_client *client = to_i2c_client(dev); 404 struct i2c_client *client = to_i2c_client(dev);
@@ -427,19 +416,15 @@ static int ds1374_resume(struct device *dev)
427 disable_irq_wake(client->irq); 416 disable_irq_wake(client->irq);
428 return 0; 417 return 0;
429} 418}
419#endif
430 420
431static SIMPLE_DEV_PM_OPS(ds1374_pm, ds1374_suspend, ds1374_resume); 421static SIMPLE_DEV_PM_OPS(ds1374_pm, ds1374_suspend, ds1374_resume);
432 422
433#define DS1374_PM (&ds1374_pm)
434#else
435#define DS1374_PM NULL
436#endif
437
438static struct i2c_driver ds1374_driver = { 423static struct i2c_driver ds1374_driver = {
439 .driver = { 424 .driver = {
440 .name = "rtc-ds1374", 425 .name = "rtc-ds1374",
441 .owner = THIS_MODULE, 426 .owner = THIS_MODULE,
442 .pm = DS1374_PM, 427 .pm = &ds1374_pm,
443 }, 428 },
444 .probe = ds1374_probe, 429 .probe = ds1374_probe,
445 .remove = ds1374_remove, 430 .remove = ds1374_remove,
diff --git a/drivers/rtc/rtc-ds1390.c b/drivers/rtc/rtc-ds1390.c
index f994257981a0..289af419dff4 100644
--- a/drivers/rtc/rtc-ds1390.c
+++ b/drivers/rtc/rtc-ds1390.c
@@ -131,26 +131,24 @@ static int ds1390_probe(struct spi_device *spi)
131 spi->bits_per_word = 8; 131 spi->bits_per_word = 8;
132 spi_setup(spi); 132 spi_setup(spi);
133 133
134 chip = kzalloc(sizeof *chip, GFP_KERNEL); 134 chip = devm_kzalloc(&spi->dev, sizeof(*chip), GFP_KERNEL);
135 if (!chip) { 135 if (!chip) {
136 dev_err(&spi->dev, "unable to allocate device memory\n"); 136 dev_err(&spi->dev, "unable to allocate device memory\n");
137 return -ENOMEM; 137 return -ENOMEM;
138 } 138 }
139 dev_set_drvdata(&spi->dev, chip); 139 spi_set_drvdata(spi, chip);
140 140
141 res = ds1390_get_reg(&spi->dev, DS1390_REG_SECONDS, &tmp); 141 res = ds1390_get_reg(&spi->dev, DS1390_REG_SECONDS, &tmp);
142 if (res != 0) { 142 if (res != 0) {
143 dev_err(&spi->dev, "unable to read device\n"); 143 dev_err(&spi->dev, "unable to read device\n");
144 kfree(chip);
145 return res; 144 return res;
146 } 145 }
147 146
148 chip->rtc = rtc_device_register("ds1390", 147 chip->rtc = devm_rtc_device_register(&spi->dev, "ds1390",
149 &spi->dev, &ds1390_rtc_ops, THIS_MODULE); 148 &ds1390_rtc_ops, THIS_MODULE);
150 if (IS_ERR(chip->rtc)) { 149 if (IS_ERR(chip->rtc)) {
151 dev_err(&spi->dev, "unable to register device\n"); 150 dev_err(&spi->dev, "unable to register device\n");
152 res = PTR_ERR(chip->rtc); 151 res = PTR_ERR(chip->rtc);
153 kfree(chip);
154 } 152 }
155 153
156 return res; 154 return res;
@@ -158,11 +156,6 @@ static int ds1390_probe(struct spi_device *spi)
158 156
159static int ds1390_remove(struct spi_device *spi) 157static int ds1390_remove(struct spi_device *spi)
160{ 158{
161 struct ds1390 *chip = spi_get_drvdata(spi);
162
163 rtc_device_unregister(chip->rtc);
164 kfree(chip);
165
166 return 0; 159 return 0;
167} 160}
168 161
diff --git a/drivers/rtc/rtc-ds1511.c b/drivers/rtc/rtc-ds1511.c
index 6a3fcfe3b0e7..6ce8a997cf51 100644
--- a/drivers/rtc/rtc-ds1511.c
+++ b/drivers/rtc/rtc-ds1511.c
@@ -538,15 +538,14 @@ static int ds1511_rtc_probe(struct platform_device *pdev)
538 } 538 }
539 } 539 }
540 540
541 rtc = rtc_device_register(pdev->name, &pdev->dev, &ds1511_rtc_ops, 541 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &ds1511_rtc_ops,
542 THIS_MODULE); 542 THIS_MODULE);
543 if (IS_ERR(rtc)) 543 if (IS_ERR(rtc))
544 return PTR_ERR(rtc); 544 return PTR_ERR(rtc);
545 pdata->rtc = rtc; 545 pdata->rtc = rtc;
546 546
547 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 547 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
548 if (ret) 548
549 rtc_device_unregister(pdata->rtc);
550 return ret; 549 return ret;
551} 550}
552 551
@@ -555,7 +554,6 @@ static int ds1511_rtc_remove(struct platform_device *pdev)
555 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 554 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
556 555
557 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr); 556 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1511_nvram_attr);
558 rtc_device_unregister(pdata->rtc);
559 if (pdata->irq > 0) { 557 if (pdata->irq > 0) {
560 /* 558 /*
561 * disable the alarm interrupt 559 * disable the alarm interrupt
diff --git a/drivers/rtc/rtc-ds1553.c b/drivers/rtc/rtc-ds1553.c
index 25ce0621ade9..8c6c952e90b1 100644
--- a/drivers/rtc/rtc-ds1553.c
+++ b/drivers/rtc/rtc-ds1553.c
@@ -326,15 +326,14 @@ static int ds1553_rtc_probe(struct platform_device *pdev)
326 } 326 }
327 } 327 }
328 328
329 rtc = rtc_device_register(pdev->name, &pdev->dev, 329 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
330 &ds1553_rtc_ops, THIS_MODULE); 330 &ds1553_rtc_ops, THIS_MODULE);
331 if (IS_ERR(rtc)) 331 if (IS_ERR(rtc))
332 return PTR_ERR(rtc); 332 return PTR_ERR(rtc);
333 pdata->rtc = rtc; 333 pdata->rtc = rtc;
334 334
335 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 335 ret = sysfs_create_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
336 if (ret) 336
337 rtc_device_unregister(rtc);
338 return ret; 337 return ret;
339} 338}
340 339
@@ -343,7 +342,6 @@ static int ds1553_rtc_remove(struct platform_device *pdev)
343 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 342 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
344 343
345 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr); 344 sysfs_remove_bin_file(&pdev->dev.kobj, &ds1553_nvram_attr);
346 rtc_device_unregister(pdata->rtc);
347 if (pdata->irq > 0) 345 if (pdata->irq > 0)
348 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 346 writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
349 return 0; 347 return 0;
diff --git a/drivers/rtc/rtc-ds1672.c b/drivers/rtc/rtc-ds1672.c
index 45d65c0b3a85..3fc2a4738027 100644
--- a/drivers/rtc/rtc-ds1672.c
+++ b/drivers/rtc/rtc-ds1672.c
@@ -155,11 +155,6 @@ static const struct rtc_class_ops ds1672_rtc_ops = {
155 155
156static int ds1672_remove(struct i2c_client *client) 156static int ds1672_remove(struct i2c_client *client)
157{ 157{
158 struct rtc_device *rtc = i2c_get_clientdata(client);
159
160 if (rtc)
161 rtc_device_unregister(rtc);
162
163 return 0; 158 return 0;
164} 159}
165 160
@@ -177,7 +172,7 @@ static int ds1672_probe(struct i2c_client *client,
177 172
178 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 173 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
179 174
180 rtc = rtc_device_register(ds1672_driver.driver.name, &client->dev, 175 rtc = devm_rtc_device_register(&client->dev, ds1672_driver.driver.name,
181 &ds1672_rtc_ops, THIS_MODULE); 176 &ds1672_rtc_ops, THIS_MODULE);
182 177
183 if (IS_ERR(rtc)) 178 if (IS_ERR(rtc))
@@ -202,7 +197,6 @@ static int ds1672_probe(struct i2c_client *client,
202 return 0; 197 return 0;
203 198
204 exit_devreg: 199 exit_devreg:
205 rtc_device_unregister(rtc);
206 return err; 200 return err;
207} 201}
208 202
diff --git a/drivers/rtc/rtc-ds1742.c b/drivers/rtc/rtc-ds1742.c
index 609c870e2cc5..eccdc62ae1c0 100644
--- a/drivers/rtc/rtc-ds1742.c
+++ b/drivers/rtc/rtc-ds1742.c
@@ -208,17 +208,14 @@ static int ds1742_rtc_probe(struct platform_device *pdev)
208 208
209 pdata->last_jiffies = jiffies; 209 pdata->last_jiffies = jiffies;
210 platform_set_drvdata(pdev, pdata); 210 platform_set_drvdata(pdev, pdata);
211 rtc = rtc_device_register(pdev->name, &pdev->dev, 211 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
212 &ds1742_rtc_ops, THIS_MODULE); 212 &ds1742_rtc_ops, THIS_MODULE);
213 if (IS_ERR(rtc)) 213 if (IS_ERR(rtc))
214 return PTR_ERR(rtc); 214 return PTR_ERR(rtc);
215 pdata->rtc = rtc; 215 pdata->rtc = rtc;
216 216
217 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 217 ret = sysfs_create_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
218 if (ret) { 218
219 dev_err(&pdev->dev, "creating nvram file in sysfs failed\n");
220 rtc_device_unregister(rtc);
221 }
222 return ret; 219 return ret;
223} 220}
224 221
@@ -227,7 +224,6 @@ static int ds1742_rtc_remove(struct platform_device *pdev)
227 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 224 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
228 225
229 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr); 226 sysfs_remove_bin_file(&pdev->dev.kobj, &pdata->nvram_attr);
230 rtc_device_unregister(pdata->rtc);
231 return 0; 227 return 0;
232} 228}
233 229
diff --git a/drivers/rtc/rtc-ds2404.c b/drivers/rtc/rtc-ds2404.c
index b04fc4272fb3..2ca5a23aba8a 100644
--- a/drivers/rtc/rtc-ds2404.c
+++ b/drivers/rtc/rtc-ds2404.c
@@ -228,7 +228,7 @@ static int rtc_probe(struct platform_device *pdev)
228 struct ds2404 *chip; 228 struct ds2404 *chip;
229 int retval = -EBUSY; 229 int retval = -EBUSY;
230 230
231 chip = kzalloc(sizeof(struct ds2404), GFP_KERNEL); 231 chip = devm_kzalloc(&pdev->dev, sizeof(struct ds2404), GFP_KERNEL);
232 if (!chip) 232 if (!chip)
233 return -ENOMEM; 233 return -ENOMEM;
234 234
@@ -244,8 +244,8 @@ static int rtc_probe(struct platform_device *pdev)
244 244
245 platform_set_drvdata(pdev, chip); 245 platform_set_drvdata(pdev, chip);
246 246
247 chip->rtc = rtc_device_register("ds2404", 247 chip->rtc = devm_rtc_device_register(&pdev->dev, "ds2404",
248 &pdev->dev, &ds2404_rtc_ops, THIS_MODULE); 248 &ds2404_rtc_ops, THIS_MODULE);
249 if (IS_ERR(chip->rtc)) { 249 if (IS_ERR(chip->rtc)) {
250 retval = PTR_ERR(chip->rtc); 250 retval = PTR_ERR(chip->rtc);
251 goto err_io; 251 goto err_io;
@@ -257,20 +257,14 @@ static int rtc_probe(struct platform_device *pdev)
257err_io: 257err_io:
258 chip->ops->unmap_io(chip); 258 chip->ops->unmap_io(chip);
259err_chip: 259err_chip:
260 kfree(chip);
261 return retval; 260 return retval;
262} 261}
263 262
264static int rtc_remove(struct platform_device *dev) 263static int rtc_remove(struct platform_device *dev)
265{ 264{
266 struct ds2404 *chip = platform_get_drvdata(dev); 265 struct ds2404 *chip = platform_get_drvdata(dev);
267 struct rtc_device *rtc = chip->rtc;
268
269 if (rtc)
270 rtc_device_unregister(rtc);
271 266
272 chip->ops->unmap_io(chip); 267 chip->ops->unmap_io(chip);
273 kfree(chip);
274 268
275 return 0; 269 return 0;
276} 270}
diff --git a/drivers/rtc/rtc-ds3232.c b/drivers/rtc/rtc-ds3232.c
index db0ca08db315..b83bb5a527f8 100644
--- a/drivers/rtc/rtc-ds3232.c
+++ b/drivers/rtc/rtc-ds3232.c
@@ -397,7 +397,7 @@ static int ds3232_probe(struct i2c_client *client,
397 struct ds3232 *ds3232; 397 struct ds3232 *ds3232;
398 int ret; 398 int ret;
399 399
400 ds3232 = kzalloc(sizeof(struct ds3232), GFP_KERNEL); 400 ds3232 = devm_kzalloc(&client->dev, sizeof(struct ds3232), GFP_KERNEL);
401 if (!ds3232) 401 if (!ds3232)
402 return -ENOMEM; 402 return -ENOMEM;
403 403
@@ -409,34 +409,25 @@ static int ds3232_probe(struct i2c_client *client,
409 409
410 ret = ds3232_check_rtc_status(client); 410 ret = ds3232_check_rtc_status(client);
411 if (ret) 411 if (ret)
412 goto out_free; 412 return ret;
413 413
414 ds3232->rtc = rtc_device_register(client->name, &client->dev, 414 ds3232->rtc = devm_rtc_device_register(&client->dev, client->name,
415 &ds3232_rtc_ops, THIS_MODULE); 415 &ds3232_rtc_ops, THIS_MODULE);
416 if (IS_ERR(ds3232->rtc)) { 416 if (IS_ERR(ds3232->rtc)) {
417 ret = PTR_ERR(ds3232->rtc);
418 dev_err(&client->dev, "unable to register the class device\n"); 417 dev_err(&client->dev, "unable to register the class device\n");
419 goto out_irq; 418 return PTR_ERR(ds3232->rtc);
420 } 419 }
421 420
422 if (client->irq >= 0) { 421 if (client->irq >= 0) {
423 ret = request_irq(client->irq, ds3232_irq, 0, 422 ret = devm_request_irq(&client->dev, client->irq, ds3232_irq, 0,
424 "ds3232", client); 423 "ds3232", client);
425 if (ret) { 424 if (ret) {
426 dev_err(&client->dev, "unable to request IRQ\n"); 425 dev_err(&client->dev, "unable to request IRQ\n");
427 goto out_free; 426 return ret;
428 } 427 }
429 } 428 }
430 429
431 return 0; 430 return 0;
432
433out_irq:
434 if (client->irq >= 0)
435 free_irq(client->irq, client);
436
437out_free:
438 kfree(ds3232);
439 return ret;
440} 431}
441 432
442static int ds3232_remove(struct i2c_client *client) 433static int ds3232_remove(struct i2c_client *client)
@@ -448,12 +439,10 @@ static int ds3232_remove(struct i2c_client *client)
448 ds3232->exiting = 1; 439 ds3232->exiting = 1;
449 mutex_unlock(&ds3232->mutex); 440 mutex_unlock(&ds3232->mutex);
450 441
451 free_irq(client->irq, client); 442 devm_free_irq(&client->dev, client->irq, client);
452 cancel_work_sync(&ds3232->work); 443 cancel_work_sync(&ds3232->work);
453 } 444 }
454 445
455 rtc_device_unregister(ds3232->rtc);
456 kfree(ds3232);
457 return 0; 446 return 0;
458} 447}
459 448
diff --git a/drivers/rtc/rtc-ds3234.c b/drivers/rtc/rtc-ds3234.c
index 7a4495ef1c39..ba98c0e9580d 100644
--- a/drivers/rtc/rtc-ds3234.c
+++ b/drivers/rtc/rtc-ds3234.c
@@ -146,21 +146,18 @@ static int ds3234_probe(struct spi_device *spi)
146 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp); 146 ds3234_get_reg(&spi->dev, DS3234_REG_CONT_STAT, &tmp);
147 dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp); 147 dev_info(&spi->dev, "Ctrl/Stat Reg: 0x%02x\n", tmp);
148 148
149 rtc = rtc_device_register("ds3234", 149 rtc = devm_rtc_device_register(&spi->dev, "ds3234",
150 &spi->dev, &ds3234_rtc_ops, THIS_MODULE); 150 &ds3234_rtc_ops, THIS_MODULE);
151 if (IS_ERR(rtc)) 151 if (IS_ERR(rtc))
152 return PTR_ERR(rtc); 152 return PTR_ERR(rtc);
153 153
154 dev_set_drvdata(&spi->dev, rtc); 154 spi_set_drvdata(spi, rtc);
155 155
156 return 0; 156 return 0;
157} 157}
158 158
159static int ds3234_remove(struct spi_device *spi) 159static int ds3234_remove(struct spi_device *spi)
160{ 160{
161 struct rtc_device *rtc = spi_get_drvdata(spi);
162
163 rtc_device_unregister(rtc);
164 return 0; 161 return 0;
165} 162}
166 163
diff --git a/drivers/rtc/rtc-efi.c b/drivers/rtc/rtc-efi.c
index 1a0c37c9152b..b3c8c0b1709d 100644
--- a/drivers/rtc/rtc-efi.c
+++ b/drivers/rtc/rtc-efi.c
@@ -191,7 +191,7 @@ static int __init efi_rtc_probe(struct platform_device *dev)
191{ 191{
192 struct rtc_device *rtc; 192 struct rtc_device *rtc;
193 193
194 rtc = rtc_device_register("rtc-efi", &dev->dev, &efi_rtc_ops, 194 rtc = devm_rtc_device_register(&dev->dev, "rtc-efi", &efi_rtc_ops,
195 THIS_MODULE); 195 THIS_MODULE);
196 if (IS_ERR(rtc)) 196 if (IS_ERR(rtc))
197 return PTR_ERR(rtc); 197 return PTR_ERR(rtc);
@@ -203,10 +203,6 @@ static int __init efi_rtc_probe(struct platform_device *dev)
203 203
204static int __exit efi_rtc_remove(struct platform_device *dev) 204static int __exit efi_rtc_remove(struct platform_device *dev)
205{ 205{
206 struct rtc_device *rtc = platform_get_drvdata(dev);
207
208 rtc_device_unregister(rtc);
209
210 return 0; 206 return 0;
211} 207}
212 208
@@ -218,18 +214,7 @@ static struct platform_driver efi_rtc_driver = {
218 .remove = __exit_p(efi_rtc_remove), 214 .remove = __exit_p(efi_rtc_remove),
219}; 215};
220 216
221static int __init efi_rtc_init(void) 217module_platform_driver_probe(efi_rtc_driver, efi_rtc_probe);
222{
223 return platform_driver_probe(&efi_rtc_driver, efi_rtc_probe);
224}
225
226static void __exit efi_rtc_exit(void)
227{
228 platform_driver_unregister(&efi_rtc_driver);
229}
230
231module_init(efi_rtc_init);
232module_exit(efi_rtc_exit);
233 218
234MODULE_AUTHOR("dann frazier <dannf@hp.com>"); 219MODULE_AUTHOR("dann frazier <dannf@hp.com>");
235MODULE_LICENSE("GPL"); 220MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-em3027.c b/drivers/rtc/rtc-em3027.c
index f6c24ce35d36..3f9eb57d0486 100644
--- a/drivers/rtc/rtc-em3027.c
+++ b/drivers/rtc/rtc-em3027.c
@@ -121,7 +121,7 @@ static int em3027_probe(struct i2c_client *client,
121 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 121 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
122 return -ENODEV; 122 return -ENODEV;
123 123
124 rtc = rtc_device_register(em3027_driver.driver.name, &client->dev, 124 rtc = devm_rtc_device_register(&client->dev, em3027_driver.driver.name,
125 &em3027_rtc_ops, THIS_MODULE); 125 &em3027_rtc_ops, THIS_MODULE);
126 if (IS_ERR(rtc)) 126 if (IS_ERR(rtc))
127 return PTR_ERR(rtc); 127 return PTR_ERR(rtc);
@@ -133,11 +133,6 @@ static int em3027_probe(struct i2c_client *client,
133 133
134static int em3027_remove(struct i2c_client *client) 134static int em3027_remove(struct i2c_client *client)
135{ 135{
136 struct rtc_device *rtc = i2c_get_clientdata(client);
137
138 if (rtc)
139 rtc_device_unregister(rtc);
140
141 return 0; 136 return 0;
142} 137}
143 138
diff --git a/drivers/rtc/rtc-ep93xx.c b/drivers/rtc/rtc-ep93xx.c
index 1a4e5e4a70cd..5807b77c444a 100644
--- a/drivers/rtc/rtc-ep93xx.c
+++ b/drivers/rtc/rtc-ep93xx.c
@@ -153,8 +153,8 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
153 pdev->dev.platform_data = ep93xx_rtc; 153 pdev->dev.platform_data = ep93xx_rtc;
154 platform_set_drvdata(pdev, ep93xx_rtc); 154 platform_set_drvdata(pdev, ep93xx_rtc);
155 155
156 ep93xx_rtc->rtc = rtc_device_register(pdev->name, 156 ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev,
157 &pdev->dev, &ep93xx_rtc_ops, THIS_MODULE); 157 pdev->name, &ep93xx_rtc_ops, THIS_MODULE);
158 if (IS_ERR(ep93xx_rtc->rtc)) { 158 if (IS_ERR(ep93xx_rtc->rtc)) {
159 err = PTR_ERR(ep93xx_rtc->rtc); 159 err = PTR_ERR(ep93xx_rtc->rtc);
160 goto exit; 160 goto exit;
@@ -162,12 +162,10 @@ static int ep93xx_rtc_probe(struct platform_device *pdev)
162 162
163 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); 163 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
164 if (err) 164 if (err)
165 goto fail; 165 goto exit;
166 166
167 return 0; 167 return 0;
168 168
169fail:
170 rtc_device_unregister(ep93xx_rtc->rtc);
171exit: 169exit:
172 platform_set_drvdata(pdev, NULL); 170 platform_set_drvdata(pdev, NULL);
173 pdev->dev.platform_data = NULL; 171 pdev->dev.platform_data = NULL;
@@ -176,11 +174,8 @@ exit:
176 174
177static int ep93xx_rtc_remove(struct platform_device *pdev) 175static int ep93xx_rtc_remove(struct platform_device *pdev)
178{ 176{
179 struct ep93xx_rtc *ep93xx_rtc = platform_get_drvdata(pdev);
180
181 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files); 177 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
182 platform_set_drvdata(pdev, NULL); 178 platform_set_drvdata(pdev, NULL);
183 rtc_device_unregister(ep93xx_rtc->rtc);
184 pdev->dev.platform_data = NULL; 179 pdev->dev.platform_data = NULL;
185 180
186 return 0; 181 return 0;
diff --git a/drivers/rtc/rtc-fm3130.c b/drivers/rtc/rtc-fm3130.c
index bff3cdc5140e..2835fb6c1965 100644
--- a/drivers/rtc/rtc-fm3130.c
+++ b/drivers/rtc/rtc-fm3130.c
@@ -358,7 +358,7 @@ static int fm3130_probe(struct i2c_client *client,
358 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 358 I2C_FUNC_I2C | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
359 return -EIO; 359 return -EIO;
360 360
361 fm3130 = kzalloc(sizeof(struct fm3130), GFP_KERNEL); 361 fm3130 = devm_kzalloc(&client->dev, sizeof(struct fm3130), GFP_KERNEL);
362 362
363 if (!fm3130) 363 if (!fm3130)
364 return -ENOMEM; 364 return -ENOMEM;
@@ -395,7 +395,7 @@ static int fm3130_probe(struct i2c_client *client,
395 395
396 tmp = i2c_transfer(adapter, fm3130->msg, 4); 396 tmp = i2c_transfer(adapter, fm3130->msg, 4);
397 if (tmp != 4) { 397 if (tmp != 4) {
398 pr_debug("read error %d\n", tmp); 398 dev_dbg(&client->dev, "read error %d\n", tmp);
399 err = -EIO; 399 err = -EIO;
400 goto exit_free; 400 goto exit_free;
401 } 401 }
@@ -507,7 +507,7 @@ bad_clock:
507 507
508 /* We won't bail out here because we just got invalid data. 508 /* We won't bail out here because we just got invalid data.
509 Time setting from u-boot doesn't work anyway */ 509 Time setting from u-boot doesn't work anyway */
510 fm3130->rtc = rtc_device_register(client->name, &client->dev, 510 fm3130->rtc = devm_rtc_device_register(&client->dev, client->name,
511 &fm3130_rtc_ops, THIS_MODULE); 511 &fm3130_rtc_ops, THIS_MODULE);
512 if (IS_ERR(fm3130->rtc)) { 512 if (IS_ERR(fm3130->rtc)) {
513 err = PTR_ERR(fm3130->rtc); 513 err = PTR_ERR(fm3130->rtc);
@@ -517,16 +517,11 @@ bad_clock:
517 } 517 }
518 return 0; 518 return 0;
519exit_free: 519exit_free:
520 kfree(fm3130);
521 return err; 520 return err;
522} 521}
523 522
524static int fm3130_remove(struct i2c_client *client) 523static int fm3130_remove(struct i2c_client *client)
525{ 524{
526 struct fm3130 *fm3130 = i2c_get_clientdata(client);
527
528 rtc_device_unregister(fm3130->rtc);
529 kfree(fm3130);
530 return 0; 525 return 0;
531} 526}
532 527
diff --git a/drivers/rtc/rtc-generic.c b/drivers/rtc/rtc-generic.c
index 98322004ad2e..06279ce6bff2 100644
--- a/drivers/rtc/rtc-generic.c
+++ b/drivers/rtc/rtc-generic.c
@@ -38,8 +38,8 @@ static int __init generic_rtc_probe(struct platform_device *dev)
38{ 38{
39 struct rtc_device *rtc; 39 struct rtc_device *rtc;
40 40
41 rtc = rtc_device_register("rtc-generic", &dev->dev, &generic_rtc_ops, 41 rtc = devm_rtc_device_register(&dev->dev, "rtc-generic",
42 THIS_MODULE); 42 &generic_rtc_ops, THIS_MODULE);
43 if (IS_ERR(rtc)) 43 if (IS_ERR(rtc))
44 return PTR_ERR(rtc); 44 return PTR_ERR(rtc);
45 45
@@ -50,10 +50,6 @@ static int __init generic_rtc_probe(struct platform_device *dev)
50 50
51static int __exit generic_rtc_remove(struct platform_device *dev) 51static int __exit generic_rtc_remove(struct platform_device *dev)
52{ 52{
53 struct rtc_device *rtc = platform_get_drvdata(dev);
54
55 rtc_device_unregister(rtc);
56
57 return 0; 53 return 0;
58} 54}
59 55
@@ -65,18 +61,7 @@ static struct platform_driver generic_rtc_driver = {
65 .remove = __exit_p(generic_rtc_remove), 61 .remove = __exit_p(generic_rtc_remove),
66}; 62};
67 63
68static int __init generic_rtc_init(void) 64module_platform_driver_probe(generic_rtc_driver, generic_rtc_probe);
69{
70 return platform_driver_probe(&generic_rtc_driver, generic_rtc_probe);
71}
72
73static void __exit generic_rtc_fini(void)
74{
75 platform_driver_unregister(&generic_rtc_driver);
76}
77
78module_init(generic_rtc_init);
79module_exit(generic_rtc_fini);
80 65
81MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>"); 66MODULE_AUTHOR("Kyle McMartin <kyle@mcmartin.ca>");
82MODULE_LICENSE("GPL"); 67MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 31c5728ef629..63024505dddc 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -255,8 +255,9 @@ static int hid_time_probe(struct platform_device *pdev)
255 return ret; 255 return ret;
256 } 256 }
257 257
258 time_state->rtc = rtc_device_register("hid-sensor-time", 258 time_state->rtc = devm_rtc_device_register(&pdev->dev,
259 &pdev->dev, &hid_time_rtc_ops, THIS_MODULE); 259 "hid-sensor-time", &hid_time_rtc_ops,
260 THIS_MODULE);
260 261
261 if (IS_ERR(time_state->rtc)) { 262 if (IS_ERR(time_state->rtc)) {
262 dev_err(&pdev->dev, "rtc device register failed!\n"); 263 dev_err(&pdev->dev, "rtc device register failed!\n");
@@ -269,9 +270,7 @@ static int hid_time_probe(struct platform_device *pdev)
269static int hid_time_remove(struct platform_device *pdev) 270static int hid_time_remove(struct platform_device *pdev)
270{ 271{
271 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data; 272 struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
272 struct hid_time_state *time_state = platform_get_drvdata(pdev);
273 273
274 rtc_device_unregister(time_state->rtc);
275 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME); 274 sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_TIME);
276 275
277 return 0; 276 return 0;
diff --git a/drivers/rtc/rtc-imxdi.c b/drivers/rtc/rtc-imxdi.c
index 82aad695979e..d3a8c8e255de 100644
--- a/drivers/rtc/rtc-imxdi.c
+++ b/drivers/rtc/rtc-imxdi.c
@@ -369,7 +369,7 @@ static void dryice_work(struct work_struct *work)
369/* 369/*
370 * probe for dryice rtc device 370 * probe for dryice rtc device
371 */ 371 */
372static int dryice_rtc_probe(struct platform_device *pdev) 372static int __init dryice_rtc_probe(struct platform_device *pdev)
373{ 373{
374 struct resource *res; 374 struct resource *res;
375 struct imxdi_dev *imxdi; 375 struct imxdi_dev *imxdi;
@@ -464,7 +464,7 @@ static int dryice_rtc_probe(struct platform_device *pdev)
464 } 464 }
465 465
466 platform_set_drvdata(pdev, imxdi); 466 platform_set_drvdata(pdev, imxdi);
467 imxdi->rtc = rtc_device_register(pdev->name, &pdev->dev, 467 imxdi->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
468 &dryice_rtc_ops, THIS_MODULE); 468 &dryice_rtc_ops, THIS_MODULE);
469 if (IS_ERR(imxdi->rtc)) { 469 if (IS_ERR(imxdi->rtc)) {
470 rc = PTR_ERR(imxdi->rtc); 470 rc = PTR_ERR(imxdi->rtc);
@@ -479,7 +479,7 @@ err:
479 return rc; 479 return rc;
480} 480}
481 481
482static int dryice_rtc_remove(struct platform_device *pdev) 482static int __exit dryice_rtc_remove(struct platform_device *pdev)
483{ 483{
484 struct imxdi_dev *imxdi = platform_get_drvdata(pdev); 484 struct imxdi_dev *imxdi = platform_get_drvdata(pdev);
485 485
@@ -488,8 +488,6 @@ static int dryice_rtc_remove(struct platform_device *pdev)
488 /* mask all interrupts */ 488 /* mask all interrupts */
489 __raw_writel(0, imxdi->ioaddr + DIER); 489 __raw_writel(0, imxdi->ioaddr + DIER);
490 490
491 rtc_device_unregister(imxdi->rtc);
492
493 clk_disable_unprepare(imxdi->clk); 491 clk_disable_unprepare(imxdi->clk);
494 492
495 return 0; 493 return 0;
@@ -510,21 +508,10 @@ static struct platform_driver dryice_rtc_driver = {
510 .owner = THIS_MODULE, 508 .owner = THIS_MODULE,
511 .of_match_table = of_match_ptr(dryice_dt_ids), 509 .of_match_table = of_match_ptr(dryice_dt_ids),
512 }, 510 },
513 .remove = dryice_rtc_remove, 511 .remove = __exit_p(dryice_rtc_remove),
514}; 512};
515 513
516static int __init dryice_rtc_init(void) 514module_platform_driver_probe(dryice_rtc_driver, dryice_rtc_probe);
517{
518 return platform_driver_probe(&dryice_rtc_driver, dryice_rtc_probe);
519}
520
521static void __exit dryice_rtc_exit(void)
522{
523 platform_driver_unregister(&dryice_rtc_driver);
524}
525
526module_init(dryice_rtc_init);
527module_exit(dryice_rtc_exit);
528 515
529MODULE_AUTHOR("Freescale Semiconductor, Inc."); 516MODULE_AUTHOR("Freescale Semiconductor, Inc.");
530MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>"); 517MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
diff --git a/drivers/rtc/rtc-isl12022.c b/drivers/rtc/rtc-isl12022.c
index 6b4298ea683d..a1bbbb8de029 100644
--- a/drivers/rtc/rtc-isl12022.c
+++ b/drivers/rtc/rtc-isl12022.c
@@ -252,12 +252,11 @@ static int isl12022_probe(struct i2c_client *client,
252{ 252{
253 struct isl12022 *isl12022; 253 struct isl12022 *isl12022;
254 254
255 int ret = 0;
256
257 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 255 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
258 return -ENODEV; 256 return -ENODEV;
259 257
260 isl12022 = kzalloc(sizeof(struct isl12022), GFP_KERNEL); 258 isl12022 = devm_kzalloc(&client->dev, sizeof(struct isl12022),
259 GFP_KERNEL);
261 if (!isl12022) 260 if (!isl12022)
262 return -ENOMEM; 261 return -ENOMEM;
263 262
@@ -265,37 +264,22 @@ static int isl12022_probe(struct i2c_client *client,
265 264
266 i2c_set_clientdata(client, isl12022); 265 i2c_set_clientdata(client, isl12022);
267 266
268 isl12022->rtc = rtc_device_register(isl12022_driver.driver.name, 267 isl12022->rtc = devm_rtc_device_register(&client->dev,
269 &client->dev, 268 isl12022_driver.driver.name,
270 &isl12022_rtc_ops, 269 &isl12022_rtc_ops, THIS_MODULE);
271 THIS_MODULE); 270 if (IS_ERR(isl12022->rtc))
272 271 return PTR_ERR(isl12022->rtc);
273 if (IS_ERR(isl12022->rtc)) {
274 ret = PTR_ERR(isl12022->rtc);
275 goto exit_kfree;
276 }
277 272
278 return 0; 273 return 0;
279
280exit_kfree:
281 kfree(isl12022);
282
283 return ret;
284} 274}
285 275
286static int isl12022_remove(struct i2c_client *client) 276static int isl12022_remove(struct i2c_client *client)
287{ 277{
288 struct isl12022 *isl12022 = i2c_get_clientdata(client);
289
290 rtc_device_unregister(isl12022->rtc);
291 kfree(isl12022);
292
293 return 0; 278 return 0;
294} 279}
295 280
296static const struct i2c_device_id isl12022_id[] = { 281static const struct i2c_device_id isl12022_id[] = {
297 { "isl12022", 0 }, 282 { "isl12022", 0 },
298 { "rtc8564", 0 },
299 { } 283 { }
300}; 284};
301MODULE_DEVICE_TABLE(i2c, isl12022_id); 285MODULE_DEVICE_TABLE(i2c, isl12022_id);
diff --git a/drivers/rtc/rtc-lp8788.c b/drivers/rtc/rtc-lp8788.c
index 9a4631218f41..9853ac15b296 100644
--- a/drivers/rtc/rtc-lp8788.c
+++ b/drivers/rtc/rtc-lp8788.c
@@ -299,7 +299,7 @@ static int lp8788_rtc_probe(struct platform_device *pdev)
299 299
300 device_init_wakeup(dev, 1); 300 device_init_wakeup(dev, 1);
301 301
302 rtc->rdev = rtc_device_register("lp8788_rtc", dev, 302 rtc->rdev = devm_rtc_device_register(dev, "lp8788_rtc",
303 &lp8788_rtc_ops, THIS_MODULE); 303 &lp8788_rtc_ops, THIS_MODULE);
304 if (IS_ERR(rtc->rdev)) { 304 if (IS_ERR(rtc->rdev)) {
305 dev_err(dev, "can not register rtc device\n"); 305 dev_err(dev, "can not register rtc device\n");
@@ -314,9 +314,6 @@ static int lp8788_rtc_probe(struct platform_device *pdev)
314 314
315static int lp8788_rtc_remove(struct platform_device *pdev) 315static int lp8788_rtc_remove(struct platform_device *pdev)
316{ 316{
317 struct lp8788_rtc *rtc = platform_get_drvdata(pdev);
318
319 rtc_device_unregister(rtc->rdev);
320 platform_set_drvdata(pdev, NULL); 317 platform_set_drvdata(pdev, NULL);
321 318
322 return 0; 319 return 0;
diff --git a/drivers/rtc/rtc-lpc32xx.c b/drivers/rtc/rtc-lpc32xx.c
index 40a598332bac..787550d756e9 100644
--- a/drivers/rtc/rtc-lpc32xx.c
+++ b/drivers/rtc/rtc-lpc32xx.c
@@ -273,8 +273,8 @@ static int lpc32xx_rtc_probe(struct platform_device *pdev)
273 273
274 platform_set_drvdata(pdev, rtc); 274 platform_set_drvdata(pdev, rtc);
275 275
276 rtc->rtc = rtc_device_register(RTC_NAME, &pdev->dev, &lpc32xx_rtc_ops, 276 rtc->rtc = devm_rtc_device_register(&pdev->dev, RTC_NAME,
277 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); 280 platform_set_drvdata(pdev, NULL);
@@ -307,7 +307,6 @@ static int lpc32xx_rtc_remove(struct platform_device *pdev)
307 device_init_wakeup(&pdev->dev, 0); 307 device_init_wakeup(&pdev->dev, 0);
308 308
309 platform_set_drvdata(pdev, NULL); 309 platform_set_drvdata(pdev, NULL);
310 rtc_device_unregister(rtc->rtc);
311 310
312 return 0; 311 return 0;
313} 312}
diff --git a/drivers/rtc/rtc-ls1x.c b/drivers/rtc/rtc-ls1x.c
index f59b6349551a..db82f91f4562 100644
--- a/drivers/rtc/rtc-ls1x.c
+++ b/drivers/rtc/rtc-ls1x.c
@@ -172,7 +172,7 @@ static int ls1x_rtc_probe(struct platform_device *pdev)
172 while (readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_TTS) 172 while (readl(SYS_COUNTER_CNTRL) & SYS_CNTRL_TTS)
173 usleep_range(1000, 3000); 173 usleep_range(1000, 3000);
174 174
175 rtcdev = rtc_device_register("ls1x-rtc", &pdev->dev, 175 rtcdev = devm_rtc_device_register(&pdev->dev, "ls1x-rtc",
176 &ls1x_rtc_ops , THIS_MODULE); 176 &ls1x_rtc_ops , THIS_MODULE);
177 if (IS_ERR(rtcdev)) { 177 if (IS_ERR(rtcdev)) {
178 ret = PTR_ERR(rtcdev); 178 ret = PTR_ERR(rtcdev);
@@ -187,9 +187,6 @@ err:
187 187
188static int ls1x_rtc_remove(struct platform_device *pdev) 188static int ls1x_rtc_remove(struct platform_device *pdev)
189{ 189{
190 struct rtc_device *rtcdev = platform_get_drvdata(pdev);
191
192 rtc_device_unregister(rtcdev);
193 platform_set_drvdata(pdev, NULL); 190 platform_set_drvdata(pdev, NULL);
194 191
195 return 0; 192 return 0;
diff --git a/drivers/rtc/rtc-m41t80.c b/drivers/rtc/rtc-m41t80.c
index b885bcd08908..89674b5e6efd 100644
--- a/drivers/rtc/rtc-m41t80.c
+++ b/drivers/rtc/rtc-m41t80.c
@@ -637,7 +637,8 @@ static int m41t80_probe(struct i2c_client *client,
637 dev_info(&client->dev, 637 dev_info(&client->dev,
638 "chip found, driver version " DRV_VERSION "\n"); 638 "chip found, driver version " DRV_VERSION "\n");
639 639
640 clientdata = kzalloc(sizeof(*clientdata), GFP_KERNEL); 640 clientdata = devm_kzalloc(&client->dev, sizeof(*clientdata),
641 GFP_KERNEL);
641 if (!clientdata) { 642 if (!clientdata) {
642 rc = -ENOMEM; 643 rc = -ENOMEM;
643 goto exit; 644 goto exit;
@@ -646,8 +647,8 @@ static int m41t80_probe(struct i2c_client *client,
646 clientdata->features = id->driver_data; 647 clientdata->features = id->driver_data;
647 i2c_set_clientdata(client, clientdata); 648 i2c_set_clientdata(client, clientdata);
648 649
649 rtc = rtc_device_register(client->name, &client->dev, 650 rtc = devm_rtc_device_register(&client->dev, client->name,
650 &m41t80_rtc_ops, THIS_MODULE); 651 &m41t80_rtc_ops, THIS_MODULE);
651 if (IS_ERR(rtc)) { 652 if (IS_ERR(rtc)) {
652 rc = PTR_ERR(rtc); 653 rc = PTR_ERR(rtc);
653 rtc = NULL; 654 rtc = NULL;
@@ -718,26 +719,19 @@ ht_err:
718 goto exit; 719 goto exit;
719 720
720exit: 721exit:
721 if (rtc)
722 rtc_device_unregister(rtc);
723 kfree(clientdata);
724 return rc; 722 return rc;
725} 723}
726 724
727static int m41t80_remove(struct i2c_client *client) 725static int m41t80_remove(struct i2c_client *client)
728{ 726{
727#ifdef CONFIG_RTC_DRV_M41T80_WDT
729 struct m41t80_data *clientdata = i2c_get_clientdata(client); 728 struct m41t80_data *clientdata = i2c_get_clientdata(client);
730 struct rtc_device *rtc = clientdata->rtc;
731 729
732#ifdef CONFIG_RTC_DRV_M41T80_WDT
733 if (clientdata->features & M41T80_FEATURE_HT) { 730 if (clientdata->features & M41T80_FEATURE_HT) {
734 misc_deregister(&wdt_dev); 731 misc_deregister(&wdt_dev);
735 unregister_reboot_notifier(&wdt_notifier); 732 unregister_reboot_notifier(&wdt_notifier);
736 } 733 }
737#endif 734#endif
738 if (rtc)
739 rtc_device_unregister(rtc);
740 kfree(clientdata);
741 735
742 return 0; 736 return 0;
743} 737}
diff --git a/drivers/rtc/rtc-m41t93.c b/drivers/rtc/rtc-m41t93.c
index 49169680786e..9707d36e8b15 100644
--- a/drivers/rtc/rtc-m41t93.c
+++ b/drivers/rtc/rtc-m41t93.c
@@ -184,12 +184,12 @@ static int m41t93_probe(struct spi_device *spi)
184 return -ENODEV; 184 return -ENODEV;
185 } 185 }
186 186
187 rtc = rtc_device_register(m41t93_driver.driver.name, 187 rtc = devm_rtc_device_register(&spi->dev, m41t93_driver.driver.name,
188 &spi->dev, &m41t93_rtc_ops, THIS_MODULE); 188 &m41t93_rtc_ops, THIS_MODULE);
189 if (IS_ERR(rtc)) 189 if (IS_ERR(rtc))
190 return PTR_ERR(rtc); 190 return PTR_ERR(rtc);
191 191
192 dev_set_drvdata(&spi->dev, rtc); 192 spi_set_drvdata(spi, rtc);
193 193
194 return 0; 194 return 0;
195} 195}
@@ -197,11 +197,6 @@ static int m41t93_probe(struct spi_device *spi)
197 197
198static int m41t93_remove(struct spi_device *spi) 198static int m41t93_remove(struct spi_device *spi)
199{ 199{
200 struct rtc_device *rtc = spi_get_drvdata(spi);
201
202 if (rtc)
203 rtc_device_unregister(rtc);
204
205 return 0; 200 return 0;
206} 201}
207 202
diff --git a/drivers/rtc/rtc-m41t94.c b/drivers/rtc/rtc-m41t94.c
index 89266c6764bc..7454ef0a4cfa 100644
--- a/drivers/rtc/rtc-m41t94.c
+++ b/drivers/rtc/rtc-m41t94.c
@@ -124,23 +124,18 @@ static int m41t94_probe(struct spi_device *spi)
124 return res; 124 return res;
125 } 125 }
126 126
127 rtc = rtc_device_register(m41t94_driver.driver.name, 127 rtc = devm_rtc_device_register(&spi->dev, m41t94_driver.driver.name,
128 &spi->dev, &m41t94_rtc_ops, THIS_MODULE); 128 &m41t94_rtc_ops, THIS_MODULE);
129 if (IS_ERR(rtc)) 129 if (IS_ERR(rtc))
130 return PTR_ERR(rtc); 130 return PTR_ERR(rtc);
131 131
132 dev_set_drvdata(&spi->dev, rtc); 132 spi_set_drvdata(spi, rtc);
133 133
134 return 0; 134 return 0;
135} 135}
136 136
137static int m41t94_remove(struct spi_device *spi) 137static int m41t94_remove(struct spi_device *spi)
138{ 138{
139 struct rtc_device *rtc = spi_get_drvdata(spi);
140
141 if (rtc)
142 rtc_device_unregister(rtc);
143
144 return 0; 139 return 0;
145} 140}
146 141
diff --git a/drivers/rtc/rtc-m48t35.c b/drivers/rtc/rtc-m48t35.c
index 31c9190a1fcb..37444246e5e4 100644
--- a/drivers/rtc/rtc-m48t35.c
+++ b/drivers/rtc/rtc-m48t35.c
@@ -145,12 +145,11 @@ static int m48t35_probe(struct platform_device *pdev)
145{ 145{
146 struct resource *res; 146 struct resource *res;
147 struct m48t35_priv *priv; 147 struct m48t35_priv *priv;
148 int ret = 0;
149 148
150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 149 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!res) 150 if (!res)
152 return -ENODEV; 151 return -ENODEV;
153 priv = kzalloc(sizeof(struct m48t35_priv), GFP_KERNEL); 152 priv = devm_kzalloc(&pdev->dev, sizeof(struct m48t35_priv), GFP_KERNEL);
154 if (!priv) 153 if (!priv)
155 return -ENOMEM; 154 return -ENOMEM;
156 155
@@ -160,50 +159,29 @@ static int m48t35_probe(struct platform_device *pdev)
160 * conflicts are resolved 159 * conflicts are resolved
161 */ 160 */
162#ifndef CONFIG_SGI_IP27 161#ifndef CONFIG_SGI_IP27
163 if (!request_mem_region(res->start, priv->size, pdev->name)) { 162 if (!devm_request_mem_region(&pdev->dev, res->start, priv->size,
164 ret = -EBUSY; 163 pdev->name))
165 goto out; 164 return -EBUSY;
166 }
167#endif 165#endif
168 priv->baseaddr = res->start; 166 priv->baseaddr = res->start;
169 priv->reg = ioremap(priv->baseaddr, priv->size); 167 priv->reg = devm_ioremap(&pdev->dev, priv->baseaddr, priv->size);
170 if (!priv->reg) { 168 if (!priv->reg)
171 ret = -ENOMEM; 169 return -ENOMEM;
172 goto out;
173 }
174 170
175 spin_lock_init(&priv->lock); 171 spin_lock_init(&priv->lock);
176 172
177 platform_set_drvdata(pdev, priv); 173 platform_set_drvdata(pdev, priv);
178 174
179 priv->rtc = rtc_device_register("m48t35", &pdev->dev, 175 priv->rtc = devm_rtc_device_register(&pdev->dev, "m48t35",
180 &m48t35_ops, THIS_MODULE); 176 &m48t35_ops, THIS_MODULE);
181 if (IS_ERR(priv->rtc)) { 177 if (IS_ERR(priv->rtc))
182 ret = PTR_ERR(priv->rtc); 178 return PTR_ERR(priv->rtc);
183 goto out;
184 }
185 179
186 return 0; 180 return 0;
187
188out:
189 if (priv->reg)
190 iounmap(priv->reg);
191 if (priv->baseaddr)
192 release_mem_region(priv->baseaddr, priv->size);
193 kfree(priv);
194 return ret;
195} 181}
196 182
197static int m48t35_remove(struct platform_device *pdev) 183static int m48t35_remove(struct platform_device *pdev)
198{ 184{
199 struct m48t35_priv *priv = platform_get_drvdata(pdev);
200
201 rtc_device_unregister(priv->rtc);
202 iounmap(priv->reg);
203#ifndef CONFIG_SGI_IP27
204 release_mem_region(priv->baseaddr, priv->size);
205#endif
206 kfree(priv);
207 return 0; 185 return 0;
208} 186}
209 187
diff --git a/drivers/rtc/rtc-m48t86.c b/drivers/rtc/rtc-m48t86.c
index 2ffbcacd2439..33a91c484533 100644
--- a/drivers/rtc/rtc-m48t86.c
+++ b/drivers/rtc/rtc-m48t86.c
@@ -148,8 +148,10 @@ static int m48t86_rtc_probe(struct platform_device *dev)
148{ 148{
149 unsigned char reg; 149 unsigned char reg;
150 struct m48t86_ops *ops = dev->dev.platform_data; 150 struct m48t86_ops *ops = dev->dev.platform_data;
151 struct rtc_device *rtc = rtc_device_register("m48t86", 151 struct rtc_device *rtc;
152 &dev->dev, &m48t86_rtc_ops, THIS_MODULE); 152
153 rtc = devm_rtc_device_register(&dev->dev, "m48t86",
154 &m48t86_rtc_ops, THIS_MODULE);
153 155
154 if (IS_ERR(rtc)) 156 if (IS_ERR(rtc))
155 return PTR_ERR(rtc); 157 return PTR_ERR(rtc);
@@ -166,11 +168,6 @@ static int m48t86_rtc_probe(struct platform_device *dev)
166 168
167static int m48t86_rtc_remove(struct platform_device *dev) 169static int m48t86_rtc_remove(struct platform_device *dev)
168{ 170{
169 struct rtc_device *rtc = platform_get_drvdata(dev);
170
171 if (rtc)
172 rtc_device_unregister(rtc);
173
174 platform_set_drvdata(dev, NULL); 171 platform_set_drvdata(dev, NULL);
175 172
176 return 0; 173 return 0;
diff --git a/drivers/rtc/rtc-max6900.c b/drivers/rtc/rtc-max6900.c
index a00e33204b91..8669d6d09a00 100644
--- a/drivers/rtc/rtc-max6900.c
+++ b/drivers/rtc/rtc-max6900.c
@@ -214,11 +214,6 @@ static int max6900_rtc_set_time(struct device *dev, struct rtc_time *tm)
214 214
215static int max6900_remove(struct i2c_client *client) 215static int max6900_remove(struct i2c_client *client)
216{ 216{
217 struct rtc_device *rtc = i2c_get_clientdata(client);
218
219 if (rtc)
220 rtc_device_unregister(rtc);
221
222 return 0; 217 return 0;
223} 218}
224 219
@@ -237,8 +232,8 @@ max6900_probe(struct i2c_client *client, const struct i2c_device_id *id)
237 232
238 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 233 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
239 234
240 rtc = rtc_device_register(max6900_driver.driver.name, 235 rtc = devm_rtc_device_register(&client->dev, max6900_driver.driver.name,
241 &client->dev, &max6900_rtc_ops, THIS_MODULE); 236 &max6900_rtc_ops, THIS_MODULE);
242 if (IS_ERR(rtc)) 237 if (IS_ERR(rtc))
243 return PTR_ERR(rtc); 238 return PTR_ERR(rtc);
244 239
diff --git a/drivers/rtc/rtc-max6902.c b/drivers/rtc/rtc-max6902.c
index 7d0bf698b79e..e3aea00c3145 100644
--- a/drivers/rtc/rtc-max6902.c
+++ b/drivers/rtc/rtc-max6902.c
@@ -93,24 +93,24 @@ static int max6902_set_time(struct device *dev, struct rtc_time *dt)
93 dt->tm_year = dt->tm_year + 1900; 93 dt->tm_year = dt->tm_year + 1900;
94 94
95 /* Remove write protection */ 95 /* Remove write protection */
96 max6902_set_reg(dev, 0xF, 0); 96 max6902_set_reg(dev, MAX6902_REG_CONTROL, 0);
97 97
98 max6902_set_reg(dev, 0x01, bin2bcd(dt->tm_sec)); 98 max6902_set_reg(dev, MAX6902_REG_SECONDS, bin2bcd(dt->tm_sec));
99 max6902_set_reg(dev, 0x03, bin2bcd(dt->tm_min)); 99 max6902_set_reg(dev, MAX6902_REG_MINUTES, bin2bcd(dt->tm_min));
100 max6902_set_reg(dev, 0x05, bin2bcd(dt->tm_hour)); 100 max6902_set_reg(dev, MAX6902_REG_HOURS, bin2bcd(dt->tm_hour));
101 101
102 max6902_set_reg(dev, 0x07, bin2bcd(dt->tm_mday)); 102 max6902_set_reg(dev, MAX6902_REG_DATE, bin2bcd(dt->tm_mday));
103 max6902_set_reg(dev, 0x09, bin2bcd(dt->tm_mon + 1)); 103 max6902_set_reg(dev, MAX6902_REG_MONTH, bin2bcd(dt->tm_mon + 1));
104 max6902_set_reg(dev, 0x0B, bin2bcd(dt->tm_wday)); 104 max6902_set_reg(dev, MAX6902_REG_DAY, bin2bcd(dt->tm_wday));
105 max6902_set_reg(dev, 0x0D, bin2bcd(dt->tm_year % 100)); 105 max6902_set_reg(dev, MAX6902_REG_YEAR, bin2bcd(dt->tm_year % 100));
106 max6902_set_reg(dev, 0x13, bin2bcd(dt->tm_year / 100)); 106 max6902_set_reg(dev, MAX6902_REG_CENTURY, bin2bcd(dt->tm_year / 100));
107 107
108 /* Compulab used a delay here. However, the datasheet 108 /* Compulab used a delay here. However, the datasheet
109 * does not mention a delay being required anywhere... */ 109 * does not mention a delay being required anywhere... */
110 /* delay(2000); */ 110 /* delay(2000); */
111 111
112 /* Write protect */ 112 /* Write protect */
113 max6902_set_reg(dev, 0xF, 0x80); 113 max6902_set_reg(dev, MAX6902_REG_CONTROL, 0x80);
114 114
115 return 0; 115 return 0;
116} 116}
@@ -134,20 +134,17 @@ static int max6902_probe(struct spi_device *spi)
134 if (res != 0) 134 if (res != 0)
135 return res; 135 return res;
136 136
137 rtc = rtc_device_register("max6902", 137 rtc = devm_rtc_device_register(&spi->dev, "max6902",
138 &spi->dev, &max6902_rtc_ops, THIS_MODULE); 138 &max6902_rtc_ops, THIS_MODULE);
139 if (IS_ERR(rtc)) 139 if (IS_ERR(rtc))
140 return PTR_ERR(rtc); 140 return PTR_ERR(rtc);
141 141
142 dev_set_drvdata(&spi->dev, rtc); 142 spi_set_drvdata(spi, rtc);
143 return 0; 143 return 0;
144} 144}
145 145
146static int max6902_remove(struct spi_device *spi) 146static int max6902_remove(struct spi_device *spi)
147{ 147{
148 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
149
150 rtc_device_unregister(rtc);
151 return 0; 148 return 0;
152} 149}
153 150
diff --git a/drivers/rtc/rtc-max77686.c b/drivers/rtc/rtc-max77686.c
index 6b1337f9baf4..771812d62e6b 100644
--- a/drivers/rtc/rtc-max77686.c
+++ b/drivers/rtc/rtc-max77686.c
@@ -24,7 +24,7 @@
24 24
25/* RTC Control Register */ 25/* RTC Control Register */
26#define BCD_EN_SHIFT 0 26#define BCD_EN_SHIFT 0
27#define BCD_EN_MASK (1 << BCD_EN_SHIFT) 27#define BCD_EN_MASK (1 << BCD_EN_SHIFT)
28#define MODEL24_SHIFT 1 28#define MODEL24_SHIFT 1
29#define MODEL24_MASK (1 << MODEL24_SHIFT) 29#define MODEL24_MASK (1 << MODEL24_SHIFT)
30/* RTC Update Register1 */ 30/* RTC Update Register1 */
@@ -33,12 +33,12 @@
33#define RTC_RBUDR_SHIFT 4 33#define RTC_RBUDR_SHIFT 4
34#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT) 34#define RTC_RBUDR_MASK (1 << RTC_RBUDR_SHIFT)
35/* WTSR and SMPL Register */ 35/* WTSR and SMPL Register */
36#define WTSRT_SHIFT 0 36#define WTSRT_SHIFT 0
37#define SMPLT_SHIFT 2 37#define SMPLT_SHIFT 2
38#define WTSR_EN_SHIFT 6 38#define WTSR_EN_SHIFT 6
39#define SMPL_EN_SHIFT 7 39#define SMPL_EN_SHIFT 7
40#define WTSRT_MASK (3 << WTSRT_SHIFT) 40#define WTSRT_MASK (3 << WTSRT_SHIFT)
41#define SMPLT_MASK (3 << SMPLT_SHIFT) 41#define SMPLT_MASK (3 << SMPLT_SHIFT)
42#define WTSR_EN_MASK (1 << WTSR_EN_SHIFT) 42#define WTSR_EN_MASK (1 << WTSR_EN_SHIFT)
43#define SMPL_EN_MASK (1 << SMPL_EN_SHIFT) 43#define SMPL_EN_MASK (1 << SMPL_EN_SHIFT)
44/* RTC Hour register */ 44/* RTC Hour register */
@@ -466,7 +466,7 @@ static void max77686_rtc_enable_smpl(struct max77686_rtc_info *info, bool enable
466 466
467 val = 0; 467 val = 0;
468 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val); 468 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
469 pr_info("%s: WTSR_SMPL(0x%02x)\n", __func__, val); 469 dev_info(info->dev, "%s: WTSR_SMPL(0x%02x)\n", __func__, val);
470} 470}
471#endif /* MAX77686_RTC_WTSR_SMPL */ 471#endif /* MAX77686_RTC_WTSR_SMPL */
472 472
@@ -505,7 +505,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
505 505
506 dev_info(&pdev->dev, "%s\n", __func__); 506 dev_info(&pdev->dev, "%s\n", __func__);
507 507
508 info = kzalloc(sizeof(struct max77686_rtc_info), GFP_KERNEL); 508 info = devm_kzalloc(&pdev->dev, sizeof(struct max77686_rtc_info),
509 GFP_KERNEL);
509 if (!info) 510 if (!info)
510 return -ENOMEM; 511 return -ENOMEM;
511 512
@@ -513,13 +514,12 @@ static int max77686_rtc_probe(struct platform_device *pdev)
513 info->dev = &pdev->dev; 514 info->dev = &pdev->dev;
514 info->max77686 = max77686; 515 info->max77686 = max77686;
515 info->rtc = max77686->rtc; 516 info->rtc = max77686->rtc;
516 info->max77686->rtc_regmap = regmap_init_i2c(info->max77686->rtc, 517 info->max77686->rtc_regmap = devm_regmap_init_i2c(info->max77686->rtc,
517 &max77686_rtc_regmap_config); 518 &max77686_rtc_regmap_config);
518 if (IS_ERR(info->max77686->rtc_regmap)) { 519 if (IS_ERR(info->max77686->rtc_regmap)) {
519 ret = PTR_ERR(info->max77686->rtc_regmap); 520 ret = PTR_ERR(info->max77686->rtc_regmap);
520 dev_err(info->max77686->dev, "Failed to allocate register map: %d\n", 521 dev_err(info->max77686->dev, "Failed to allocate register map: %d\n",
521 ret); 522 ret);
522 kfree(info);
523 return ret; 523 return ret;
524 } 524 }
525 platform_set_drvdata(pdev, info); 525 platform_set_drvdata(pdev, info);
@@ -538,8 +538,8 @@ static int max77686_rtc_probe(struct platform_device *pdev)
538 538
539 device_init_wakeup(&pdev->dev, 1); 539 device_init_wakeup(&pdev->dev, 1);
540 540
541 info->rtc_dev = rtc_device_register("max77686-rtc", &pdev->dev, 541 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max77686-rtc",
542 &max77686_rtc_ops, THIS_MODULE); 542 &max77686_rtc_ops, THIS_MODULE);
543 543
544 if (IS_ERR(info->rtc_dev)) { 544 if (IS_ERR(info->rtc_dev)) {
545 dev_info(&pdev->dev, "%s: fail\n", __func__); 545 dev_info(&pdev->dev, "%s: fail\n", __func__);
@@ -551,36 +551,24 @@ static int max77686_rtc_probe(struct platform_device *pdev)
551 goto err_rtc; 551 goto err_rtc;
552 } 552 }
553 virq = irq_create_mapping(max77686->irq_domain, MAX77686_RTCIRQ_RTCA1); 553 virq = irq_create_mapping(max77686->irq_domain, MAX77686_RTCIRQ_RTCA1);
554 if (!virq) 554 if (!virq) {
555 ret = -ENXIO;
555 goto err_rtc; 556 goto err_rtc;
557 }
556 info->virq = virq; 558 info->virq = virq;
557 559
558 ret = request_threaded_irq(virq, NULL, max77686_rtc_alarm_irq, 0, 560 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
559 "rtc-alarm0", info); 561 max77686_rtc_alarm_irq, 0, "rtc-alarm0", info);
560 if (ret < 0) { 562 if (ret < 0)
561 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 563 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
562 info->virq, ret); 564 info->virq, ret);
563 goto err_rtc;
564 }
565 565
566 goto out;
567err_rtc: 566err_rtc:
568 kfree(info);
569 return ret;
570out:
571 return ret; 567 return ret;
572} 568}
573 569
574static int max77686_rtc_remove(struct platform_device *pdev) 570static int max77686_rtc_remove(struct platform_device *pdev)
575{ 571{
576 struct max77686_rtc_info *info = platform_get_drvdata(pdev);
577
578 if (info) {
579 free_irq(info->virq, info);
580 rtc_device_unregister(info->rtc_dev);
581 kfree(info);
582 }
583
584 return 0; 572 return 0;
585} 573}
586 574
@@ -594,11 +582,14 @@ static void max77686_rtc_shutdown(struct platform_device *pdev)
594 for (i = 0; i < 3; i++) { 582 for (i = 0; i < 3; i++) {
595 max77686_rtc_enable_wtsr(info, false); 583 max77686_rtc_enable_wtsr(info, false);
596 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val); 584 regmap_read(info->max77686->rtc_regmap, MAX77686_WTSR_SMPL_CNTL, &val);
597 pr_info("%s: WTSR_SMPL reg(0x%02x)\n", __func__, val); 585 dev_info(info->dev, "%s: WTSR_SMPL reg(0x%02x)\n", __func__,
598 if (val & WTSR_EN_MASK) 586 val);
599 pr_emerg("%s: fail to disable WTSR\n", __func__); 587 if (val & WTSR_EN_MASK) {
600 else { 588 dev_emerg(info->dev, "%s: fail to disable WTSR\n",
601 pr_info("%s: success to disable WTSR\n", __func__); 589 __func__);
590 } else {
591 dev_info(info->dev, "%s: success to disable WTSR\n",
592 __func__);
602 break; 593 break;
603 } 594 }
604 } 595 }
@@ -624,18 +615,8 @@ static struct platform_driver max77686_rtc_driver = {
624 .id_table = rtc_id, 615 .id_table = rtc_id,
625}; 616};
626 617
627static int __init max77686_rtc_init(void) 618module_platform_driver(max77686_rtc_driver);
628{
629 return platform_driver_register(&max77686_rtc_driver);
630}
631module_init(max77686_rtc_init);
632
633static void __exit max77686_rtc_exit(void)
634{
635 platform_driver_unregister(&max77686_rtc_driver);
636}
637module_exit(max77686_rtc_exit);
638 619
639MODULE_DESCRIPTION("Maxim MAX77686 RTC driver"); 620MODULE_DESCRIPTION("Maxim MAX77686 RTC driver");
640MODULE_AUTHOR("<woong.byun@samsung.com>"); 621MODULE_AUTHOR("Chiwoong Byun <woong.byun@samsung.com>");
641MODULE_LICENSE("GPL"); 622MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-max8907.c b/drivers/rtc/rtc-max8907.c
index 31ca8faf9f05..86afb797125d 100644
--- a/drivers/rtc/rtc-max8907.c
+++ b/drivers/rtc/rtc-max8907.c
@@ -190,7 +190,7 @@ static int max8907_rtc_probe(struct platform_device *pdev)
190 rtc->max8907 = max8907; 190 rtc->max8907 = max8907;
191 rtc->regmap = max8907->regmap_rtc; 191 rtc->regmap = max8907->regmap_rtc;
192 192
193 rtc->rtc_dev = rtc_device_register("max8907-rtc", &pdev->dev, 193 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8907-rtc",
194 &max8907_rtc_ops, THIS_MODULE); 194 &max8907_rtc_ops, THIS_MODULE);
195 if (IS_ERR(rtc->rtc_dev)) { 195 if (IS_ERR(rtc->rtc_dev)) {
196 ret = PTR_ERR(rtc->rtc_dev); 196 ret = PTR_ERR(rtc->rtc_dev);
@@ -200,33 +200,21 @@ static int max8907_rtc_probe(struct platform_device *pdev)
200 200
201 rtc->irq = regmap_irq_get_virq(max8907->irqc_rtc, 201 rtc->irq = regmap_irq_get_virq(max8907->irqc_rtc,
202 MAX8907_IRQ_RTC_ALARM0); 202 MAX8907_IRQ_RTC_ALARM0);
203 if (rtc->irq < 0) { 203 if (rtc->irq < 0)
204 ret = rtc->irq; 204 return rtc->irq;
205 goto err_unregister;
206 }
207 205
208 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL, 206 ret = devm_request_threaded_irq(&pdev->dev, rtc->irq, NULL,
209 max8907_irq_handler, 207 max8907_irq_handler,
210 IRQF_ONESHOT, "max8907-alarm0", rtc); 208 IRQF_ONESHOT, "max8907-alarm0", rtc);
211 if (ret < 0) { 209 if (ret < 0)
212 dev_err(&pdev->dev, "Failed to request IRQ%d: %d\n", 210 dev_err(&pdev->dev, "Failed to request IRQ%d: %d\n",
213 rtc->irq, ret); 211 rtc->irq, ret);
214 goto err_unregister;
215 }
216 212
217 return 0;
218
219err_unregister:
220 rtc_device_unregister(rtc->rtc_dev);
221 return ret; 213 return ret;
222} 214}
223 215
224static int max8907_rtc_remove(struct platform_device *pdev) 216static int max8907_rtc_remove(struct platform_device *pdev)
225{ 217{
226 struct max8907_rtc *rtc = platform_get_drvdata(pdev);
227
228 rtc_device_unregister(rtc->rtc_dev);
229
230 return 0; 218 return 0;
231} 219}
232 220
diff --git a/drivers/rtc/rtc-max8925.c b/drivers/rtc/rtc-max8925.c
index a0c8265646d2..7c90f4e45e27 100644
--- a/drivers/rtc/rtc-max8925.c
+++ b/drivers/rtc/rtc-max8925.c
@@ -253,7 +253,8 @@ static int max8925_rtc_probe(struct platform_device *pdev)
253 struct max8925_rtc_info *info; 253 struct max8925_rtc_info *info;
254 int ret; 254 int ret;
255 255
256 info = kzalloc(sizeof(struct max8925_rtc_info), GFP_KERNEL); 256 info = devm_kzalloc(&pdev->dev, sizeof(struct max8925_rtc_info),
257 GFP_KERNEL);
257 if (!info) 258 if (!info)
258 return -ENOMEM; 259 return -ENOMEM;
259 info->chip = chip; 260 info->chip = chip;
@@ -261,12 +262,13 @@ static int max8925_rtc_probe(struct platform_device *pdev)
261 info->dev = &pdev->dev; 262 info->dev = &pdev->dev;
262 info->irq = platform_get_irq(pdev, 0); 263 info->irq = platform_get_irq(pdev, 0);
263 264
264 ret = request_threaded_irq(info->irq, NULL, rtc_update_handler, 265 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
265 IRQF_ONESHOT, "rtc-alarm0", info); 266 rtc_update_handler, IRQF_ONESHOT,
267 "rtc-alarm0", info);
266 if (ret < 0) { 268 if (ret < 0) {
267 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n", 269 dev_err(chip->dev, "Failed to request IRQ: #%d: %d\n",
268 info->irq, ret); 270 info->irq, ret);
269 goto out_irq; 271 goto err;
270 } 272 }
271 273
272 dev_set_drvdata(&pdev->dev, info); 274 dev_set_drvdata(&pdev->dev, info);
@@ -275,32 +277,22 @@ static int max8925_rtc_probe(struct platform_device *pdev)
275 277
276 device_init_wakeup(&pdev->dev, 1); 278 device_init_wakeup(&pdev->dev, 1);
277 279
278 info->rtc_dev = rtc_device_register("max8925-rtc", &pdev->dev, 280 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8925-rtc",
279 &max8925_rtc_ops, THIS_MODULE); 281 &max8925_rtc_ops, THIS_MODULE);
280 ret = PTR_ERR(info->rtc_dev); 282 ret = PTR_ERR(info->rtc_dev);
281 if (IS_ERR(info->rtc_dev)) { 283 if (IS_ERR(info->rtc_dev)) {
282 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);
283 goto out_rtc; 285 goto err;
284 } 286 }
285 287
286 return 0; 288 return 0;
287out_rtc: 289err:
288 platform_set_drvdata(pdev, NULL); 290 platform_set_drvdata(pdev, NULL);
289 free_irq(info->irq, info);
290out_irq:
291 kfree(info);
292 return ret; 291 return ret;
293} 292}
294 293
295static int max8925_rtc_remove(struct platform_device *pdev) 294static int max8925_rtc_remove(struct platform_device *pdev)
296{ 295{
297 struct max8925_rtc_info *info = platform_get_drvdata(pdev);
298
299 if (info) {
300 free_irq(info->irq, info);
301 rtc_device_unregister(info->rtc_dev);
302 kfree(info);
303 }
304 return 0; 296 return 0;
305} 297}
306 298
diff --git a/drivers/rtc/rtc-max8997.c b/drivers/rtc/rtc-max8997.c
index 00e505b6bee3..5693619614f4 100644
--- a/drivers/rtc/rtc-max8997.c
+++ b/drivers/rtc/rtc-max8997.c
@@ -479,8 +479,8 @@ static int max8997_rtc_probe(struct platform_device *pdev)
479 479
480 device_init_wakeup(&pdev->dev, 1); 480 device_init_wakeup(&pdev->dev, 1);
481 481
482 info->rtc_dev = rtc_device_register("max8997-rtc", &pdev->dev, 482 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8997-rtc",
483 &max8997_rtc_ops, THIS_MODULE); 483 &max8997_rtc_ops, THIS_MODULE);
484 484
485 if (IS_ERR(info->rtc_dev)) { 485 if (IS_ERR(info->rtc_dev)) {
486 ret = PTR_ERR(info->rtc_dev); 486 ret = PTR_ERR(info->rtc_dev);
@@ -491,6 +491,7 @@ static int max8997_rtc_probe(struct platform_device *pdev)
491 virq = irq_create_mapping(max8997->irq_domain, MAX8997_PMICIRQ_RTCA1); 491 virq = irq_create_mapping(max8997->irq_domain, MAX8997_PMICIRQ_RTCA1);
492 if (!virq) { 492 if (!virq) {
493 dev_err(&pdev->dev, "Failed to create mapping alarm IRQ\n"); 493 dev_err(&pdev->dev, "Failed to create mapping alarm IRQ\n");
494 ret = -ENXIO;
494 goto err_out; 495 goto err_out;
495 } 496 }
496 info->virq = virq; 497 info->virq = virq;
@@ -498,26 +499,16 @@ static int max8997_rtc_probe(struct platform_device *pdev)
498 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, 499 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
499 max8997_rtc_alarm_irq, 0, 500 max8997_rtc_alarm_irq, 0,
500 "rtc-alarm0", info); 501 "rtc-alarm0", info);
501 if (ret < 0) { 502 if (ret < 0)
502 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 503 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
503 info->virq, ret); 504 info->virq, ret);
504 goto err_out;
505 }
506
507 return ret;
508 505
509err_out: 506err_out:
510 rtc_device_unregister(info->rtc_dev);
511 return ret; 507 return ret;
512} 508}
513 509
514static int max8997_rtc_remove(struct platform_device *pdev) 510static int max8997_rtc_remove(struct platform_device *pdev)
515{ 511{
516 struct max8997_rtc_info *info = platform_get_drvdata(pdev);
517
518 if (info)
519 rtc_device_unregister(info->rtc_dev);
520
521 return 0; 512 return 0;
522} 513}
523 514
diff --git a/drivers/rtc/rtc-max8998.c b/drivers/rtc/rtc-max8998.c
index 8f234a075e8f..48b6612fae7f 100644
--- a/drivers/rtc/rtc-max8998.c
+++ b/drivers/rtc/rtc-max8998.c
@@ -256,7 +256,8 @@ static int max8998_rtc_probe(struct platform_device *pdev)
256 struct max8998_rtc_info *info; 256 struct max8998_rtc_info *info;
257 int ret; 257 int ret;
258 258
259 info = kzalloc(sizeof(struct max8998_rtc_info), GFP_KERNEL); 259 info = devm_kzalloc(&pdev->dev, sizeof(struct max8998_rtc_info),
260 GFP_KERNEL);
260 if (!info) 261 if (!info)
261 return -ENOMEM; 262 return -ENOMEM;
262 263
@@ -267,7 +268,7 @@ static int max8998_rtc_probe(struct platform_device *pdev)
267 268
268 platform_set_drvdata(pdev, info); 269 platform_set_drvdata(pdev, info);
269 270
270 info->rtc_dev = rtc_device_register("max8998-rtc", &pdev->dev, 271 info->rtc_dev = devm_rtc_device_register(&pdev->dev, "max8998-rtc",
271 &max8998_rtc_ops, THIS_MODULE); 272 &max8998_rtc_ops, THIS_MODULE);
272 273
273 if (IS_ERR(info->rtc_dev)) { 274 if (IS_ERR(info->rtc_dev)) {
@@ -276,8 +277,8 @@ static int max8998_rtc_probe(struct platform_device *pdev)
276 goto out_rtc; 277 goto out_rtc;
277 } 278 }
278 279
279 ret = request_threaded_irq(info->irq, NULL, max8998_rtc_alarm_irq, 0, 280 ret = devm_request_threaded_irq(&pdev->dev, info->irq, NULL,
280 "rtc-alarm0", info); 281 max8998_rtc_alarm_irq, 0, "rtc-alarm0", info);
281 282
282 if (ret < 0) 283 if (ret < 0)
283 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n", 284 dev_err(&pdev->dev, "Failed to request alarm IRQ: %d: %d\n",
@@ -294,20 +295,11 @@ static int max8998_rtc_probe(struct platform_device *pdev)
294 295
295out_rtc: 296out_rtc:
296 platform_set_drvdata(pdev, NULL); 297 platform_set_drvdata(pdev, NULL);
297 kfree(info);
298 return ret; 298 return ret;
299} 299}
300 300
301static int max8998_rtc_remove(struct platform_device *pdev) 301static int max8998_rtc_remove(struct platform_device *pdev)
302{ 302{
303 struct max8998_rtc_info *info = platform_get_drvdata(pdev);
304
305 if (info) {
306 free_irq(info->irq, info);
307 rtc_device_unregister(info->rtc_dev);
308 kfree(info);
309 }
310
311 return 0; 303 return 0;
312} 304}
313 305
diff --git a/drivers/rtc/rtc-mc13xxx.c b/drivers/rtc/rtc-mc13xxx.c
index 2643d8874925..7a8ed27a5f2e 100644
--- a/drivers/rtc/rtc-mc13xxx.c
+++ b/drivers/rtc/rtc-mc13xxx.c
@@ -316,7 +316,7 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
316 struct mc13xxx *mc13xxx; 316 struct mc13xxx *mc13xxx;
317 int rtcrst_pending; 317 int rtcrst_pending;
318 318
319 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 319 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
320 if (!priv) 320 if (!priv)
321 return -ENOMEM; 321 return -ENOMEM;
322 322
@@ -351,8 +351,8 @@ static int __init mc13xxx_rtc_probe(struct platform_device *pdev)
351 351
352 mc13xxx_unlock(mc13xxx); 352 mc13xxx_unlock(mc13xxx);
353 353
354 priv->rtc = rtc_device_register(pdev->name, 354 priv->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
355 &pdev->dev, &mc13xxx_rtc_ops, THIS_MODULE); 355 &mc13xxx_rtc_ops, THIS_MODULE);
356 if (IS_ERR(priv->rtc)) { 356 if (IS_ERR(priv->rtc)) {
357 ret = PTR_ERR(priv->rtc); 357 ret = PTR_ERR(priv->rtc);
358 358
@@ -372,7 +372,6 @@ err_reset_irq_request:
372 mc13xxx_unlock(mc13xxx); 372 mc13xxx_unlock(mc13xxx);
373 373
374 platform_set_drvdata(pdev, NULL); 374 platform_set_drvdata(pdev, NULL);
375 kfree(priv);
376 } 375 }
377 376
378 return ret; 377 return ret;
@@ -384,8 +383,6 @@ static int __exit mc13xxx_rtc_remove(struct platform_device *pdev)
384 383
385 mc13xxx_lock(priv->mc13xxx); 384 mc13xxx_lock(priv->mc13xxx);
386 385
387 rtc_device_unregister(priv->rtc);
388
389 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TODA, priv); 386 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_TODA, priv);
390 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_1HZ, priv); 387 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_1HZ, priv);
391 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_RTCRST, priv); 388 mc13xxx_irq_free(priv->mc13xxx, MC13XXX_IRQ_RTCRST, priv);
@@ -394,8 +391,6 @@ static int __exit mc13xxx_rtc_remove(struct platform_device *pdev)
394 391
395 platform_set_drvdata(pdev, NULL); 392 platform_set_drvdata(pdev, NULL);
396 393
397 kfree(priv);
398
399 return 0; 394 return 0;
400} 395}
401 396
@@ -420,17 +415,7 @@ static struct platform_driver mc13xxx_rtc_driver = {
420 }, 415 },
421}; 416};
422 417
423static int __init mc13xxx_rtc_init(void) 418module_platform_driver_probe(mc13xxx_rtc_driver, &mc13xxx_rtc_probe);
424{
425 return platform_driver_probe(&mc13xxx_rtc_driver, &mc13xxx_rtc_probe);
426}
427module_init(mc13xxx_rtc_init);
428
429static void __exit mc13xxx_rtc_exit(void)
430{
431 platform_driver_unregister(&mc13xxx_rtc_driver);
432}
433module_exit(mc13xxx_rtc_exit);
434 419
435MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); 420MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
436MODULE_DESCRIPTION("RTC driver for Freescale MC13XXX PMIC"); 421MODULE_DESCRIPTION("RTC driver for Freescale MC13XXX PMIC");
diff --git a/drivers/rtc/rtc-msm6242.c b/drivers/rtc/rtc-msm6242.c
index fcb113c11122..771f86a05d14 100644
--- a/drivers/rtc/rtc-msm6242.c
+++ b/drivers/rtc/rtc-msm6242.c
@@ -194,30 +194,28 @@ static const struct rtc_class_ops msm6242_rtc_ops = {
194 .set_time = msm6242_set_time, 194 .set_time = msm6242_set_time,
195}; 195};
196 196
197static int __init msm6242_rtc_probe(struct platform_device *dev) 197static int __init msm6242_rtc_probe(struct platform_device *pdev)
198{ 198{
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; 202 int error;
203 203
204 res = platform_get_resource(dev, IORESOURCE_MEM, 0); 204 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
205 if (!res) 205 if (!res)
206 return -ENODEV; 206 return -ENODEV;
207 207
208 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 208 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
209 if (!priv) 209 if (!priv)
210 return -ENOMEM; 210 return -ENOMEM;
211 211
212 priv->regs = ioremap(res->start, resource_size(res)); 212 priv->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res));
213 if (!priv->regs) { 213 if (!priv->regs)
214 error = -ENOMEM; 214 return -ENOMEM;
215 goto out_free_priv; 215 platform_set_drvdata(pdev, priv);
216 }
217 platform_set_drvdata(dev, priv);
218 216
219 rtc = rtc_device_register("rtc-msm6242", &dev->dev, &msm6242_rtc_ops, 217 rtc = devm_rtc_device_register(&pdev->dev, "rtc-msm6242",
220 THIS_MODULE); 218 &msm6242_rtc_ops, THIS_MODULE);
221 if (IS_ERR(rtc)) { 219 if (IS_ERR(rtc)) {
222 error = PTR_ERR(rtc); 220 error = PTR_ERR(rtc);
223 goto out_unmap; 221 goto out_unmap;
@@ -227,20 +225,12 @@ static int __init msm6242_rtc_probe(struct platform_device *dev)
227 return 0; 225 return 0;
228 226
229out_unmap: 227out_unmap:
230 platform_set_drvdata(dev, NULL); 228 platform_set_drvdata(pdev, NULL);
231 iounmap(priv->regs);
232out_free_priv:
233 kfree(priv);
234 return error; 229 return error;
235} 230}
236 231
237static int __exit msm6242_rtc_remove(struct platform_device *dev) 232static int __exit msm6242_rtc_remove(struct platform_device *pdev)
238{ 233{
239 struct msm6242_priv *priv = platform_get_drvdata(dev);
240
241 rtc_device_unregister(priv->rtc);
242 iounmap(priv->regs);
243 kfree(priv);
244 return 0; 234 return 0;
245} 235}
246 236
@@ -252,18 +242,7 @@ static struct platform_driver msm6242_rtc_driver = {
252 .remove = __exit_p(msm6242_rtc_remove), 242 .remove = __exit_p(msm6242_rtc_remove),
253}; 243};
254 244
255static int __init msm6242_rtc_init(void) 245module_platform_driver_probe(msm6242_rtc_driver, msm6242_rtc_probe);
256{
257 return platform_driver_probe(&msm6242_rtc_driver, msm6242_rtc_probe);
258}
259
260static void __exit msm6242_rtc_fini(void)
261{
262 platform_driver_unregister(&msm6242_rtc_driver);
263}
264
265module_init(msm6242_rtc_init);
266module_exit(msm6242_rtc_fini);
267 246
268MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); 247MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
269MODULE_LICENSE("GPL"); 248MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-mv.c b/drivers/rtc/rtc-mv.c
index 8f87fec27ce7..baab802f2153 100644
--- a/drivers/rtc/rtc-mv.c
+++ b/drivers/rtc/rtc-mv.c
@@ -217,7 +217,7 @@ static const struct rtc_class_ops mv_rtc_alarm_ops = {
217 .alarm_irq_enable = mv_rtc_alarm_irq_enable, 217 .alarm_irq_enable = mv_rtc_alarm_irq_enable,
218}; 218};
219 219
220static int mv_rtc_probe(struct platform_device *pdev) 220static int __init mv_rtc_probe(struct platform_device *pdev)
221{ 221{
222 struct resource *res; 222 struct resource *res;
223 struct rtc_plat_data *pdata; 223 struct rtc_plat_data *pdata;
@@ -272,12 +272,13 @@ static int mv_rtc_probe(struct platform_device *pdev)
272 272
273 if (pdata->irq >= 0) { 273 if (pdata->irq >= 0) {
274 device_init_wakeup(&pdev->dev, 1); 274 device_init_wakeup(&pdev->dev, 1);
275 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 275 pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
276 &mv_rtc_alarm_ops, 276 &mv_rtc_alarm_ops,
277 THIS_MODULE); 277 THIS_MODULE);
278 } else 278 } else {
279 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 279 pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
280 &mv_rtc_ops, THIS_MODULE); 280 &mv_rtc_ops, THIS_MODULE);
281 }
281 if (IS_ERR(pdata->rtc)) { 282 if (IS_ERR(pdata->rtc)) {
282 ret = PTR_ERR(pdata->rtc); 283 ret = PTR_ERR(pdata->rtc);
283 goto out; 284 goto out;
@@ -308,7 +309,6 @@ static int __exit mv_rtc_remove(struct platform_device *pdev)
308 if (pdata->irq >= 0) 309 if (pdata->irq >= 0)
309 device_init_wakeup(&pdev->dev, 0); 310 device_init_wakeup(&pdev->dev, 0);
310 311
311 rtc_device_unregister(pdata->rtc);
312 if (!IS_ERR(pdata->clk)) 312 if (!IS_ERR(pdata->clk))
313 clk_disable_unprepare(pdata->clk); 313 clk_disable_unprepare(pdata->clk);
314 314
@@ -331,18 +331,7 @@ static struct platform_driver mv_rtc_driver = {
331 }, 331 },
332}; 332};
333 333
334static __init int mv_init(void) 334module_platform_driver_probe(mv_rtc_driver, mv_rtc_probe);
335{
336 return platform_driver_probe(&mv_rtc_driver, mv_rtc_probe);
337}
338
339static __exit void mv_exit(void)
340{
341 platform_driver_unregister(&mv_rtc_driver);
342}
343
344module_init(mv_init);
345module_exit(mv_exit);
346 335
347MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>"); 336MODULE_AUTHOR("Saeed Bishara <saeed@marvell.com>");
348MODULE_DESCRIPTION("Marvell RTC driver"); 337MODULE_DESCRIPTION("Marvell RTC driver");
diff --git a/drivers/rtc/rtc-mxc.c b/drivers/rtc/rtc-mxc.c
index 1c3ef7289565..9a3895bc4f4d 100644
--- a/drivers/rtc/rtc-mxc.c
+++ b/drivers/rtc/rtc-mxc.c
@@ -439,7 +439,7 @@ static int mxc_rtc_probe(struct platform_device *pdev)
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 = rtc_device_register(pdev->name, &pdev->dev, &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);
@@ -464,15 +464,13 @@ static int mxc_rtc_remove(struct platform_device *pdev)
464{ 464{
465 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 465 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
466 466
467 rtc_device_unregister(pdata->rtc);
468
469 clk_disable_unprepare(pdata->clk); 467 clk_disable_unprepare(pdata->clk);
470 platform_set_drvdata(pdev, NULL); 468 platform_set_drvdata(pdev, NULL);
471 469
472 return 0; 470 return 0;
473} 471}
474 472
475#ifdef CONFIG_PM 473#ifdef CONFIG_PM_SLEEP
476static int mxc_rtc_suspend(struct device *dev) 474static int mxc_rtc_suspend(struct device *dev)
477{ 475{
478 struct rtc_plat_data *pdata = dev_get_drvdata(dev); 476 struct rtc_plat_data *pdata = dev_get_drvdata(dev);
@@ -492,19 +490,14 @@ static int mxc_rtc_resume(struct device *dev)
492 490
493 return 0; 491 return 0;
494} 492}
495
496static struct dev_pm_ops mxc_rtc_pm_ops = {
497 .suspend = mxc_rtc_suspend,
498 .resume = mxc_rtc_resume,
499};
500#endif 493#endif
501 494
495static SIMPLE_DEV_PM_OPS(mxc_rtc_pm_ops, mxc_rtc_suspend, mxc_rtc_resume);
496
502static struct platform_driver mxc_rtc_driver = { 497static struct platform_driver mxc_rtc_driver = {
503 .driver = { 498 .driver = {
504 .name = "mxc_rtc", 499 .name = "mxc_rtc",
505#ifdef CONFIG_PM
506 .pm = &mxc_rtc_pm_ops, 500 .pm = &mxc_rtc_pm_ops,
507#endif
508 .owner = THIS_MODULE, 501 .owner = THIS_MODULE,
509 }, 502 },
510 .id_table = imx_rtc_devtype, 503 .id_table = imx_rtc_devtype,
diff --git a/drivers/rtc/rtc-nuc900.c b/drivers/rtc/rtc-nuc900.c
index a63680850fef..f5dfb6e5e7d9 100644
--- a/drivers/rtc/rtc-nuc900.c
+++ b/drivers/rtc/rtc-nuc900.c
@@ -222,13 +222,13 @@ static struct rtc_class_ops nuc900_rtc_ops = {
222 .alarm_irq_enable = nuc900_alarm_irq_enable, 222 .alarm_irq_enable = nuc900_alarm_irq_enable,
223}; 223};
224 224
225static int nuc900_rtc_probe(struct platform_device *pdev) 225static int __init nuc900_rtc_probe(struct platform_device *pdev)
226{ 226{
227 struct resource *res; 227 struct resource *res;
228 struct nuc900_rtc *nuc900_rtc; 228 struct nuc900_rtc *nuc900_rtc;
229 int err = 0;
230 229
231 nuc900_rtc = kzalloc(sizeof(struct nuc900_rtc), GFP_KERNEL); 230 nuc900_rtc = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_rtc),
231 GFP_KERNEL);
232 if (!nuc900_rtc) { 232 if (!nuc900_rtc) {
233 dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n"); 233 dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n");
234 return -ENOMEM; 234 return -ENOMEM;
@@ -236,93 +236,51 @@ static int nuc900_rtc_probe(struct platform_device *pdev)
236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
237 if (!res) { 237 if (!res) {
238 dev_err(&pdev->dev, "platform_get_resource failed\n"); 238 dev_err(&pdev->dev, "platform_get_resource failed\n");
239 err = -ENXIO; 239 return -ENXIO;
240 goto fail1;
241 } 240 }
242 241
243 if (!request_mem_region(res->start, resource_size(res), 242 nuc900_rtc->rtc_reg = devm_ioremap_resource(&pdev->dev, res);
244 pdev->name)) { 243 if (IS_ERR(nuc900_rtc->rtc_reg))
245 dev_err(&pdev->dev, "request_mem_region failed\n"); 244 return PTR_ERR(nuc900_rtc->rtc_reg);
246 err = -EBUSY;
247 goto fail1;
248 }
249
250 nuc900_rtc->rtc_reg = ioremap(res->start, resource_size(res));
251 if (!nuc900_rtc->rtc_reg) {
252 dev_err(&pdev->dev, "ioremap rtc_reg failed\n");
253 err = -ENOMEM;
254 goto fail2;
255 }
256 245
257 platform_set_drvdata(pdev, nuc900_rtc); 246 platform_set_drvdata(pdev, nuc900_rtc);
258 247
259 nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev, 248 nuc900_rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
260 &nuc900_rtc_ops, THIS_MODULE); 249 &nuc900_rtc_ops, THIS_MODULE);
261 if (IS_ERR(nuc900_rtc->rtcdev)) { 250 if (IS_ERR(nuc900_rtc->rtcdev)) {
262 dev_err(&pdev->dev, "rtc device register failed\n"); 251 dev_err(&pdev->dev, "rtc device register failed\n");
263 err = PTR_ERR(nuc900_rtc->rtcdev); 252 return PTR_ERR(nuc900_rtc->rtcdev);
264 goto fail3;
265 } 253 }
266 254
267 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24, 255 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24,
268 nuc900_rtc->rtc_reg + REG_RTC_TSSR); 256 nuc900_rtc->rtc_reg + REG_RTC_TSSR);
269 257
270 nuc900_rtc->irq_num = platform_get_irq(pdev, 0); 258 nuc900_rtc->irq_num = platform_get_irq(pdev, 0);
271 if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt, 259 if (devm_request_irq(&pdev->dev, nuc900_rtc->irq_num,
272 0, "nuc900rtc", nuc900_rtc)) { 260 nuc900_rtc_interrupt, 0, "nuc900rtc", nuc900_rtc)) {
273 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n"); 261 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
274 err = -EBUSY; 262 return -EBUSY;
275 goto fail4;
276 } 263 }
277 264
278 return 0; 265 return 0;
279
280fail4: rtc_device_unregister(nuc900_rtc->rtcdev);
281fail3: iounmap(nuc900_rtc->rtc_reg);
282fail2: release_mem_region(res->start, resource_size(res));
283fail1: kfree(nuc900_rtc);
284 return err;
285} 266}
286 267
287static int nuc900_rtc_remove(struct platform_device *pdev) 268static int __exit nuc900_rtc_remove(struct platform_device *pdev)
288{ 269{
289 struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
290 struct resource *res;
291
292 free_irq(nuc900_rtc->irq_num, nuc900_rtc);
293 rtc_device_unregister(nuc900_rtc->rtcdev);
294 iounmap(nuc900_rtc->rtc_reg);
295
296 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
297 release_mem_region(res->start, resource_size(res));
298
299 kfree(nuc900_rtc);
300
301 platform_set_drvdata(pdev, NULL); 270 platform_set_drvdata(pdev, NULL);
302 271
303 return 0; 272 return 0;
304} 273}
305 274
306static struct platform_driver nuc900_rtc_driver = { 275static struct platform_driver nuc900_rtc_driver = {
307 .remove = nuc900_rtc_remove, 276 .remove = __exit_p(nuc900_rtc_remove),
308 .driver = { 277 .driver = {
309 .name = "nuc900-rtc", 278 .name = "nuc900-rtc",
310 .owner = THIS_MODULE, 279 .owner = THIS_MODULE,
311 }, 280 },
312}; 281};
313 282
314static int __init nuc900_rtc_init(void) 283module_platform_driver_probe(nuc900_rtc_driver, nuc900_rtc_probe);
315{
316 return platform_driver_probe(&nuc900_rtc_driver, nuc900_rtc_probe);
317}
318
319static void __exit nuc900_rtc_exit(void)
320{
321 platform_driver_unregister(&nuc900_rtc_driver);
322}
323
324module_init(nuc900_rtc_init);
325module_exit(nuc900_rtc_exit);
326 284
327MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>"); 285MODULE_AUTHOR("Wan ZongShun <mcuos.com@gmail.com>");
328MODULE_DESCRIPTION("nuc910/nuc920 RTC driver"); 286MODULE_DESCRIPTION("nuc910/nuc920 RTC driver");
diff --git a/drivers/rtc/rtc-omap.c b/drivers/rtc/rtc-omap.c
index 600971407aac..4e1bdb832e37 100644
--- a/drivers/rtc/rtc-omap.c
+++ b/drivers/rtc/rtc-omap.c
@@ -324,7 +324,7 @@ MODULE_DEVICE_TABLE(of, omap_rtc_of_match);
324 324
325static int __init omap_rtc_probe(struct platform_device *pdev) 325static int __init omap_rtc_probe(struct platform_device *pdev)
326{ 326{
327 struct resource *res, *mem; 327 struct resource *res;
328 struct rtc_device *rtc; 328 struct rtc_device *rtc;
329 u8 reg, new_ctrl; 329 u8 reg, new_ctrl;
330 const struct platform_device_id *id_entry; 330 const struct platform_device_id *id_entry;
@@ -352,18 +352,9 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
352 return -ENOENT; 352 return -ENOENT;
353 } 353 }
354 354
355 mem = request_mem_region(res->start, resource_size(res), pdev->name); 355 rtc_base = devm_ioremap_resource(&pdev->dev, res);
356 if (!mem) { 356 if (IS_ERR(rtc_base))
357 pr_debug("%s: RTC registers at %08x are not free\n", 357 return PTR_ERR(rtc_base);
358 pdev->name, res->start);
359 return -EBUSY;
360 }
361
362 rtc_base = ioremap(res->start, resource_size(res));
363 if (!rtc_base) {
364 pr_debug("%s: RTC registers can't be mapped\n", pdev->name);
365 goto fail;
366 }
367 358
368 /* Enable the clock/module so that we can access the registers */ 359 /* Enable the clock/module so that we can access the registers */
369 pm_runtime_enable(&pdev->dev); 360 pm_runtime_enable(&pdev->dev);
@@ -375,7 +366,7 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
375 rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG); 366 rtc_writel(KICK1_VALUE, OMAP_RTC_KICK1_REG);
376 } 367 }
377 368
378 rtc = rtc_device_register(pdev->name, &pdev->dev, 369 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
379 &omap_rtc_ops, THIS_MODULE); 370 &omap_rtc_ops, THIS_MODULE);
380 if (IS_ERR(rtc)) { 371 if (IS_ERR(rtc)) {
381 pr_debug("%s: can't register RTC device, err %ld\n", 372 pr_debug("%s: can't register RTC device, err %ld\n",
@@ -383,7 +374,6 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
383 goto fail0; 374 goto fail0;
384 } 375 }
385 platform_set_drvdata(pdev, rtc); 376 platform_set_drvdata(pdev, rtc);
386 dev_set_drvdata(&rtc->dev, mem);
387 377
388 /* clear pending irqs, and set 1/second periodic, 378 /* clear pending irqs, and set 1/second periodic,
389 * which we'll use instead of update irqs 379 * which we'll use instead of update irqs
@@ -401,18 +391,18 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
401 rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG); 391 rtc_write(OMAP_RTC_STATUS_ALARM, OMAP_RTC_STATUS_REG);
402 392
403 /* handle periodic and alarm irqs */ 393 /* handle periodic and alarm irqs */
404 if (request_irq(omap_rtc_timer, rtc_irq, 0, 394 if (devm_request_irq(&pdev->dev, omap_rtc_timer, rtc_irq, 0,
405 dev_name(&rtc->dev), rtc)) { 395 dev_name(&rtc->dev), rtc)) {
406 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n", 396 pr_debug("%s: RTC timer interrupt IRQ%d already claimed\n",
407 pdev->name, omap_rtc_timer); 397 pdev->name, omap_rtc_timer);
408 goto fail1; 398 goto fail0;
409 } 399 }
410 if ((omap_rtc_timer != omap_rtc_alarm) && 400 if ((omap_rtc_timer != omap_rtc_alarm) &&
411 (request_irq(omap_rtc_alarm, rtc_irq, 0, 401 (devm_request_irq(&pdev->dev, omap_rtc_alarm, rtc_irq, 0,
412 dev_name(&rtc->dev), rtc))) { 402 dev_name(&rtc->dev), rtc))) {
413 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n", 403 pr_debug("%s: RTC alarm interrupt IRQ%d already claimed\n",
414 pdev->name, omap_rtc_alarm); 404 pdev->name, omap_rtc_alarm);
415 goto fail2; 405 goto fail0;
416 } 406 }
417 407
418 /* On boards with split power, RTC_ON_NOFF won't reset the RTC */ 408 /* On boards with split power, RTC_ON_NOFF won't reset the RTC */
@@ -446,25 +436,16 @@ static int __init omap_rtc_probe(struct platform_device *pdev)
446 436
447 return 0; 437 return 0;
448 438
449fail2:
450 free_irq(omap_rtc_timer, rtc);
451fail1:
452 rtc_device_unregister(rtc);
453fail0: 439fail0:
454 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) 440 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER))
455 rtc_writel(0, OMAP_RTC_KICK0_REG); 441 rtc_writel(0, OMAP_RTC_KICK0_REG);
456 pm_runtime_put_sync(&pdev->dev); 442 pm_runtime_put_sync(&pdev->dev);
457 pm_runtime_disable(&pdev->dev); 443 pm_runtime_disable(&pdev->dev);
458 iounmap(rtc_base);
459fail:
460 release_mem_region(mem->start, resource_size(mem));
461 return -EIO; 444 return -EIO;
462} 445}
463 446
464static int __exit omap_rtc_remove(struct platform_device *pdev) 447static int __exit omap_rtc_remove(struct platform_device *pdev)
465{ 448{
466 struct rtc_device *rtc = platform_get_drvdata(pdev);
467 struct resource *mem = dev_get_drvdata(&rtc->dev);
468 const struct platform_device_id *id_entry = 449 const struct platform_device_id *id_entry =
469 platform_get_device_id(pdev); 450 platform_get_device_id(pdev);
470 451
@@ -473,12 +454,6 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
473 /* leave rtc running, but disable irqs */ 454 /* leave rtc running, but disable irqs */
474 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 455 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
475 456
476 free_irq(omap_rtc_timer, rtc);
477
478 if (omap_rtc_timer != omap_rtc_alarm)
479 free_irq(omap_rtc_alarm, rtc);
480
481 rtc_device_unregister(rtc);
482 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER)) 457 if (id_entry && (id_entry->driver_data & OMAP_RTC_HAS_KICKER))
483 rtc_writel(0, OMAP_RTC_KICK0_REG); 458 rtc_writel(0, OMAP_RTC_KICK0_REG);
484 459
@@ -486,16 +461,13 @@ static int __exit omap_rtc_remove(struct platform_device *pdev)
486 pm_runtime_put_sync(&pdev->dev); 461 pm_runtime_put_sync(&pdev->dev);
487 pm_runtime_disable(&pdev->dev); 462 pm_runtime_disable(&pdev->dev);
488 463
489 iounmap(rtc_base);
490 release_mem_region(mem->start, resource_size(mem));
491 return 0; 464 return 0;
492} 465}
493 466
494#ifdef CONFIG_PM 467#ifdef CONFIG_PM_SLEEP
495
496static u8 irqstat; 468static u8 irqstat;
497 469
498static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state) 470static int omap_rtc_suspend(struct device *dev)
499{ 471{
500 irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG); 472 irqstat = rtc_read(OMAP_RTC_INTERRUPTS_REG);
501 473
@@ -503,34 +475,32 @@ static int omap_rtc_suspend(struct platform_device *pdev, pm_message_t state)
503 * source, and in fact this enable() call is just saving a flag 475 * source, and in fact this enable() call is just saving a flag
504 * that's never used... 476 * that's never used...
505 */ 477 */
506 if (device_may_wakeup(&pdev->dev)) 478 if (device_may_wakeup(dev))
507 enable_irq_wake(omap_rtc_alarm); 479 enable_irq_wake(omap_rtc_alarm);
508 else 480 else
509 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 481 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
510 482
511 /* Disable the clock/module */ 483 /* Disable the clock/module */
512 pm_runtime_put_sync(&pdev->dev); 484 pm_runtime_put_sync(dev);
513 485
514 return 0; 486 return 0;
515} 487}
516 488
517static int omap_rtc_resume(struct platform_device *pdev) 489static int omap_rtc_resume(struct device *dev)
518{ 490{
519 /* Enable the clock/module so that we can access the registers */ 491 /* Enable the clock/module so that we can access the registers */
520 pm_runtime_get_sync(&pdev->dev); 492 pm_runtime_get_sync(dev);
521 493
522 if (device_may_wakeup(&pdev->dev)) 494 if (device_may_wakeup(dev))
523 disable_irq_wake(omap_rtc_alarm); 495 disable_irq_wake(omap_rtc_alarm);
524 else 496 else
525 rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG); 497 rtc_write(irqstat, OMAP_RTC_INTERRUPTS_REG);
526 return 0; 498 return 0;
527} 499}
528
529#else
530#define omap_rtc_suspend NULL
531#define omap_rtc_resume NULL
532#endif 500#endif
533 501
502static SIMPLE_DEV_PM_OPS(omap_rtc_pm_ops, omap_rtc_suspend, omap_rtc_resume);
503
534static void omap_rtc_shutdown(struct platform_device *pdev) 504static void omap_rtc_shutdown(struct platform_device *pdev)
535{ 505{
536 rtc_write(0, OMAP_RTC_INTERRUPTS_REG); 506 rtc_write(0, OMAP_RTC_INTERRUPTS_REG);
@@ -539,28 +509,17 @@ static void omap_rtc_shutdown(struct platform_device *pdev)
539MODULE_ALIAS("platform:omap_rtc"); 509MODULE_ALIAS("platform:omap_rtc");
540static struct platform_driver omap_rtc_driver = { 510static struct platform_driver omap_rtc_driver = {
541 .remove = __exit_p(omap_rtc_remove), 511 .remove = __exit_p(omap_rtc_remove),
542 .suspend = omap_rtc_suspend,
543 .resume = omap_rtc_resume,
544 .shutdown = omap_rtc_shutdown, 512 .shutdown = omap_rtc_shutdown,
545 .driver = { 513 .driver = {
546 .name = DRIVER_NAME, 514 .name = DRIVER_NAME,
547 .owner = THIS_MODULE, 515 .owner = THIS_MODULE,
516 .pm = &omap_rtc_pm_ops,
548 .of_match_table = of_match_ptr(omap_rtc_of_match), 517 .of_match_table = of_match_ptr(omap_rtc_of_match),
549 }, 518 },
550 .id_table = omap_rtc_devtype, 519 .id_table = omap_rtc_devtype,
551}; 520};
552 521
553static int __init rtc_init(void) 522module_platform_driver_probe(omap_rtc_driver, omap_rtc_probe);
554{
555 return platform_driver_probe(&omap_rtc_driver, omap_rtc_probe);
556}
557module_init(rtc_init);
558
559static void __exit rtc_exit(void)
560{
561 platform_driver_unregister(&omap_rtc_driver);
562}
563module_exit(rtc_exit);
564 523
565MODULE_AUTHOR("George G. Davis (and others)"); 524MODULE_AUTHOR("George G. Davis (and others)");
566MODULE_LICENSE("GPL"); 525MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-palmas.c b/drivers/rtc/rtc-palmas.c
index 59c42986254e..50204d474eb7 100644
--- a/drivers/rtc/rtc-palmas.c
+++ b/drivers/rtc/rtc-palmas.c
@@ -30,6 +30,7 @@
30#include <linux/kernel.h> 30#include <linux/kernel.h>
31#include <linux/mfd/palmas.h> 31#include <linux/mfd/palmas.h>
32#include <linux/module.h> 32#include <linux/module.h>
33#include <linux/of.h>
33#include <linux/rtc.h> 34#include <linux/rtc.h>
34#include <linux/types.h> 35#include <linux/types.h>
35#include <linux/platform_device.h> 36#include <linux/platform_device.h>
@@ -264,7 +265,7 @@ static int palmas_rtc_probe(struct platform_device *pdev)
264 265
265 palmas_rtc->irq = platform_get_irq(pdev, 0); 266 palmas_rtc->irq = platform_get_irq(pdev, 0);
266 267
267 palmas_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 268 palmas_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
268 &palmas_rtc_ops, THIS_MODULE); 269 &palmas_rtc_ops, THIS_MODULE);
269 if (IS_ERR(palmas_rtc->rtc)) { 270 if (IS_ERR(palmas_rtc->rtc)) {
270 ret = PTR_ERR(palmas_rtc->rtc); 271 ret = PTR_ERR(palmas_rtc->rtc);
@@ -272,14 +273,13 @@ static int palmas_rtc_probe(struct platform_device *pdev)
272 return ret; 273 return ret;
273 } 274 }
274 275
275 ret = request_threaded_irq(palmas_rtc->irq, NULL, 276 ret = devm_request_threaded_irq(&pdev->dev, palmas_rtc->irq, NULL,
276 palmas_rtc_interrupt, 277 palmas_rtc_interrupt,
277 IRQF_TRIGGER_LOW | IRQF_ONESHOT | 278 IRQF_TRIGGER_LOW | IRQF_ONESHOT |
278 IRQF_EARLY_RESUME, 279 IRQF_EARLY_RESUME,
279 dev_name(&pdev->dev), palmas_rtc); 280 dev_name(&pdev->dev), palmas_rtc);
280 if (ret < 0) { 281 if (ret < 0) {
281 dev_err(&pdev->dev, "IRQ request failed, err = %d\n", ret); 282 dev_err(&pdev->dev, "IRQ request failed, err = %d\n", ret);
282 rtc_device_unregister(palmas_rtc->rtc);
283 return ret; 283 return ret;
284 } 284 }
285 285
@@ -289,11 +289,7 @@ static int palmas_rtc_probe(struct platform_device *pdev)
289 289
290static int palmas_rtc_remove(struct platform_device *pdev) 290static int palmas_rtc_remove(struct platform_device *pdev)
291{ 291{
292 struct palmas_rtc *palmas_rtc = platform_get_drvdata(pdev);
293
294 palmas_rtc_alarm_irq_enable(&pdev->dev, 0); 292 palmas_rtc_alarm_irq_enable(&pdev->dev, 0);
295 free_irq(palmas_rtc->irq, palmas_rtc);
296 rtc_device_unregister(palmas_rtc->rtc);
297 return 0; 293 return 0;
298} 294}
299 295
@@ -321,6 +317,14 @@ static const struct dev_pm_ops palmas_rtc_pm_ops = {
321 SET_SYSTEM_SLEEP_PM_OPS(palmas_rtc_suspend, palmas_rtc_resume) 317 SET_SYSTEM_SLEEP_PM_OPS(palmas_rtc_suspend, palmas_rtc_resume)
322}; 318};
323 319
320#ifdef CONFIG_OF
321static struct of_device_id of_palmas_rtc_match[] = {
322 { .compatible = "ti,palmas-rtc"},
323 { },
324};
325MODULE_DEVICE_TABLE(of, of_palmas_rtc_match);
326#endif
327
324static struct platform_driver palmas_rtc_driver = { 328static struct platform_driver palmas_rtc_driver = {
325 .probe = palmas_rtc_probe, 329 .probe = palmas_rtc_probe,
326 .remove = palmas_rtc_remove, 330 .remove = palmas_rtc_remove,
@@ -328,6 +332,7 @@ static struct platform_driver palmas_rtc_driver = {
328 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
329 .name = "palmas-rtc", 333 .name = "palmas-rtc",
330 .pm = &palmas_rtc_pm_ops, 334 .pm = &palmas_rtc_pm_ops,
335 .of_match_table = of_match_ptr(of_palmas_rtc_match),
331 }, 336 },
332}; 337};
333 338
diff --git a/drivers/rtc/rtc-pcap.c b/drivers/rtc/rtc-pcap.c
index e0019cd0bf71..539a90b98bc5 100644
--- a/drivers/rtc/rtc-pcap.c
+++ b/drivers/rtc/rtc-pcap.c
@@ -139,13 +139,14 @@ static const struct rtc_class_ops pcap_rtc_ops = {
139 .alarm_irq_enable = pcap_rtc_alarm_irq_enable, 139 .alarm_irq_enable = pcap_rtc_alarm_irq_enable,
140}; 140};
141 141
142static int pcap_rtc_probe(struct platform_device *pdev) 142static int __init pcap_rtc_probe(struct platform_device *pdev)
143{ 143{
144 struct pcap_rtc *pcap_rtc; 144 struct pcap_rtc *pcap_rtc;
145 int timer_irq, alarm_irq; 145 int timer_irq, alarm_irq;
146 int err = -ENOMEM; 146 int err = -ENOMEM;
147 147
148 pcap_rtc = kmalloc(sizeof(struct pcap_rtc), GFP_KERNEL); 148 pcap_rtc = devm_kzalloc(&pdev->dev, sizeof(struct pcap_rtc),
149 GFP_KERNEL);
149 if (!pcap_rtc) 150 if (!pcap_rtc)
150 return err; 151 return err;
151 152
@@ -153,68 +154,46 @@ static int pcap_rtc_probe(struct platform_device *pdev)
153 154
154 platform_set_drvdata(pdev, pcap_rtc); 155 platform_set_drvdata(pdev, pcap_rtc);
155 156
156 pcap_rtc->rtc = rtc_device_register("pcap", &pdev->dev, 157 pcap_rtc->rtc = devm_rtc_device_register(&pdev->dev, "pcap",
157 &pcap_rtc_ops, THIS_MODULE); 158 &pcap_rtc_ops, THIS_MODULE);
158 if (IS_ERR(pcap_rtc->rtc)) { 159 if (IS_ERR(pcap_rtc->rtc)) {
159 err = PTR_ERR(pcap_rtc->rtc); 160 err = PTR_ERR(pcap_rtc->rtc);
160 goto fail_rtc; 161 goto fail;
161 } 162 }
162 163
163
164 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ); 164 timer_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ);
165 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA); 165 alarm_irq = pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA);
166 166
167 err = request_irq(timer_irq, pcap_rtc_irq, 0, "RTC Timer", pcap_rtc); 167 err = devm_request_irq(&pdev->dev, timer_irq, pcap_rtc_irq, 0,
168 "RTC Timer", pcap_rtc);
168 if (err) 169 if (err)
169 goto fail_timer; 170 goto fail;
170 171
171 err = request_irq(alarm_irq, pcap_rtc_irq, 0, "RTC Alarm", pcap_rtc); 172 err = devm_request_irq(&pdev->dev, alarm_irq, pcap_rtc_irq, 0,
173 "RTC Alarm", pcap_rtc);
172 if (err) 174 if (err)
173 goto fail_alarm; 175 goto fail;
174 176
175 return 0; 177 return 0;
176fail_alarm: 178fail:
177 free_irq(timer_irq, pcap_rtc);
178fail_timer:
179 rtc_device_unregister(pcap_rtc->rtc);
180fail_rtc:
181 platform_set_drvdata(pdev, NULL); 179 platform_set_drvdata(pdev, NULL);
182 kfree(pcap_rtc);
183 return err; 180 return err;
184} 181}
185 182
186static int pcap_rtc_remove(struct platform_device *pdev) 183static int __exit pcap_rtc_remove(struct platform_device *pdev)
187{ 184{
188 struct pcap_rtc *pcap_rtc = platform_get_drvdata(pdev);
189
190 free_irq(pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_1HZ), pcap_rtc);
191 free_irq(pcap_to_irq(pcap_rtc->pcap, PCAP_IRQ_TODA), pcap_rtc);
192 rtc_device_unregister(pcap_rtc->rtc);
193 kfree(pcap_rtc);
194
195 return 0; 185 return 0;
196} 186}
197 187
198static struct platform_driver pcap_rtc_driver = { 188static struct platform_driver pcap_rtc_driver = {
199 .remove = pcap_rtc_remove, 189 .remove = __exit_p(pcap_rtc_remove),
200 .driver = { 190 .driver = {
201 .name = "pcap-rtc", 191 .name = "pcap-rtc",
202 .owner = THIS_MODULE, 192 .owner = THIS_MODULE,
203 }, 193 },
204}; 194};
205 195
206static int __init rtc_pcap_init(void) 196module_platform_driver_probe(pcap_rtc_driver, pcap_rtc_probe);
207{
208 return platform_driver_probe(&pcap_rtc_driver, pcap_rtc_probe);
209}
210
211static void __exit rtc_pcap_exit(void)
212{
213 platform_driver_unregister(&pcap_rtc_driver);
214}
215
216module_init(rtc_pcap_init);
217module_exit(rtc_pcap_exit);
218 197
219MODULE_DESCRIPTION("Motorola pcap rtc driver"); 198MODULE_DESCRIPTION("Motorola pcap rtc driver");
220MODULE_AUTHOR("guiming zhuo <gmzhuo@gmail.com>"); 199MODULE_AUTHOR("guiming zhuo <gmzhuo@gmail.com>");
diff --git a/drivers/rtc/rtc-pcf2123.c b/drivers/rtc/rtc-pcf2123.c
index 02b742afa761..796a6c5067dd 100644
--- a/drivers/rtc/rtc-pcf2123.c
+++ b/drivers/rtc/rtc-pcf2123.c
@@ -226,7 +226,8 @@ static int pcf2123_probe(struct spi_device *spi)
226 u8 txbuf[2], rxbuf[2]; 226 u8 txbuf[2], rxbuf[2];
227 int ret, i; 227 int ret, i;
228 228
229 pdata = kzalloc(sizeof(struct pcf2123_plat_data), GFP_KERNEL); 229 pdata = devm_kzalloc(&spi->dev, sizeof(struct pcf2123_plat_data),
230 GFP_KERNEL);
230 if (!pdata) 231 if (!pdata)
231 return -ENOMEM; 232 return -ENOMEM;
232 spi->dev.platform_data = pdata; 233 spi->dev.platform_data = pdata;
@@ -265,6 +266,7 @@ static int pcf2123_probe(struct spi_device *spi)
265 266
266 if (!(rxbuf[0] & 0x20)) { 267 if (!(rxbuf[0] & 0x20)) {
267 dev_err(&spi->dev, "chip not found\n"); 268 dev_err(&spi->dev, "chip not found\n");
269 ret = -ENODEV;
268 goto kfree_exit; 270 goto kfree_exit;
269 } 271 }
270 272
@@ -281,7 +283,7 @@ static int pcf2123_probe(struct spi_device *spi)
281 pcf2123_delay_trec(); 283 pcf2123_delay_trec();
282 284
283 /* Finalize the initialization */ 285 /* Finalize the initialization */
284 rtc = rtc_device_register(pcf2123_driver.driver.name, &spi->dev, 286 rtc = devm_rtc_device_register(&spi->dev, pcf2123_driver.driver.name,
285 &pcf2123_rtc_ops, THIS_MODULE); 287 &pcf2123_rtc_ops, THIS_MODULE);
286 288
287 if (IS_ERR(rtc)) { 289 if (IS_ERR(rtc)) {
@@ -314,7 +316,6 @@ sysfs_exit:
314 device_remove_file(&spi->dev, &pdata->regs[i].attr); 316 device_remove_file(&spi->dev, &pdata->regs[i].attr);
315 317
316kfree_exit: 318kfree_exit:
317 kfree(pdata);
318 spi->dev.platform_data = NULL; 319 spi->dev.platform_data = NULL;
319 return ret; 320 return ret;
320} 321}
@@ -325,15 +326,10 @@ static int pcf2123_remove(struct spi_device *spi)
325 int i; 326 int i;
326 327
327 if (pdata) { 328 if (pdata) {
328 struct rtc_device *rtc = pdata->rtc;
329
330 if (rtc)
331 rtc_device_unregister(rtc);
332 for (i = 0; i < 16; i++) 329 for (i = 0; i < 16; i++)
333 if (pdata->regs[i].name[0]) 330 if (pdata->regs[i].name[0])
334 device_remove_file(&spi->dev, 331 device_remove_file(&spi->dev,
335 &pdata->regs[i].attr); 332 &pdata->regs[i].attr);
336 kfree(pdata);
337 } 333 }
338 334
339 return 0; 335 return 0;
diff --git a/drivers/rtc/rtc-pcf50633.c b/drivers/rtc/rtc-pcf50633.c
index e9f3135d305f..e6b6911c8e05 100644
--- a/drivers/rtc/rtc-pcf50633.c
+++ b/drivers/rtc/rtc-pcf50633.c
@@ -252,20 +252,17 @@ static int pcf50633_rtc_probe(struct platform_device *pdev)
252{ 252{
253 struct pcf50633_rtc *rtc; 253 struct pcf50633_rtc *rtc;
254 254
255 rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); 255 rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
256 if (!rtc) 256 if (!rtc)
257 return -ENOMEM; 257 return -ENOMEM;
258 258
259 rtc->pcf = dev_to_pcf50633(pdev->dev.parent); 259 rtc->pcf = dev_to_pcf50633(pdev->dev.parent);
260 platform_set_drvdata(pdev, rtc); 260 platform_set_drvdata(pdev, rtc);
261 rtc->rtc_dev = rtc_device_register("pcf50633-rtc", &pdev->dev, 261 rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "pcf50633-rtc",
262 &pcf50633_rtc_ops, THIS_MODULE); 262 &pcf50633_rtc_ops, THIS_MODULE);
263 263
264 if (IS_ERR(rtc->rtc_dev)) { 264 if (IS_ERR(rtc->rtc_dev))
265 int ret = PTR_ERR(rtc->rtc_dev); 265 return PTR_ERR(rtc->rtc_dev);
266 kfree(rtc);
267 return ret;
268 }
269 266
270 pcf50633_register_irq(rtc->pcf, PCF50633_IRQ_ALARM, 267 pcf50633_register_irq(rtc->pcf, PCF50633_IRQ_ALARM,
271 pcf50633_rtc_irq, rtc); 268 pcf50633_rtc_irq, rtc);
@@ -277,12 +274,8 @@ static int pcf50633_rtc_remove(struct platform_device *pdev)
277 struct pcf50633_rtc *rtc; 274 struct pcf50633_rtc *rtc;
278 275
279 rtc = platform_get_drvdata(pdev); 276 rtc = platform_get_drvdata(pdev);
280
281 pcf50633_free_irq(rtc->pcf, PCF50633_IRQ_ALARM); 277 pcf50633_free_irq(rtc->pcf, PCF50633_IRQ_ALARM);
282 278
283 rtc_device_unregister(rtc->rtc_dev);
284 kfree(rtc);
285
286 return 0; 279 return 0;
287} 280}
288 281
diff --git a/drivers/rtc/rtc-pcf8523.c b/drivers/rtc/rtc-pcf8523.c
index 889e3160e701..305c9515e5bb 100644
--- a/drivers/rtc/rtc-pcf8523.c
+++ b/drivers/rtc/rtc-pcf8523.c
@@ -307,7 +307,7 @@ static int pcf8523_probe(struct i2c_client *client,
307 if (err < 0) 307 if (err < 0)
308 return err; 308 return err;
309 309
310 pcf->rtc = rtc_device_register(DRIVER_NAME, &client->dev, 310 pcf->rtc = devm_rtc_device_register(&client->dev, DRIVER_NAME,
311 &pcf8523_rtc_ops, THIS_MODULE); 311 &pcf8523_rtc_ops, THIS_MODULE);
312 if (IS_ERR(pcf->rtc)) 312 if (IS_ERR(pcf->rtc))
313 return PTR_ERR(pcf->rtc); 313 return PTR_ERR(pcf->rtc);
@@ -319,10 +319,6 @@ static int pcf8523_probe(struct i2c_client *client,
319 319
320static int pcf8523_remove(struct i2c_client *client) 320static int pcf8523_remove(struct i2c_client *client)
321{ 321{
322 struct pcf8523 *pcf = i2c_get_clientdata(client);
323
324 rtc_device_unregister(pcf->rtc);
325
326 return 0; 322 return 0;
327} 323}
328 324
diff --git a/drivers/rtc/rtc-pcf8563.c b/drivers/rtc/rtc-pcf8563.c
index f7daf18a112e..97b354a26a44 100644
--- a/drivers/rtc/rtc-pcf8563.c
+++ b/drivers/rtc/rtc-pcf8563.c
@@ -245,14 +245,13 @@ static int pcf8563_probe(struct i2c_client *client,
245{ 245{
246 struct pcf8563 *pcf8563; 246 struct pcf8563 *pcf8563;
247 247
248 int err = 0;
249
250 dev_dbg(&client->dev, "%s\n", __func__); 248 dev_dbg(&client->dev, "%s\n", __func__);
251 249
252 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 250 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
253 return -ENODEV; 251 return -ENODEV;
254 252
255 pcf8563 = kzalloc(sizeof(struct pcf8563), GFP_KERNEL); 253 pcf8563 = devm_kzalloc(&client->dev, sizeof(struct pcf8563),
254 GFP_KERNEL);
256 if (!pcf8563) 255 if (!pcf8563)
257 return -ENOMEM; 256 return -ENOMEM;
258 257
@@ -260,31 +259,18 @@ static int pcf8563_probe(struct i2c_client *client,
260 259
261 i2c_set_clientdata(client, pcf8563); 260 i2c_set_clientdata(client, pcf8563);
262 261
263 pcf8563->rtc = rtc_device_register(pcf8563_driver.driver.name, 262 pcf8563->rtc = devm_rtc_device_register(&client->dev,
264 &client->dev, &pcf8563_rtc_ops, THIS_MODULE); 263 pcf8563_driver.driver.name,
264 &pcf8563_rtc_ops, THIS_MODULE);
265 265
266 if (IS_ERR(pcf8563->rtc)) { 266 if (IS_ERR(pcf8563->rtc))
267 err = PTR_ERR(pcf8563->rtc); 267 return PTR_ERR(pcf8563->rtc);
268 goto exit_kfree;
269 }
270 268
271 return 0; 269 return 0;
272
273exit_kfree:
274 kfree(pcf8563);
275
276 return err;
277} 270}
278 271
279static int pcf8563_remove(struct i2c_client *client) 272static int pcf8563_remove(struct i2c_client *client)
280{ 273{
281 struct pcf8563 *pcf8563 = i2c_get_clientdata(client);
282
283 if (pcf8563->rtc)
284 rtc_device_unregister(pcf8563->rtc);
285
286 kfree(pcf8563);
287
288 return 0; 274 return 0;
289} 275}
290 276
diff --git a/drivers/rtc/rtc-pcf8583.c b/drivers/rtc/rtc-pcf8583.c
index 5f97c61247d5..95886dcf4a39 100644
--- a/drivers/rtc/rtc-pcf8583.c
+++ b/drivers/rtc/rtc-pcf8583.c
@@ -268,39 +268,29 @@ static int pcf8583_probe(struct i2c_client *client,
268 const struct i2c_device_id *id) 268 const struct i2c_device_id *id)
269{ 269{
270 struct pcf8583 *pcf8583; 270 struct pcf8583 *pcf8583;
271 int err;
272 271
273 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) 272 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C))
274 return -ENODEV; 273 return -ENODEV;
275 274
276 pcf8583 = kzalloc(sizeof(struct pcf8583), GFP_KERNEL); 275 pcf8583 = devm_kzalloc(&client->dev, sizeof(struct pcf8583),
276 GFP_KERNEL);
277 if (!pcf8583) 277 if (!pcf8583)
278 return -ENOMEM; 278 return -ENOMEM;
279 279
280 i2c_set_clientdata(client, pcf8583); 280 i2c_set_clientdata(client, pcf8583);
281 281
282 pcf8583->rtc = rtc_device_register(pcf8583_driver.driver.name, 282 pcf8583->rtc = devm_rtc_device_register(&client->dev,
283 &client->dev, &pcf8583_rtc_ops, THIS_MODULE); 283 pcf8583_driver.driver.name,
284 &pcf8583_rtc_ops, THIS_MODULE);
284 285
285 if (IS_ERR(pcf8583->rtc)) { 286 if (IS_ERR(pcf8583->rtc))
286 err = PTR_ERR(pcf8583->rtc); 287 return PTR_ERR(pcf8583->rtc);
287 goto exit_kfree;
288 }
289 288
290 return 0; 289 return 0;
291
292exit_kfree:
293 kfree(pcf8583);
294 return err;
295} 290}
296 291
297static int pcf8583_remove(struct i2c_client *client) 292static int pcf8583_remove(struct i2c_client *client)
298{ 293{
299 struct pcf8583 *pcf8583 = i2c_get_clientdata(client);
300
301 if (pcf8583->rtc)
302 rtc_device_unregister(pcf8583->rtc);
303 kfree(pcf8583);
304 return 0; 294 return 0;
305} 295}
306 296
diff --git a/drivers/rtc/rtc-ps3.c b/drivers/rtc/rtc-ps3.c
index 968133ce1ee8..4bb825bb5804 100644
--- a/drivers/rtc/rtc-ps3.c
+++ b/drivers/rtc/rtc-ps3.c
@@ -62,7 +62,7 @@ static int __init ps3_rtc_probe(struct platform_device *dev)
62{ 62{
63 struct rtc_device *rtc; 63 struct rtc_device *rtc;
64 64
65 rtc = rtc_device_register("rtc-ps3", &dev->dev, &ps3_rtc_ops, 65 rtc = devm_rtc_device_register(&dev->dev, "rtc-ps3", &ps3_rtc_ops,
66 THIS_MODULE); 66 THIS_MODULE);
67 if (IS_ERR(rtc)) 67 if (IS_ERR(rtc))
68 return PTR_ERR(rtc); 68 return PTR_ERR(rtc);
@@ -73,7 +73,6 @@ static int __init ps3_rtc_probe(struct platform_device *dev)
73 73
74static int __exit ps3_rtc_remove(struct platform_device *dev) 74static int __exit ps3_rtc_remove(struct platform_device *dev)
75{ 75{
76 rtc_device_unregister(platform_get_drvdata(dev));
77 return 0; 76 return 0;
78} 77}
79 78
@@ -85,18 +84,7 @@ static struct platform_driver ps3_rtc_driver = {
85 .remove = __exit_p(ps3_rtc_remove), 84 .remove = __exit_p(ps3_rtc_remove),
86}; 85};
87 86
88static int __init ps3_rtc_init(void) 87module_platform_driver_probe(ps3_rtc_driver, ps3_rtc_probe);
89{
90 return platform_driver_probe(&ps3_rtc_driver, ps3_rtc_probe);
91}
92
93static void __exit ps3_rtc_fini(void)
94{
95 platform_driver_unregister(&ps3_rtc_driver);
96}
97
98module_init(ps3_rtc_init);
99module_exit(ps3_rtc_fini);
100 88
101MODULE_AUTHOR("Sony Corporation"); 89MODULE_AUTHOR("Sony Corporation");
102MODULE_LICENSE("GPL"); 90MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-puv3.c b/drivers/rtc/rtc-puv3.c
index 0407e13d4de4..72f437170d2e 100644
--- a/drivers/rtc/rtc-puv3.c
+++ b/drivers/rtc/rtc-puv3.c
@@ -207,14 +207,14 @@ static const struct rtc_class_ops puv3_rtcops = {
207 .proc = puv3_rtc_proc, 207 .proc = puv3_rtc_proc,
208}; 208};
209 209
210static void puv3_rtc_enable(struct platform_device *pdev, int en) 210static void puv3_rtc_enable(struct device *dev, int en)
211{ 211{
212 if (!en) { 212 if (!en) {
213 writel(readl(RTC_RTSR) & ~RTC_RTSR_HZE, RTC_RTSR); 213 writel(readl(RTC_RTSR) & ~RTC_RTSR_HZE, RTC_RTSR);
214 } else { 214 } else {
215 /* re-enable the device, and check it is ok */ 215 /* re-enable the device, and check it is ok */
216 if ((readl(RTC_RTSR) & RTC_RTSR_HZE) == 0) { 216 if ((readl(RTC_RTSR) & RTC_RTSR_HZE) == 0) {
217 dev_info(&pdev->dev, "rtc disabled, re-enabling\n"); 217 dev_info(dev, "rtc disabled, re-enabling\n");
218 writel(readl(RTC_RTSR) | RTC_RTSR_HZE, RTC_RTSR); 218 writel(readl(RTC_RTSR) | RTC_RTSR_HZE, RTC_RTSR);
219 } 219 }
220 } 220 }
@@ -276,7 +276,7 @@ static int puv3_rtc_probe(struct platform_device *pdev)
276 goto err_nores; 276 goto err_nores;
277 } 277 }
278 278
279 puv3_rtc_enable(pdev, 1); 279 puv3_rtc_enable(&pdev->dev, 1);
280 280
281 /* register RTC and exit */ 281 /* register RTC and exit */
282 rtc = rtc_device_register("pkunity", &pdev->dev, &puv3_rtcops, 282 rtc = rtc_device_register("pkunity", &pdev->dev, &puv3_rtcops,
@@ -296,44 +296,41 @@ static int puv3_rtc_probe(struct platform_device *pdev)
296 return 0; 296 return 0;
297 297
298 err_nortc: 298 err_nortc:
299 puv3_rtc_enable(pdev, 0); 299 puv3_rtc_enable(&pdev->dev, 0);
300 release_resource(puv3_rtc_mem); 300 release_resource(puv3_rtc_mem);
301 301
302 err_nores: 302 err_nores:
303 return ret; 303 return ret;
304} 304}
305 305
306#ifdef CONFIG_PM 306#ifdef CONFIG_PM_SLEEP
307
308static int ticnt_save; 307static int ticnt_save;
309 308
310static int puv3_rtc_suspend(struct platform_device *pdev, pm_message_t state) 309static int puv3_rtc_suspend(struct device *dev)
311{ 310{
312 /* save RTAR for anyone using periodic interrupts */ 311 /* save RTAR for anyone using periodic interrupts */
313 ticnt_save = readl(RTC_RTAR); 312 ticnt_save = readl(RTC_RTAR);
314 puv3_rtc_enable(pdev, 0); 313 puv3_rtc_enable(dev, 0);
315 return 0; 314 return 0;
316} 315}
317 316
318static int puv3_rtc_resume(struct platform_device *pdev) 317static int puv3_rtc_resume(struct device *dev)
319{ 318{
320 puv3_rtc_enable(pdev, 1); 319 puv3_rtc_enable(dev, 1);
321 writel(ticnt_save, RTC_RTAR); 320 writel(ticnt_save, RTC_RTAR);
322 return 0; 321 return 0;
323} 322}
324#else
325#define puv3_rtc_suspend NULL
326#define puv3_rtc_resume NULL
327#endif 323#endif
328 324
325static SIMPLE_DEV_PM_OPS(puv3_rtc_pm_ops, puv3_rtc_suspend, puv3_rtc_resume);
326
329static struct platform_driver puv3_rtc_driver = { 327static struct platform_driver puv3_rtc_driver = {
330 .probe = puv3_rtc_probe, 328 .probe = puv3_rtc_probe,
331 .remove = puv3_rtc_remove, 329 .remove = puv3_rtc_remove,
332 .suspend = puv3_rtc_suspend,
333 .resume = puv3_rtc_resume,
334 .driver = { 330 .driver = {
335 .name = "PKUnity-v3-RTC", 331 .name = "PKUnity-v3-RTC",
336 .owner = THIS_MODULE, 332 .owner = THIS_MODULE,
333 .pm = &puv3_rtc_pm_ops,
337 } 334 }
338}; 335};
339 336
diff --git a/drivers/rtc/rtc-pxa.c b/drivers/rtc/rtc-pxa.c
index 03c85ee719a7..ed037ae91c5f 100644
--- a/drivers/rtc/rtc-pxa.c
+++ b/drivers/rtc/rtc-pxa.c
@@ -416,7 +416,7 @@ static struct of_device_id pxa_rtc_dt_ids[] = {
416MODULE_DEVICE_TABLE(of, pxa_rtc_dt_ids); 416MODULE_DEVICE_TABLE(of, pxa_rtc_dt_ids);
417#endif 417#endif
418 418
419#ifdef CONFIG_PM 419#ifdef CONFIG_PM_SLEEP
420static int pxa_rtc_suspend(struct device *dev) 420static int pxa_rtc_suspend(struct device *dev)
421{ 421{
422 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev); 422 struct pxa_rtc *pxa_rtc = dev_get_drvdata(dev);
@@ -434,36 +434,20 @@ static int pxa_rtc_resume(struct device *dev)
434 disable_irq_wake(pxa_rtc->irq_Alrm); 434 disable_irq_wake(pxa_rtc->irq_Alrm);
435 return 0; 435 return 0;
436} 436}
437
438static const struct dev_pm_ops pxa_rtc_pm_ops = {
439 .suspend = pxa_rtc_suspend,
440 .resume = pxa_rtc_resume,
441};
442#endif 437#endif
443 438
439static SIMPLE_DEV_PM_OPS(pxa_rtc_pm_ops, pxa_rtc_suspend, pxa_rtc_resume);
440
444static struct platform_driver pxa_rtc_driver = { 441static struct platform_driver pxa_rtc_driver = {
445 .remove = __exit_p(pxa_rtc_remove), 442 .remove = __exit_p(pxa_rtc_remove),
446 .driver = { 443 .driver = {
447 .name = "pxa-rtc", 444 .name = "pxa-rtc",
448 .of_match_table = of_match_ptr(pxa_rtc_dt_ids), 445 .of_match_table = of_match_ptr(pxa_rtc_dt_ids),
449#ifdef CONFIG_PM
450 .pm = &pxa_rtc_pm_ops, 446 .pm = &pxa_rtc_pm_ops,
451#endif
452 }, 447 },
453}; 448};
454 449
455static int __init pxa_rtc_init(void) 450module_platform_driver_probe(pxa_rtc_driver, pxa_rtc_probe);
456{
457 return platform_driver_probe(&pxa_rtc_driver, pxa_rtc_probe);
458}
459
460static void __exit pxa_rtc_exit(void)
461{
462 platform_driver_unregister(&pxa_rtc_driver);
463}
464
465module_init(pxa_rtc_init);
466module_exit(pxa_rtc_exit);
467 451
468MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>"); 452MODULE_AUTHOR("Robert Jarzmik <robert.jarzmik@free.fr>");
469MODULE_DESCRIPTION("PXA27x/PXA3xx Realtime Clock Driver (RTC)"); 453MODULE_DESCRIPTION("PXA27x/PXA3xx Realtime Clock Driver (RTC)");
diff --git a/drivers/rtc/rtc-r9701.c b/drivers/rtc/rtc-r9701.c
index 7726f4a4f2d0..feeedbd82000 100644
--- a/drivers/rtc/rtc-r9701.c
+++ b/drivers/rtc/rtc-r9701.c
@@ -154,21 +154,18 @@ static int r9701_probe(struct spi_device *spi)
154 } 154 }
155 } 155 }
156 156
157 rtc = rtc_device_register("r9701", 157 rtc = devm_rtc_device_register(&spi->dev, "r9701",
158 &spi->dev, &r9701_rtc_ops, THIS_MODULE); 158 &r9701_rtc_ops, THIS_MODULE);
159 if (IS_ERR(rtc)) 159 if (IS_ERR(rtc))
160 return PTR_ERR(rtc); 160 return PTR_ERR(rtc);
161 161
162 dev_set_drvdata(&spi->dev, rtc); 162 spi_set_drvdata(spi, rtc);
163 163
164 return 0; 164 return 0;
165} 165}
166 166
167static int r9701_remove(struct spi_device *spi) 167static int r9701_remove(struct spi_device *spi)
168{ 168{
169 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
170
171 rtc_device_unregister(rtc);
172 return 0; 169 return 0;
173} 170}
174 171
diff --git a/drivers/rtc/rtc-rc5t583.c b/drivers/rtc/rtc-rc5t583.c
index eb3194d664a8..8eabcf51b35a 100644
--- a/drivers/rtc/rtc-rc5t583.c
+++ b/drivers/rtc/rtc-rc5t583.c
@@ -256,7 +256,7 @@ static int rc5t583_rtc_probe(struct platform_device *pdev)
256 } 256 }
257 device_init_wakeup(&pdev->dev, 1); 257 device_init_wakeup(&pdev->dev, 1);
258 258
259 ricoh_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 259 ricoh_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
260 &rc5t583_rtc_ops, THIS_MODULE); 260 &rc5t583_rtc_ops, THIS_MODULE);
261 if (IS_ERR(ricoh_rtc->rtc)) { 261 if (IS_ERR(ricoh_rtc->rtc)) {
262 ret = PTR_ERR(ricoh_rtc->rtc); 262 ret = PTR_ERR(ricoh_rtc->rtc);
@@ -276,13 +276,10 @@ static int rc5t583_rtc_remove(struct platform_device *pdev)
276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev); 276 struct rc5t583_rtc *rc5t583_rtc = dev_get_drvdata(&pdev->dev);
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
280 rtc_device_unregister(rc5t583_rtc->rtc);
281 return 0; 279 return 0;
282} 280}
283 281
284#ifdef CONFIG_PM_SLEEP 282#ifdef CONFIG_PM_SLEEP
285
286static int rc5t583_rtc_suspend(struct device *dev) 283static int rc5t583_rtc_suspend(struct device *dev)
287{ 284{
288 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent); 285 struct rc5t583 *rc5t583 = dev_get_drvdata(dev->parent);
@@ -304,24 +301,18 @@ static int rc5t583_rtc_resume(struct device *dev)
304 return regmap_write(rc5t583->regmap, RC5T583_RTC_CTL1, 301 return regmap_write(rc5t583->regmap, RC5T583_RTC_CTL1,
305 rc5t583_rtc->irqen); 302 rc5t583_rtc->irqen);
306} 303}
307
308static const struct dev_pm_ops rc5t583_rtc_pm_ops = {
309 .suspend = rc5t583_rtc_suspend,
310 .resume = rc5t583_rtc_resume,
311};
312
313#define DEV_PM_OPS (&rc5t583_rtc_pm_ops)
314#else
315#define DEV_PM_OPS NULL
316#endif 304#endif
317 305
306static SIMPLE_DEV_PM_OPS(rc5t583_rtc_pm_ops, rc5t583_rtc_suspend,
307 rc5t583_rtc_resume);
308
318static struct platform_driver rc5t583_rtc_driver = { 309static struct platform_driver rc5t583_rtc_driver = {
319 .probe = rc5t583_rtc_probe, 310 .probe = rc5t583_rtc_probe,
320 .remove = rc5t583_rtc_remove, 311 .remove = rc5t583_rtc_remove,
321 .driver = { 312 .driver = {
322 .owner = THIS_MODULE, 313 .owner = THIS_MODULE,
323 .name = "rtc-rc5t583", 314 .name = "rtc-rc5t583",
324 .pm = DEV_PM_OPS, 315 .pm = &rc5t583_rtc_pm_ops,
325 }, 316 },
326}; 317};
327 318
diff --git a/drivers/rtc/rtc-rp5c01.c b/drivers/rtc/rtc-rp5c01.c
index 359da6d020b9..873c689f01c3 100644
--- a/drivers/rtc/rtc-rp5c01.c
+++ b/drivers/rtc/rtc-rp5c01.c
@@ -230,15 +230,13 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
230 if (!res) 230 if (!res)
231 return -ENODEV; 231 return -ENODEV;
232 232
233 priv = kzalloc(sizeof(*priv), GFP_KERNEL); 233 priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
234 if (!priv) 234 if (!priv)
235 return -ENOMEM; 235 return -ENOMEM;
236 236
237 priv->regs = ioremap(res->start, resource_size(res)); 237 priv->regs = devm_ioremap(&dev->dev, res->start, resource_size(res));
238 if (!priv->regs) { 238 if (!priv->regs)
239 error = -ENOMEM; 239 return -ENOMEM;
240 goto out_free_priv;
241 }
242 240
243 sysfs_bin_attr_init(&priv->nvram_attr); 241 sysfs_bin_attr_init(&priv->nvram_attr);
244 priv->nvram_attr.attr.name = "nvram"; 242 priv->nvram_attr.attr.name = "nvram";
@@ -251,27 +249,22 @@ static int __init rp5c01_rtc_probe(struct platform_device *dev)
251 249
252 platform_set_drvdata(dev, priv); 250 platform_set_drvdata(dev, priv);
253 251
254 rtc = rtc_device_register("rtc-rp5c01", &dev->dev, &rp5c01_rtc_ops, 252 rtc = devm_rtc_device_register(&dev->dev, "rtc-rp5c01", &rp5c01_rtc_ops,
255 THIS_MODULE); 253 THIS_MODULE);
256 if (IS_ERR(rtc)) { 254 if (IS_ERR(rtc)) {
257 error = PTR_ERR(rtc); 255 error = PTR_ERR(rtc);
258 goto out_unmap; 256 goto out;
259 } 257 }
260 priv->rtc = rtc; 258 priv->rtc = rtc;
261 259
262 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr); 260 error = sysfs_create_bin_file(&dev->dev.kobj, &priv->nvram_attr);
263 if (error) 261 if (error)
264 goto out_unregister; 262 goto out;
265 263
266 return 0; 264 return 0;
267 265
268out_unregister: 266out:
269 rtc_device_unregister(rtc);
270out_unmap:
271 platform_set_drvdata(dev, NULL); 267 platform_set_drvdata(dev, NULL);
272 iounmap(priv->regs);
273out_free_priv:
274 kfree(priv);
275 return error; 268 return error;
276} 269}
277 270
@@ -280,9 +273,6 @@ static int __exit rp5c01_rtc_remove(struct platform_device *dev)
280 struct rp5c01_priv *priv = platform_get_drvdata(dev); 273 struct rp5c01_priv *priv = platform_get_drvdata(dev);
281 274
282 sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr); 275 sysfs_remove_bin_file(&dev->dev.kobj, &priv->nvram_attr);
283 rtc_device_unregister(priv->rtc);
284 iounmap(priv->regs);
285 kfree(priv);
286 return 0; 276 return 0;
287} 277}
288 278
@@ -294,18 +284,7 @@ static struct platform_driver rp5c01_rtc_driver = {
294 .remove = __exit_p(rp5c01_rtc_remove), 284 .remove = __exit_p(rp5c01_rtc_remove),
295}; 285};
296 286
297static int __init rp5c01_rtc_init(void) 287module_platform_driver_probe(rp5c01_rtc_driver, rp5c01_rtc_probe);
298{
299 return platform_driver_probe(&rp5c01_rtc_driver, rp5c01_rtc_probe);
300}
301
302static void __exit rp5c01_rtc_fini(void)
303{
304 platform_driver_unregister(&rp5c01_rtc_driver);
305}
306
307module_init(rp5c01_rtc_init);
308module_exit(rp5c01_rtc_fini);
309 288
310MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>"); 289MODULE_AUTHOR("Geert Uytterhoeven <geert@linux-m68k.org>");
311MODULE_LICENSE("GPL"); 290MODULE_LICENSE("GPL");
diff --git a/drivers/rtc/rtc-rs5c313.c b/drivers/rtc/rtc-rs5c313.c
index d98ea5b759c8..8089fc63e403 100644
--- a/drivers/rtc/rtc-rs5c313.c
+++ b/drivers/rtc/rtc-rs5c313.c
@@ -367,7 +367,7 @@ static const struct rtc_class_ops rs5c313_rtc_ops = {
367 367
368static int rs5c313_rtc_probe(struct platform_device *pdev) 368static int rs5c313_rtc_probe(struct platform_device *pdev)
369{ 369{
370 struct rtc_device *rtc = rtc_device_register("rs5c313", &pdev->dev, 370 struct rtc_device *rtc = devm_rtc_device_register(&pdev->dev, "rs5c313",
371 &rs5c313_rtc_ops, THIS_MODULE); 371 &rs5c313_rtc_ops, THIS_MODULE);
372 372
373 if (IS_ERR(rtc)) 373 if (IS_ERR(rtc))
@@ -380,10 +380,6 @@ static int rs5c313_rtc_probe(struct platform_device *pdev)
380 380
381static int rs5c313_rtc_remove(struct platform_device *pdev) 381static int rs5c313_rtc_remove(struct platform_device *pdev)
382{ 382{
383 struct rtc_device *rtc = platform_get_drvdata( pdev );
384
385 rtc_device_unregister(rtc);
386
387 return 0; 383 return 0;
388} 384}
389 385
diff --git a/drivers/rtc/rtc-rs5c348.c b/drivers/rtc/rtc-rs5c348.c
index 72ef10be8662..2c37df3586c7 100644
--- a/drivers/rtc/rtc-rs5c348.c
+++ b/drivers/rtc/rtc-rs5c348.c
@@ -158,7 +158,8 @@ static int rs5c348_probe(struct spi_device *spi)
158 struct rtc_device *rtc; 158 struct rtc_device *rtc;
159 struct rs5c348_plat_data *pdata; 159 struct rs5c348_plat_data *pdata;
160 160
161 pdata = kzalloc(sizeof(struct rs5c348_plat_data), GFP_KERNEL); 161 pdata = devm_kzalloc(&spi->dev, sizeof(struct rs5c348_plat_data),
162 GFP_KERNEL);
162 if (!pdata) 163 if (!pdata)
163 return -ENOMEM; 164 return -ENOMEM;
164 spi->dev.platform_data = pdata; 165 spi->dev.platform_data = pdata;
@@ -202,7 +203,7 @@ static int rs5c348_probe(struct spi_device *spi)
202 if (ret & RS5C348_BIT_24H) 203 if (ret & RS5C348_BIT_24H)
203 pdata->rtc_24h = 1; 204 pdata->rtc_24h = 1;
204 205
205 rtc = rtc_device_register(rs5c348_driver.driver.name, &spi->dev, 206 rtc = devm_rtc_device_register(&spi->dev, rs5c348_driver.driver.name,
206 &rs5c348_rtc_ops, THIS_MODULE); 207 &rs5c348_rtc_ops, THIS_MODULE);
207 208
208 if (IS_ERR(rtc)) { 209 if (IS_ERR(rtc)) {
@@ -214,18 +215,11 @@ static int rs5c348_probe(struct spi_device *spi)
214 215
215 return 0; 216 return 0;
216 kfree_exit: 217 kfree_exit:
217 kfree(pdata);
218 return ret; 218 return ret;
219} 219}
220 220
221static int rs5c348_remove(struct spi_device *spi) 221static int rs5c348_remove(struct spi_device *spi)
222{ 222{
223 struct rs5c348_plat_data *pdata = spi->dev.platform_data;
224 struct rtc_device *rtc = pdata->rtc;
225
226 if (rtc)
227 rtc_device_unregister(rtc);
228 kfree(pdata);
229 return 0; 223 return 0;
230} 224}
231 225
diff --git a/drivers/rtc/rtc-rs5c372.c b/drivers/rtc/rtc-rs5c372.c
index 581739f40097..224d634322b4 100644
--- a/drivers/rtc/rtc-rs5c372.c
+++ b/drivers/rtc/rtc-rs5c372.c
@@ -579,7 +579,9 @@ static int rs5c372_probe(struct i2c_client *client,
579 } 579 }
580 } 580 }
581 581
582 if (!(rs5c372 = kzalloc(sizeof(struct rs5c372), GFP_KERNEL))) { 582 rs5c372 = devm_kzalloc(&client->dev, sizeof(struct rs5c372),
583 GFP_KERNEL);
584 if (!rs5c372) {
583 err = -ENOMEM; 585 err = -ENOMEM;
584 goto exit; 586 goto exit;
585 } 587 }
@@ -594,7 +596,7 @@ static int rs5c372_probe(struct i2c_client *client,
594 596
595 err = rs5c_get_regs(rs5c372); 597 err = rs5c_get_regs(rs5c372);
596 if (err < 0) 598 if (err < 0)
597 goto exit_kfree; 599 goto exit;
598 600
599 /* clock may be set for am/pm or 24 hr time */ 601 /* clock may be set for am/pm or 24 hr time */
600 switch (rs5c372->type) { 602 switch (rs5c372->type) {
@@ -617,7 +619,7 @@ static int rs5c372_probe(struct i2c_client *client,
617 break; 619 break;
618 default: 620 default:
619 dev_err(&client->dev, "unknown RTC type\n"); 621 dev_err(&client->dev, "unknown RTC type\n");
620 goto exit_kfree; 622 goto exit;
621 } 623 }
622 624
623 /* if the oscillator lost power and no other software (like 625 /* if the oscillator lost power and no other software (like
@@ -629,7 +631,7 @@ static int rs5c372_probe(struct i2c_client *client,
629 err = rs5c_oscillator_setup(rs5c372); 631 err = rs5c_oscillator_setup(rs5c372);
630 if (unlikely(err < 0)) { 632 if (unlikely(err < 0)) {
631 dev_err(&client->dev, "setup error\n"); 633 dev_err(&client->dev, "setup error\n");
632 goto exit_kfree; 634 goto exit;
633 } 635 }
634 636
635 if (rs5c372_get_datetime(client, &tm) < 0) 637 if (rs5c372_get_datetime(client, &tm) < 0)
@@ -648,38 +650,28 @@ static int rs5c372_probe(struct i2c_client *client,
648 ); 650 );
649 651
650 /* REVISIT use client->irq to register alarm irq ... */ 652 /* REVISIT use client->irq to register alarm irq ... */
651 653 rs5c372->rtc = devm_rtc_device_register(&client->dev,
652 rs5c372->rtc = rtc_device_register(rs5c372_driver.driver.name, 654 rs5c372_driver.driver.name,
653 &client->dev, &rs5c372_rtc_ops, THIS_MODULE); 655 &rs5c372_rtc_ops, THIS_MODULE);
654 656
655 if (IS_ERR(rs5c372->rtc)) { 657 if (IS_ERR(rs5c372->rtc)) {
656 err = PTR_ERR(rs5c372->rtc); 658 err = PTR_ERR(rs5c372->rtc);
657 goto exit_kfree; 659 goto exit;
658 } 660 }
659 661
660 err = rs5c_sysfs_register(&client->dev); 662 err = rs5c_sysfs_register(&client->dev);
661 if (err) 663 if (err)
662 goto exit_devreg; 664 goto exit;
663 665
664 return 0; 666 return 0;
665 667
666exit_devreg:
667 rtc_device_unregister(rs5c372->rtc);
668
669exit_kfree:
670 kfree(rs5c372);
671
672exit: 668exit:
673 return err; 669 return err;
674} 670}
675 671
676static int rs5c372_remove(struct i2c_client *client) 672static int rs5c372_remove(struct i2c_client *client)
677{ 673{
678 struct rs5c372 *rs5c372 = i2c_get_clientdata(client);
679
680 rtc_device_unregister(rs5c372->rtc);
681 rs5c_sysfs_unregister(&client->dev); 674 rs5c_sysfs_unregister(&client->dev);
682 kfree(rs5c372);
683 return 0; 675 return 0;
684} 676}
685 677
diff --git a/drivers/rtc/rtc-rv3029c2.c b/drivers/rtc/rtc-rv3029c2.c
index f8ee8ad7825e..5032c24ec159 100644
--- a/drivers/rtc/rtc-rv3029c2.c
+++ b/drivers/rtc/rtc-rv3029c2.c
@@ -395,9 +395,8 @@ static int rv3029c2_probe(struct i2c_client *client,
395 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL)) 395 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_EMUL))
396 return -ENODEV; 396 return -ENODEV;
397 397
398 rtc = rtc_device_register(client->name, 398 rtc = devm_rtc_device_register(&client->dev, client->name,
399 &client->dev, &rv3029c2_rtc_ops, 399 &rv3029c2_rtc_ops, THIS_MODULE);
400 THIS_MODULE);
401 400
402 if (IS_ERR(rtc)) 401 if (IS_ERR(rtc))
403 return PTR_ERR(rtc); 402 return PTR_ERR(rtc);
@@ -407,23 +406,14 @@ static int rv3029c2_probe(struct i2c_client *client,
407 rc = rv3029c2_i2c_get_sr(client, buf); 406 rc = rv3029c2_i2c_get_sr(client, buf);
408 if (rc < 0) { 407 if (rc < 0) {
409 dev_err(&client->dev, "reading status failed\n"); 408 dev_err(&client->dev, "reading status failed\n");
410 goto exit_unregister; 409 return rc;
411 } 410 }
412 411
413 return 0; 412 return 0;
414
415exit_unregister:
416 rtc_device_unregister(rtc);
417
418 return rc;
419} 413}
420 414
421static int rv3029c2_remove(struct i2c_client *client) 415static int rv3029c2_remove(struct i2c_client *client)
422{ 416{
423 struct rtc_device *rtc = i2c_get_clientdata(client);
424
425 rtc_device_unregister(rtc);
426
427 return 0; 417 return 0;
428} 418}
429 419
diff --git a/drivers/rtc/rtc-rx4581.c b/drivers/rtc/rtc-rx4581.c
index 599ec73ec886..84eb08d65d30 100644
--- a/drivers/rtc/rtc-rx4581.c
+++ b/drivers/rtc/rtc-rx4581.c
@@ -273,20 +273,17 @@ static int rx4581_probe(struct spi_device *spi)
273 if (res != 0) 273 if (res != 0)
274 return res; 274 return res;
275 275
276 rtc = rtc_device_register("rx4581", 276 rtc = devm_rtc_device_register(&spi->dev, "rx4581",
277 &spi->dev, &rx4581_rtc_ops, THIS_MODULE); 277 &rx4581_rtc_ops, THIS_MODULE);
278 if (IS_ERR(rtc)) 278 if (IS_ERR(rtc))
279 return PTR_ERR(rtc); 279 return PTR_ERR(rtc);
280 280
281 dev_set_drvdata(&spi->dev, rtc); 281 spi_set_drvdata(spi, rtc);
282 return 0; 282 return 0;
283} 283}
284 284
285static int rx4581_remove(struct spi_device *spi) 285static int rx4581_remove(struct spi_device *spi)
286{ 286{
287 struct rtc_device *rtc = dev_get_drvdata(&spi->dev);
288
289 rtc_device_unregister(rtc);
290 return 0; 287 return 0;
291} 288}
292 289
diff --git a/drivers/rtc/rtc-rx8581.c b/drivers/rtc/rtc-rx8581.c
index b0c272658fa2..07f3037b18f4 100644
--- a/drivers/rtc/rtc-rx8581.c
+++ b/drivers/rtc/rtc-rx8581.c
@@ -240,8 +240,8 @@ static int rx8581_probe(struct i2c_client *client,
240 240
241 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 241 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
242 242
243 rtc = rtc_device_register(rx8581_driver.driver.name, 243 rtc = devm_rtc_device_register(&client->dev, rx8581_driver.driver.name,
244 &client->dev, &rx8581_rtc_ops, THIS_MODULE); 244 &rx8581_rtc_ops, THIS_MODULE);
245 245
246 if (IS_ERR(rtc)) 246 if (IS_ERR(rtc))
247 return PTR_ERR(rtc); 247 return PTR_ERR(rtc);
@@ -253,10 +253,6 @@ static int rx8581_probe(struct i2c_client *client,
253 253
254static int rx8581_remove(struct i2c_client *client) 254static int rx8581_remove(struct i2c_client *client)
255{ 255{
256 struct rtc_device *rtc = i2c_get_clientdata(client);
257
258 rtc_device_unregister(rtc);
259
260 return 0; 256 return 0;
261} 257}
262 258
diff --git a/drivers/rtc/rtc-s35390a.c b/drivers/rtc/rtc-s35390a.c
index 8a092325188d..f40afdd0e5f5 100644
--- a/drivers/rtc/rtc-s35390a.c
+++ b/drivers/rtc/rtc-s35390a.c
@@ -338,7 +338,8 @@ static int s35390a_probe(struct i2c_client *client,
338 goto exit; 338 goto exit;
339 } 339 }
340 340
341 s35390a = kzalloc(sizeof(struct s35390a), GFP_KERNEL); 341 s35390a = devm_kzalloc(&client->dev, sizeof(struct s35390a),
342 GFP_KERNEL);
342 if (!s35390a) { 343 if (!s35390a) {
343 err = -ENOMEM; 344 err = -ENOMEM;
344 goto exit; 345 goto exit;
@@ -386,8 +387,9 @@ static int s35390a_probe(struct i2c_client *client,
386 387
387 device_set_wakeup_capable(&client->dev, 1); 388 device_set_wakeup_capable(&client->dev, 1);
388 389
389 s35390a->rtc = rtc_device_register(s35390a_driver.driver.name, 390 s35390a->rtc = devm_rtc_device_register(&client->dev,
390 &client->dev, &s35390a_rtc_ops, THIS_MODULE); 391 s35390a_driver.driver.name,
392 &s35390a_rtc_ops, THIS_MODULE);
391 393
392 if (IS_ERR(s35390a->rtc)) { 394 if (IS_ERR(s35390a->rtc)) {
393 err = PTR_ERR(s35390a->rtc); 395 err = PTR_ERR(s35390a->rtc);
@@ -399,7 +401,6 @@ exit_dummy:
399 for (i = 1; i < 8; ++i) 401 for (i = 1; i < 8; ++i)
400 if (s35390a->client[i]) 402 if (s35390a->client[i])
401 i2c_unregister_device(s35390a->client[i]); 403 i2c_unregister_device(s35390a->client[i]);
402 kfree(s35390a);
403 404
404exit: 405exit:
405 return err; 406 return err;
@@ -408,15 +409,12 @@ exit:
408static int s35390a_remove(struct i2c_client *client) 409static int s35390a_remove(struct i2c_client *client)
409{ 410{
410 unsigned int i; 411 unsigned int i;
411
412 struct s35390a *s35390a = i2c_get_clientdata(client); 412 struct s35390a *s35390a = i2c_get_clientdata(client);
413
413 for (i = 1; i < 8; ++i) 414 for (i = 1; i < 8; ++i)
414 if (s35390a->client[i]) 415 if (s35390a->client[i])
415 i2c_unregister_device(s35390a->client[i]); 416 i2c_unregister_device(s35390a->client[i]);
416 417
417 rtc_device_unregister(s35390a->rtc);
418 kfree(s35390a);
419
420 return 0; 418 return 0;
421} 419}
422 420
diff --git a/drivers/rtc/rtc-s3c.c b/drivers/rtc/rtc-s3c.c
index fb994e9ddc15..8e96c00936be 100644
--- a/drivers/rtc/rtc-s3c.c
+++ b/drivers/rtc/rtc-s3c.c
@@ -51,7 +51,6 @@ static struct clk *rtc_clk;
51static void __iomem *s3c_rtc_base; 51static void __iomem *s3c_rtc_base;
52static int s3c_rtc_alarmno = NO_IRQ; 52static int s3c_rtc_alarmno = NO_IRQ;
53static int s3c_rtc_tickno = NO_IRQ; 53static int s3c_rtc_tickno = NO_IRQ;
54static bool wake_en;
55static enum s3c_cpu_type s3c_rtc_cpu_type; 54static enum s3c_cpu_type s3c_rtc_cpu_type;
56 55
57static DEFINE_SPINLOCK(s3c_rtc_pie_lock); 56static DEFINE_SPINLOCK(s3c_rtc_pie_lock);
@@ -423,13 +422,11 @@ static void s3c_rtc_enable(struct platform_device *pdev, int en)
423 422
424static int s3c_rtc_remove(struct platform_device *dev) 423static int s3c_rtc_remove(struct platform_device *dev)
425{ 424{
426 struct rtc_device *rtc = platform_get_drvdata(dev);
427
428 platform_set_drvdata(dev, NULL); 425 platform_set_drvdata(dev, NULL);
429 rtc_device_unregister(rtc);
430 426
431 s3c_rtc_setaie(&dev->dev, 0); 427 s3c_rtc_setaie(&dev->dev, 0);
432 428
429 clk_unprepare(rtc_clk);
433 rtc_clk = NULL; 430 rtc_clk = NULL;
434 431
435 return 0; 432 return 0;
@@ -498,7 +495,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
498 return ret; 495 return ret;
499 } 496 }
500 497
501 clk_enable(rtc_clk); 498 clk_prepare_enable(rtc_clk);
502 499
503 /* check to see if everything is setup correctly */ 500 /* check to see if everything is setup correctly */
504 501
@@ -511,7 +508,7 @@ static int s3c_rtc_probe(struct platform_device *pdev)
511 508
512 /* register RTC and exit */ 509 /* register RTC and exit */
513 510
514 rtc = rtc_device_register("s3c", &pdev->dev, &s3c_rtcops, 511 rtc = devm_rtc_device_register(&pdev->dev, "s3c", &s3c_rtcops,
515 THIS_MODULE); 512 THIS_MODULE);
516 513
517 if (IS_ERR(rtc)) { 514 if (IS_ERR(rtc)) {
@@ -574,23 +571,24 @@ static int s3c_rtc_probe(struct platform_device *pdev)
574 571
575 err_alarm_irq: 572 err_alarm_irq:
576 platform_set_drvdata(pdev, NULL); 573 platform_set_drvdata(pdev, NULL);
577 rtc_device_unregister(rtc);
578 574
579 err_nortc: 575 err_nortc:
580 s3c_rtc_enable(pdev, 0); 576 s3c_rtc_enable(pdev, 0);
581 clk_disable(rtc_clk); 577 clk_disable_unprepare(rtc_clk);
582 578
583 return ret; 579 return ret;
584} 580}
585 581
586#ifdef CONFIG_PM 582#ifdef CONFIG_PM_SLEEP
587
588/* RTC Power management control */ 583/* RTC Power management control */
589 584
590static int ticnt_save, ticnt_en_save; 585static int ticnt_save, ticnt_en_save;
586static bool wake_en;
591 587
592static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state) 588static int s3c_rtc_suspend(struct device *dev)
593{ 589{
590 struct platform_device *pdev = to_platform_device(dev);
591
594 clk_enable(rtc_clk); 592 clk_enable(rtc_clk);
595 /* save TICNT for anyone using periodic interrupts */ 593 /* save TICNT for anyone using periodic interrupts */
596 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT); 594 ticnt_save = readb(s3c_rtc_base + S3C2410_TICNT);
@@ -600,19 +598,20 @@ static int s3c_rtc_suspend(struct platform_device *pdev, pm_message_t state)
600 } 598 }
601 s3c_rtc_enable(pdev, 0); 599 s3c_rtc_enable(pdev, 0);
602 600
603 if (device_may_wakeup(&pdev->dev) && !wake_en) { 601 if (device_may_wakeup(dev) && !wake_en) {
604 if (enable_irq_wake(s3c_rtc_alarmno) == 0) 602 if (enable_irq_wake(s3c_rtc_alarmno) == 0)
605 wake_en = true; 603 wake_en = true;
606 else 604 else
607 dev_err(&pdev->dev, "enable_irq_wake failed\n"); 605 dev_err(dev, "enable_irq_wake failed\n");
608 } 606 }
609 clk_disable(rtc_clk); 607 clk_disable(rtc_clk);
610 608
611 return 0; 609 return 0;
612} 610}
613 611
614static int s3c_rtc_resume(struct platform_device *pdev) 612static int s3c_rtc_resume(struct device *dev)
615{ 613{
614 struct platform_device *pdev = to_platform_device(dev);
616 unsigned int tmp; 615 unsigned int tmp;
617 616
618 clk_enable(rtc_clk); 617 clk_enable(rtc_clk);
@@ -623,7 +622,7 @@ static int s3c_rtc_resume(struct platform_device *pdev)
623 writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON); 622 writew(tmp | ticnt_en_save, s3c_rtc_base + S3C2410_RTCCON);
624 } 623 }
625 624
626 if (device_may_wakeup(&pdev->dev) && wake_en) { 625 if (device_may_wakeup(dev) && wake_en) {
627 disable_irq_wake(s3c_rtc_alarmno); 626 disable_irq_wake(s3c_rtc_alarmno);
628 wake_en = false; 627 wake_en = false;
629 } 628 }
@@ -631,11 +630,10 @@ static int s3c_rtc_resume(struct platform_device *pdev)
631 630
632 return 0; 631 return 0;
633} 632}
634#else
635#define s3c_rtc_suspend NULL
636#define s3c_rtc_resume NULL
637#endif 633#endif
638 634
635static SIMPLE_DEV_PM_OPS(s3c_rtc_pm_ops, s3c_rtc_suspend, s3c_rtc_resume);
636
639#ifdef CONFIG_OF 637#ifdef CONFIG_OF
640static struct s3c_rtc_drv_data s3c_rtc_drv_data_array[] = { 638static struct s3c_rtc_drv_data s3c_rtc_drv_data_array[] = {
641 [TYPE_S3C2410] = { TYPE_S3C2410 }, 639 [TYPE_S3C2410] = { TYPE_S3C2410 },
@@ -685,12 +683,11 @@ MODULE_DEVICE_TABLE(platform, s3c_rtc_driver_ids);
685static struct platform_driver s3c_rtc_driver = { 683static struct platform_driver s3c_rtc_driver = {
686 .probe = s3c_rtc_probe, 684 .probe = s3c_rtc_probe,
687 .remove = s3c_rtc_remove, 685 .remove = s3c_rtc_remove,
688 .suspend = s3c_rtc_suspend,
689 .resume = s3c_rtc_resume,
690 .id_table = s3c_rtc_driver_ids, 686 .id_table = s3c_rtc_driver_ids,
691 .driver = { 687 .driver = {
692 .name = "s3c-rtc", 688 .name = "s3c-rtc",
693 .owner = THIS_MODULE, 689 .owner = THIS_MODULE,
690 .pm = &s3c_rtc_pm_ops,
694 .of_match_table = of_match_ptr(s3c_rtc_dt_match), 691 .of_match_table = of_match_ptr(s3c_rtc_dt_match),
695 }, 692 },
696}; 693};
diff --git a/drivers/rtc/rtc-sa1100.c b/drivers/rtc/rtc-sa1100.c
index 5ec5036df0bc..00605601dbf7 100644
--- a/drivers/rtc/rtc-sa1100.c
+++ b/drivers/rtc/rtc-sa1100.c
@@ -234,14 +234,13 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
234 if (irq_1hz < 0 || irq_alarm < 0) 234 if (irq_1hz < 0 || irq_alarm < 0)
235 return -ENODEV; 235 return -ENODEV;
236 236
237 info = kzalloc(sizeof(struct sa1100_rtc), GFP_KERNEL); 237 info = devm_kzalloc(&pdev->dev, sizeof(struct sa1100_rtc), GFP_KERNEL);
238 if (!info) 238 if (!info)
239 return -ENOMEM; 239 return -ENOMEM;
240 info->clk = clk_get(&pdev->dev, NULL); 240 info->clk = devm_clk_get(&pdev->dev, NULL);
241 if (IS_ERR(info->clk)) { 241 if (IS_ERR(info->clk)) {
242 dev_err(&pdev->dev, "failed to find rtc clock source\n"); 242 dev_err(&pdev->dev, "failed to find rtc clock source\n");
243 ret = PTR_ERR(info->clk); 243 return PTR_ERR(info->clk);
244 goto err_clk;
245 } 244 }
246 info->irq_1hz = irq_1hz; 245 info->irq_1hz = irq_1hz;
247 info->irq_alarm = irq_alarm; 246 info->irq_alarm = irq_alarm;
@@ -268,8 +267,8 @@ static int sa1100_rtc_probe(struct platform_device *pdev)
268 267
269 device_init_wakeup(&pdev->dev, 1); 268 device_init_wakeup(&pdev->dev, 1);
270 269
271 rtc = rtc_device_register(pdev->name, &pdev->dev, &sa1100_rtc_ops, 270 rtc = devm_rtc_device_register(&pdev->dev, pdev->name, &sa1100_rtc_ops,
272 THIS_MODULE); 271 THIS_MODULE);
273 272
274 if (IS_ERR(rtc)) { 273 if (IS_ERR(rtc)) {
275 ret = PTR_ERR(rtc); 274 ret = PTR_ERR(rtc);
@@ -306,9 +305,6 @@ err_dev:
306 clk_disable_unprepare(info->clk); 305 clk_disable_unprepare(info->clk);
307err_enable_clk: 306err_enable_clk:
308 platform_set_drvdata(pdev, NULL); 307 platform_set_drvdata(pdev, NULL);
309 clk_put(info->clk);
310err_clk:
311 kfree(info);
312 return ret; 308 return ret;
313} 309}
314 310
@@ -317,17 +313,14 @@ static int sa1100_rtc_remove(struct platform_device *pdev)
317 struct sa1100_rtc *info = platform_get_drvdata(pdev); 313 struct sa1100_rtc *info = platform_get_drvdata(pdev);
318 314
319 if (info) { 315 if (info) {
320 rtc_device_unregister(info->rtc);
321 clk_disable_unprepare(info->clk); 316 clk_disable_unprepare(info->clk);
322 clk_put(info->clk);
323 platform_set_drvdata(pdev, NULL); 317 platform_set_drvdata(pdev, NULL);
324 kfree(info);
325 } 318 }
326 319
327 return 0; 320 return 0;
328} 321}
329 322
330#ifdef CONFIG_PM 323#ifdef CONFIG_PM_SLEEP
331static int sa1100_rtc_suspend(struct device *dev) 324static int sa1100_rtc_suspend(struct device *dev)
332{ 325{
333 struct sa1100_rtc *info = dev_get_drvdata(dev); 326 struct sa1100_rtc *info = dev_get_drvdata(dev);
@@ -343,13 +336,11 @@ static int sa1100_rtc_resume(struct device *dev)
343 disable_irq_wake(info->irq_alarm); 336 disable_irq_wake(info->irq_alarm);
344 return 0; 337 return 0;
345} 338}
346
347static const struct dev_pm_ops sa1100_rtc_pm_ops = {
348 .suspend = sa1100_rtc_suspend,
349 .resume = sa1100_rtc_resume,
350};
351#endif 339#endif
352 340
341static SIMPLE_DEV_PM_OPS(sa1100_rtc_pm_ops, sa1100_rtc_suspend,
342 sa1100_rtc_resume);
343
353#ifdef CONFIG_OF 344#ifdef CONFIG_OF
354static struct of_device_id sa1100_rtc_dt_ids[] = { 345static struct of_device_id sa1100_rtc_dt_ids[] = {
355 { .compatible = "mrvl,sa1100-rtc", }, 346 { .compatible = "mrvl,sa1100-rtc", },
@@ -364,9 +355,7 @@ static struct platform_driver sa1100_rtc_driver = {
364 .remove = sa1100_rtc_remove, 355 .remove = sa1100_rtc_remove,
365 .driver = { 356 .driver = {
366 .name = "sa1100-rtc", 357 .name = "sa1100-rtc",
367#ifdef CONFIG_PM
368 .pm = &sa1100_rtc_pm_ops, 358 .pm = &sa1100_rtc_pm_ops,
369#endif
370 .of_match_table = of_match_ptr(sa1100_rtc_dt_ids), 359 .of_match_table = of_match_ptr(sa1100_rtc_dt_ids),
371 }, 360 },
372}; 361};
diff --git a/drivers/rtc/rtc-sh.c b/drivers/rtc/rtc-sh.c
index e55a7635ae5f..8d5bd2e36776 100644
--- a/drivers/rtc/rtc-sh.c
+++ b/drivers/rtc/rtc-sh.c
@@ -790,6 +790,7 @@ static void sh_rtc_set_irq_wake(struct device *dev, int enabled)
790 } 790 }
791} 791}
792 792
793#ifdef CONFIG_PM_SLEEP
793static int sh_rtc_suspend(struct device *dev) 794static int sh_rtc_suspend(struct device *dev)
794{ 795{
795 if (device_may_wakeup(dev)) 796 if (device_may_wakeup(dev))
@@ -805,33 +806,20 @@ static int sh_rtc_resume(struct device *dev)
805 806
806 return 0; 807 return 0;
807} 808}
809#endif
808 810
809static const struct dev_pm_ops sh_rtc_dev_pm_ops = { 811static SIMPLE_DEV_PM_OPS(sh_rtc_pm_ops, sh_rtc_suspend, sh_rtc_resume);
810 .suspend = sh_rtc_suspend,
811 .resume = sh_rtc_resume,
812};
813 812
814static struct platform_driver sh_rtc_platform_driver = { 813static struct platform_driver sh_rtc_platform_driver = {
815 .driver = { 814 .driver = {
816 .name = DRV_NAME, 815 .name = DRV_NAME,
817 .owner = THIS_MODULE, 816 .owner = THIS_MODULE,
818 .pm = &sh_rtc_dev_pm_ops, 817 .pm = &sh_rtc_pm_ops,
819 }, 818 },
820 .remove = __exit_p(sh_rtc_remove), 819 .remove = __exit_p(sh_rtc_remove),
821}; 820};
822 821
823static int __init sh_rtc_init(void) 822module_platform_driver_probe(sh_rtc_platform_driver, sh_rtc_probe);
824{
825 return platform_driver_probe(&sh_rtc_platform_driver, sh_rtc_probe);
826}
827
828static void __exit sh_rtc_exit(void)
829{
830 platform_driver_unregister(&sh_rtc_platform_driver);
831}
832
833module_init(sh_rtc_init);
834module_exit(sh_rtc_exit);
835 823
836MODULE_DESCRIPTION("SuperH on-chip RTC driver"); 824MODULE_DESCRIPTION("SuperH on-chip RTC driver");
837MODULE_VERSION(DRV_VERSION); 825MODULE_VERSION(DRV_VERSION);
diff --git a/drivers/rtc/rtc-snvs.c b/drivers/rtc/rtc-snvs.c
index f7d90703db5e..b04f09a1df2a 100644
--- a/drivers/rtc/rtc-snvs.c
+++ b/drivers/rtc/rtc-snvs.c
@@ -283,7 +283,7 @@ static int snvs_rtc_probe(struct platform_device *pdev)
283 return ret; 283 return ret;
284 } 284 }
285 285
286 data->rtc = rtc_device_register(pdev->name, &pdev->dev, 286 data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
287 &snvs_rtc_ops, THIS_MODULE); 287 &snvs_rtc_ops, THIS_MODULE);
288 if (IS_ERR(data->rtc)) { 288 if (IS_ERR(data->rtc)) {
289 ret = PTR_ERR(data->rtc); 289 ret = PTR_ERR(data->rtc);
@@ -296,10 +296,6 @@ static int snvs_rtc_probe(struct platform_device *pdev)
296 296
297static int snvs_rtc_remove(struct platform_device *pdev) 297static int snvs_rtc_remove(struct platform_device *pdev)
298{ 298{
299 struct snvs_rtc_data *data = platform_get_drvdata(pdev);
300
301 rtc_device_unregister(data->rtc);
302
303 return 0; 299 return 0;
304} 300}
305 301
diff --git a/drivers/rtc/rtc-spear.c b/drivers/rtc/rtc-spear.c
index a18c3192ed40..574359c48f65 100644
--- a/drivers/rtc/rtc-spear.c
+++ b/drivers/rtc/rtc-spear.c
@@ -400,8 +400,8 @@ static int spear_rtc_probe(struct platform_device *pdev)
400 spin_lock_init(&config->lock); 400 spin_lock_init(&config->lock);
401 platform_set_drvdata(pdev, config); 401 platform_set_drvdata(pdev, config);
402 402
403 config->rtc = rtc_device_register(pdev->name, &pdev->dev, 403 config->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
404 &spear_rtc_ops, THIS_MODULE); 404 &spear_rtc_ops, THIS_MODULE);
405 if (IS_ERR(config->rtc)) { 405 if (IS_ERR(config->rtc)) {
406 dev_err(&pdev->dev, "can't register RTC device, err %ld\n", 406 dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
407 PTR_ERR(config->rtc)); 407 PTR_ERR(config->rtc));
@@ -427,7 +427,6 @@ static int spear_rtc_remove(struct platform_device *pdev)
427{ 427{
428 struct spear_rtc_config *config = platform_get_drvdata(pdev); 428 struct spear_rtc_config *config = platform_get_drvdata(pdev);
429 429
430 rtc_device_unregister(config->rtc);
431 spear_rtc_disable_interrupt(config); 430 spear_rtc_disable_interrupt(config);
432 clk_disable_unprepare(config->clk); 431 clk_disable_unprepare(config->clk);
433 device_init_wakeup(&pdev->dev, 0); 432 device_init_wakeup(&pdev->dev, 0);
@@ -435,10 +434,10 @@ static int spear_rtc_remove(struct platform_device *pdev)
435 return 0; 434 return 0;
436} 435}
437 436
438#ifdef CONFIG_PM 437#ifdef CONFIG_PM_SLEEP
439 438static int spear_rtc_suspend(struct device *dev)
440static int spear_rtc_suspend(struct platform_device *pdev, pm_message_t state)
441{ 439{
440 struct platform_device *pdev = to_platform_device(dev);
442 struct spear_rtc_config *config = platform_get_drvdata(pdev); 441 struct spear_rtc_config *config = platform_get_drvdata(pdev);
443 int irq; 442 int irq;
444 443
@@ -454,8 +453,9 @@ static int spear_rtc_suspend(struct platform_device *pdev, pm_message_t state)
454 return 0; 453 return 0;
455} 454}
456 455
457static int spear_rtc_resume(struct platform_device *pdev) 456static int spear_rtc_resume(struct device *dev)
458{ 457{
458 struct platform_device *pdev = to_platform_device(dev);
459 struct spear_rtc_config *config = platform_get_drvdata(pdev); 459 struct spear_rtc_config *config = platform_get_drvdata(pdev);
460 int irq; 460 int irq;
461 461
@@ -473,12 +473,10 @@ static int spear_rtc_resume(struct platform_device *pdev)
473 473
474 return 0; 474 return 0;
475} 475}
476
477#else
478#define spear_rtc_suspend NULL
479#define spear_rtc_resume NULL
480#endif 476#endif
481 477
478static SIMPLE_DEV_PM_OPS(spear_rtc_pm_ops, spear_rtc_suspend, spear_rtc_resume);
479
482static void spear_rtc_shutdown(struct platform_device *pdev) 480static void spear_rtc_shutdown(struct platform_device *pdev)
483{ 481{
484 struct spear_rtc_config *config = platform_get_drvdata(pdev); 482 struct spear_rtc_config *config = platform_get_drvdata(pdev);
@@ -498,11 +496,10 @@ MODULE_DEVICE_TABLE(of, spear_rtc_id_table);
498static struct platform_driver spear_rtc_driver = { 496static struct platform_driver spear_rtc_driver = {
499 .probe = spear_rtc_probe, 497 .probe = spear_rtc_probe,
500 .remove = spear_rtc_remove, 498 .remove = spear_rtc_remove,
501 .suspend = spear_rtc_suspend,
502 .resume = spear_rtc_resume,
503 .shutdown = spear_rtc_shutdown, 499 .shutdown = spear_rtc_shutdown,
504 .driver = { 500 .driver = {
505 .name = "rtc-spear", 501 .name = "rtc-spear",
502 .pm = &spear_rtc_pm_ops,
506 .of_match_table = of_match_ptr(spear_rtc_id_table), 503 .of_match_table = of_match_ptr(spear_rtc_id_table),
507 }, 504 },
508}; 505};
diff --git a/drivers/rtc/rtc-starfire.c b/drivers/rtc/rtc-starfire.c
index 5be98bfd7ed3..987b5ec0ae56 100644
--- a/drivers/rtc/rtc-starfire.c
+++ b/drivers/rtc/rtc-starfire.c
@@ -39,8 +39,10 @@ static const struct rtc_class_ops starfire_rtc_ops = {
39 39
40static int __init starfire_rtc_probe(struct platform_device *pdev) 40static int __init starfire_rtc_probe(struct platform_device *pdev)
41{ 41{
42 struct rtc_device *rtc = rtc_device_register("starfire", &pdev->dev, 42 struct rtc_device *rtc;
43 &starfire_rtc_ops, THIS_MODULE); 43
44 rtc = devm_rtc_device_register(&pdev->dev, "starfire",
45 &starfire_rtc_ops, THIS_MODULE);
44 if (IS_ERR(rtc)) 46 if (IS_ERR(rtc))
45 return PTR_ERR(rtc); 47 return PTR_ERR(rtc);
46 48
@@ -51,10 +53,6 @@ static int __init starfire_rtc_probe(struct platform_device *pdev)
51 53
52static int __exit starfire_rtc_remove(struct platform_device *pdev) 54static int __exit starfire_rtc_remove(struct platform_device *pdev)
53{ 55{
54 struct rtc_device *rtc = platform_get_drvdata(pdev);
55
56 rtc_device_unregister(rtc);
57
58 return 0; 56 return 0;
59} 57}
60 58
@@ -66,15 +64,4 @@ static struct platform_driver starfire_rtc_driver = {
66 .remove = __exit_p(starfire_rtc_remove), 64 .remove = __exit_p(starfire_rtc_remove),
67}; 65};
68 66
69static int __init starfire_rtc_init(void) 67module_platform_driver_probe(starfire_rtc_driver, starfire_rtc_probe);
70{
71 return platform_driver_probe(&starfire_rtc_driver, starfire_rtc_probe);
72}
73
74static void __exit starfire_rtc_exit(void)
75{
76 platform_driver_unregister(&starfire_rtc_driver);
77}
78
79module_init(starfire_rtc_init);
80module_exit(starfire_rtc_exit);
diff --git a/drivers/rtc/rtc-stk17ta8.c b/drivers/rtc/rtc-stk17ta8.c
index 7e4a6f65cb91..af5e97e3f272 100644
--- a/drivers/rtc/rtc-stk17ta8.c
+++ b/drivers/rtc/rtc-stk17ta8.c
@@ -336,14 +336,13 @@ static int stk17ta8_rtc_probe(struct platform_device *pdev)
336 } 336 }
337 } 337 }
338 338
339 pdata->rtc = rtc_device_register(pdev->name, &pdev->dev, 339 pdata->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
340 &stk17ta8_rtc_ops, THIS_MODULE); 340 &stk17ta8_rtc_ops, THIS_MODULE);
341 if (IS_ERR(pdata->rtc)) 341 if (IS_ERR(pdata->rtc))
342 return PTR_ERR(pdata->rtc); 342 return PTR_ERR(pdata->rtc);
343 343
344 ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 344 ret = sysfs_create_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
345 if (ret) 345
346 rtc_device_unregister(pdata->rtc);
347 return ret; 346 return ret;
348} 347}
349 348
@@ -352,7 +351,6 @@ static int stk17ta8_rtc_remove(struct platform_device *pdev)
352 struct rtc_plat_data *pdata = platform_get_drvdata(pdev); 351 struct rtc_plat_data *pdata = platform_get_drvdata(pdev);
353 352
354 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr); 353 sysfs_remove_bin_file(&pdev->dev.kobj, &stk17ta8_nvram_attr);
355 rtc_device_unregister(pdata->rtc);
356 if (pdata->irq > 0) 354 if (pdata->irq > 0)
357 writeb(0, pdata->ioaddr + RTC_INTERRUPTS); 355 writeb(0, pdata->ioaddr + RTC_INTERRUPTS);
358 return 0; 356 return 0;
diff --git a/drivers/rtc/rtc-stmp3xxx.c b/drivers/rtc/rtc-stmp3xxx.c
index 98f0d3c30738..a9cd26a26dc0 100644
--- a/drivers/rtc/rtc-stmp3xxx.c
+++ b/drivers/rtc/rtc-stmp3xxx.c
@@ -227,11 +227,7 @@ static int stmp3xxx_rtc_remove(struct platform_device *pdev)
227 227
228 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 228 writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
229 rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 229 rtc_data->io + STMP3XXX_RTC_CTRL_CLR);
230 free_irq(rtc_data->irq_alarm, &pdev->dev);
231 rtc_device_unregister(rtc_data->rtc);
232 platform_set_drvdata(pdev, NULL); 230 platform_set_drvdata(pdev, NULL);
233 iounmap(rtc_data->io);
234 kfree(rtc_data);
235 231
236 return 0; 232 return 0;
237} 233}
@@ -242,22 +238,20 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
242 struct resource *r; 238 struct resource *r;
243 int err; 239 int err;
244 240
245 rtc_data = kzalloc(sizeof *rtc_data, GFP_KERNEL); 241 rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL);
246 if (!rtc_data) 242 if (!rtc_data)
247 return -ENOMEM; 243 return -ENOMEM;
248 244
249 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 245 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
250 if (!r) { 246 if (!r) {
251 dev_err(&pdev->dev, "failed to get resource\n"); 247 dev_err(&pdev->dev, "failed to get resource\n");
252 err = -ENXIO; 248 return -ENXIO;
253 goto out_free;
254 } 249 }
255 250
256 rtc_data->io = ioremap(r->start, resource_size(r)); 251 rtc_data->io = devm_ioremap(&pdev->dev, r->start, resource_size(r));
257 if (!rtc_data->io) { 252 if (!rtc_data->io) {
258 dev_err(&pdev->dev, "ioremap failed\n"); 253 dev_err(&pdev->dev, "ioremap failed\n");
259 err = -EIO; 254 return -EIO;
260 goto out_free;
261 } 255 }
262 256
263 rtc_data->irq_alarm = platform_get_irq(pdev, 0); 257 rtc_data->irq_alarm = platform_get_irq(pdev, 0);
@@ -265,8 +259,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
265 if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) & 259 if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) &
266 STMP3XXX_RTC_STAT_RTC_PRESENT)) { 260 STMP3XXX_RTC_STAT_RTC_PRESENT)) {
267 dev_err(&pdev->dev, "no device onboard\n"); 261 dev_err(&pdev->dev, "no device onboard\n");
268 err = -ENODEV; 262 return -ENODEV;
269 goto out_remap;
270 } 263 }
271 264
272 platform_set_drvdata(pdev, rtc_data); 265 platform_set_drvdata(pdev, rtc_data);
@@ -281,43 +274,38 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
281 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN, 274 STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
282 rtc_data->io + STMP3XXX_RTC_CTRL_CLR); 275 rtc_data->io + STMP3XXX_RTC_CTRL_CLR);
283 276
284 rtc_data->rtc = rtc_device_register(pdev->name, &pdev->dev, 277 rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
285 &stmp3xxx_rtc_ops, THIS_MODULE); 278 &stmp3xxx_rtc_ops, THIS_MODULE);
286 if (IS_ERR(rtc_data->rtc)) { 279 if (IS_ERR(rtc_data->rtc)) {
287 err = PTR_ERR(rtc_data->rtc); 280 err = PTR_ERR(rtc_data->rtc);
288 goto out_remap; 281 goto out;
289 } 282 }
290 283
291 err = request_irq(rtc_data->irq_alarm, stmp3xxx_rtc_interrupt, 0, 284 err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm,
292 "RTC alarm", &pdev->dev); 285 stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev);
293 if (err) { 286 if (err) {
294 dev_err(&pdev->dev, "Cannot claim IRQ%d\n", 287 dev_err(&pdev->dev, "Cannot claim IRQ%d\n",
295 rtc_data->irq_alarm); 288 rtc_data->irq_alarm);
296 goto out_irq_alarm; 289 goto out;
297 } 290 }
298 291
299 stmp3xxx_wdt_register(pdev); 292 stmp3xxx_wdt_register(pdev);
300 return 0; 293 return 0;
301 294
302out_irq_alarm: 295out:
303 rtc_device_unregister(rtc_data->rtc);
304out_remap:
305 platform_set_drvdata(pdev, NULL); 296 platform_set_drvdata(pdev, NULL);
306 iounmap(rtc_data->io);
307out_free:
308 kfree(rtc_data);
309 return err; 297 return err;
310} 298}
311 299
312#ifdef CONFIG_PM 300#ifdef CONFIG_PM_SLEEP
313static int stmp3xxx_rtc_suspend(struct platform_device *dev, pm_message_t state) 301static int stmp3xxx_rtc_suspend(struct device *dev)
314{ 302{
315 return 0; 303 return 0;
316} 304}
317 305
318static int stmp3xxx_rtc_resume(struct platform_device *dev) 306static int stmp3xxx_rtc_resume(struct device *dev)
319{ 307{
320 struct stmp3xxx_rtc_data *rtc_data = platform_get_drvdata(dev); 308 struct stmp3xxx_rtc_data *rtc_data = dev_get_drvdata(dev);
321 309
322 mxs_reset_block(rtc_data->io); 310 mxs_reset_block(rtc_data->io);
323 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN | 311 writel(STMP3XXX_RTC_PERSISTENT0_ALARM_EN |
@@ -326,11 +314,11 @@ static int stmp3xxx_rtc_resume(struct platform_device *dev)
326 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR); 314 rtc_data->io + STMP3XXX_RTC_PERSISTENT0_CLR);
327 return 0; 315 return 0;
328} 316}
329#else
330#define stmp3xxx_rtc_suspend NULL
331#define stmp3xxx_rtc_resume NULL
332#endif 317#endif
333 318
319static SIMPLE_DEV_PM_OPS(stmp3xxx_rtc_pm_ops, stmp3xxx_rtc_suspend,
320 stmp3xxx_rtc_resume);
321
334static const struct of_device_id rtc_dt_ids[] = { 322static const struct of_device_id rtc_dt_ids[] = {
335 { .compatible = "fsl,stmp3xxx-rtc", }, 323 { .compatible = "fsl,stmp3xxx-rtc", },
336 { /* sentinel */ } 324 { /* sentinel */ }
@@ -340,11 +328,10 @@ MODULE_DEVICE_TABLE(of, rtc_dt_ids);
340static struct platform_driver stmp3xxx_rtcdrv = { 328static struct platform_driver stmp3xxx_rtcdrv = {
341 .probe = stmp3xxx_rtc_probe, 329 .probe = stmp3xxx_rtc_probe,
342 .remove = stmp3xxx_rtc_remove, 330 .remove = stmp3xxx_rtc_remove,
343 .suspend = stmp3xxx_rtc_suspend,
344 .resume = stmp3xxx_rtc_resume,
345 .driver = { 331 .driver = {
346 .name = "stmp3xxx-rtc", 332 .name = "stmp3xxx-rtc",
347 .owner = THIS_MODULE, 333 .owner = THIS_MODULE,
334 .pm = &stmp3xxx_rtc_pm_ops,
348 .of_match_table = of_match_ptr(rtc_dt_ids), 335 .of_match_table = of_match_ptr(rtc_dt_ids),
349 }, 336 },
350}; 337};
diff --git a/drivers/rtc/rtc-sun4v.c b/drivers/rtc/rtc-sun4v.c
index 59b5c2dcb58c..ce42e5fa9e09 100644
--- a/drivers/rtc/rtc-sun4v.c
+++ b/drivers/rtc/rtc-sun4v.c
@@ -81,8 +81,10 @@ static const struct rtc_class_ops sun4v_rtc_ops = {
81 81
82static int __init sun4v_rtc_probe(struct platform_device *pdev) 82static int __init sun4v_rtc_probe(struct platform_device *pdev)
83{ 83{
84 struct rtc_device *rtc = rtc_device_register("sun4v", &pdev->dev, 84 struct rtc_device *rtc;
85 &sun4v_rtc_ops, THIS_MODULE); 85
86 rtc = devm_rtc_device_register(&pdev->dev, "sun4v",
87 &sun4v_rtc_ops, THIS_MODULE);
86 if (IS_ERR(rtc)) 88 if (IS_ERR(rtc))
87 return PTR_ERR(rtc); 89 return PTR_ERR(rtc);
88 90
@@ -92,9 +94,6 @@ static int __init sun4v_rtc_probe(struct platform_device *pdev)
92 94
93static int __exit sun4v_rtc_remove(struct platform_device *pdev) 95static int __exit sun4v_rtc_remove(struct platform_device *pdev)
94{ 96{
95 struct rtc_device *rtc = platform_get_drvdata(pdev);
96
97 rtc_device_unregister(rtc);
98 return 0; 97 return 0;
99} 98}
100 99
@@ -106,18 +105,7 @@ static struct platform_driver sun4v_rtc_driver = {
106 .remove = __exit_p(sun4v_rtc_remove), 105 .remove = __exit_p(sun4v_rtc_remove),
107}; 106};
108 107
109static int __init sun4v_rtc_init(void) 108module_platform_driver_probe(sun4v_rtc_driver, sun4v_rtc_probe);
110{
111 return platform_driver_probe(&sun4v_rtc_driver, sun4v_rtc_probe);
112}
113
114static void __exit sun4v_rtc_exit(void)
115{
116 platform_driver_unregister(&sun4v_rtc_driver);
117}
118
119module_init(sun4v_rtc_init);
120module_exit(sun4v_rtc_exit);
121 109
122MODULE_AUTHOR("David S. Miller <davem@davemloft.net>"); 110MODULE_AUTHOR("David S. Miller <davem@davemloft.net>");
123MODULE_DESCRIPTION("SUN4V RTC driver"); 111MODULE_DESCRIPTION("SUN4V RTC driver");
diff --git a/drivers/rtc/rtc-tegra.c b/drivers/rtc/rtc-tegra.c
index 7c033756d6b5..a34315d25478 100644
--- a/drivers/rtc/rtc-tegra.c
+++ b/drivers/rtc/rtc-tegra.c
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/rtc.h> 27#include <linux/rtc.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/pm.h>
29 30
30/* set to 1 = busy every eight 32kHz clocks during copy of sec+msec to AHB */ 31/* set to 1 = busy every eight 32kHz clocks during copy of sec+msec to AHB */
31#define TEGRA_RTC_REG_BUSY 0x004 32#define TEGRA_RTC_REG_BUSY 0x004
@@ -309,7 +310,7 @@ static const struct of_device_id tegra_rtc_dt_match[] = {
309}; 310};
310MODULE_DEVICE_TABLE(of, tegra_rtc_dt_match); 311MODULE_DEVICE_TABLE(of, tegra_rtc_dt_match);
311 312
312static int tegra_rtc_probe(struct platform_device *pdev) 313static int __init tegra_rtc_probe(struct platform_device *pdev)
313{ 314{
314 struct tegra_rtc_info *info; 315 struct tegra_rtc_info *info;
315 struct resource *res; 316 struct resource *res;
@@ -348,53 +349,35 @@ static int tegra_rtc_probe(struct platform_device *pdev)
348 349
349 device_init_wakeup(&pdev->dev, 1); 350 device_init_wakeup(&pdev->dev, 1);
350 351
351 info->rtc_dev = rtc_device_register( 352 info->rtc_dev = devm_rtc_device_register(&pdev->dev,
352 pdev->name, &pdev->dev, &tegra_rtc_ops, THIS_MODULE); 353 dev_name(&pdev->dev), &tegra_rtc_ops,
354 THIS_MODULE);
353 if (IS_ERR(info->rtc_dev)) { 355 if (IS_ERR(info->rtc_dev)) {
354 ret = PTR_ERR(info->rtc_dev); 356 ret = PTR_ERR(info->rtc_dev);
355 info->rtc_dev = NULL; 357 dev_err(&pdev->dev, "Unable to register device (err=%d).\n",
356 dev_err(&pdev->dev,
357 "Unable to register device (err=%d).\n",
358 ret); 358 ret);
359 return ret; 359 return ret;
360 } 360 }
361 361
362 ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq, 362 ret = devm_request_irq(&pdev->dev, info->tegra_rtc_irq,
363 tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH, 363 tegra_rtc_irq_handler, IRQF_TRIGGER_HIGH,
364 "rtc alarm", &pdev->dev); 364 dev_name(&pdev->dev), &pdev->dev);
365 if (ret) { 365 if (ret) {
366 dev_err(&pdev->dev, 366 dev_err(&pdev->dev,
367 "Unable to request interrupt for device (err=%d).\n", 367 "Unable to request interrupt for device (err=%d).\n",
368 ret); 368 ret);
369 goto err_dev_unreg; 369 return ret;
370 } 370 }
371 371
372 dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n"); 372 dev_notice(&pdev->dev, "Tegra internal Real Time Clock\n");
373 373
374 return 0; 374 return 0;
375
376err_dev_unreg:
377 rtc_device_unregister(info->rtc_dev);
378
379 return ret;
380} 375}
381 376
382static int tegra_rtc_remove(struct platform_device *pdev) 377#ifdef CONFIG_PM_SLEEP
378static int tegra_rtc_suspend(struct device *dev)
383{ 379{
384 struct tegra_rtc_info *info = platform_get_drvdata(pdev); 380 struct tegra_rtc_info *info = dev_get_drvdata(dev);
385
386 rtc_device_unregister(info->rtc_dev);
387
388 platform_set_drvdata(pdev, NULL);
389
390 return 0;
391}
392
393#ifdef CONFIG_PM
394static int tegra_rtc_suspend(struct platform_device *pdev, pm_message_t state)
395{
396 struct device *dev = &pdev->dev;
397 struct tegra_rtc_info *info = platform_get_drvdata(pdev);
398 381
399 tegra_rtc_wait_while_busy(dev); 382 tegra_rtc_wait_while_busy(dev);
400 383
@@ -416,10 +399,9 @@ static int tegra_rtc_suspend(struct platform_device *pdev, pm_message_t state)
416 return 0; 399 return 0;
417} 400}
418 401
419static int tegra_rtc_resume(struct platform_device *pdev) 402static int tegra_rtc_resume(struct device *dev)
420{ 403{
421 struct device *dev = &pdev->dev; 404 struct tegra_rtc_info *info = dev_get_drvdata(dev);
422 struct tegra_rtc_info *info = platform_get_drvdata(pdev);
423 405
424 dev_vdbg(dev, "Resume (device_may_wakeup=%d)\n", 406 dev_vdbg(dev, "Resume (device_may_wakeup=%d)\n",
425 device_may_wakeup(dev)); 407 device_may_wakeup(dev));
@@ -431,6 +413,8 @@ static int tegra_rtc_resume(struct platform_device *pdev)
431} 413}
432#endif 414#endif
433 415
416static SIMPLE_DEV_PM_OPS(tegra_rtc_pm_ops, tegra_rtc_suspend, tegra_rtc_resume);
417
434static void tegra_rtc_shutdown(struct platform_device *pdev) 418static void tegra_rtc_shutdown(struct platform_device *pdev)
435{ 419{
436 dev_vdbg(&pdev->dev, "disabling interrupts.\n"); 420 dev_vdbg(&pdev->dev, "disabling interrupts.\n");
@@ -439,30 +423,16 @@ static void tegra_rtc_shutdown(struct platform_device *pdev)
439 423
440MODULE_ALIAS("platform:tegra_rtc"); 424MODULE_ALIAS("platform:tegra_rtc");
441static struct platform_driver tegra_rtc_driver = { 425static struct platform_driver tegra_rtc_driver = {
442 .remove = tegra_rtc_remove,
443 .shutdown = tegra_rtc_shutdown, 426 .shutdown = tegra_rtc_shutdown,
444 .driver = { 427 .driver = {
445 .name = "tegra_rtc", 428 .name = "tegra_rtc",
446 .owner = THIS_MODULE, 429 .owner = THIS_MODULE,
447 .of_match_table = tegra_rtc_dt_match, 430 .of_match_table = tegra_rtc_dt_match,
431 .pm = &tegra_rtc_pm_ops,
448 }, 432 },
449#ifdef CONFIG_PM
450 .suspend = tegra_rtc_suspend,
451 .resume = tegra_rtc_resume,
452#endif
453}; 433};
454 434
455static int __init tegra_rtc_init(void) 435module_platform_driver_probe(tegra_rtc_driver, tegra_rtc_probe);
456{
457 return platform_driver_probe(&tegra_rtc_driver, tegra_rtc_probe);
458}
459module_init(tegra_rtc_init);
460
461static void __exit tegra_rtc_exit(void)
462{
463 platform_driver_unregister(&tegra_rtc_driver);
464}
465module_exit(tegra_rtc_exit);
466 436
467MODULE_AUTHOR("Jon Mayo <jmayo@nvidia.com>"); 437MODULE_AUTHOR("Jon Mayo <jmayo@nvidia.com>");
468MODULE_DESCRIPTION("driver for Tegra internal RTC"); 438MODULE_DESCRIPTION("driver for Tegra internal RTC");
diff --git a/drivers/rtc/rtc-test.c b/drivers/rtc/rtc-test.c
index b92e0f6383e6..7746e65b93f2 100644
--- a/drivers/rtc/rtc-test.c
+++ b/drivers/rtc/rtc-test.c
@@ -99,8 +99,10 @@ static DEVICE_ATTR(irq, S_IRUGO | S_IWUSR, test_irq_show, test_irq_store);
99static int test_probe(struct platform_device *plat_dev) 99static int test_probe(struct platform_device *plat_dev)
100{ 100{
101 int err; 101 int err;
102 struct rtc_device *rtc = rtc_device_register("test", &plat_dev->dev, 102 struct rtc_device *rtc;
103 &test_rtc_ops, THIS_MODULE); 103
104 rtc = devm_rtc_device_register(&plat_dev->dev, "test",
105 &test_rtc_ops, THIS_MODULE);
104 if (IS_ERR(rtc)) { 106 if (IS_ERR(rtc)) {
105 err = PTR_ERR(rtc); 107 err = PTR_ERR(rtc);
106 return err; 108 return err;
@@ -115,15 +117,11 @@ static int test_probe(struct platform_device *plat_dev)
115 return 0; 117 return 0;
116 118
117err: 119err:
118 rtc_device_unregister(rtc);
119 return err; 120 return err;
120} 121}
121 122
122static int test_remove(struct platform_device *plat_dev) 123static int test_remove(struct platform_device *plat_dev)
123{ 124{
124 struct rtc_device *rtc = platform_get_drvdata(plat_dev);
125
126 rtc_device_unregister(rtc);
127 device_remove_file(&plat_dev->dev, &dev_attr_irq); 125 device_remove_file(&plat_dev->dev, &dev_attr_irq);
128 126
129 return 0; 127 return 0;
diff --git a/drivers/rtc/rtc-tile.c b/drivers/rtc/rtc-tile.c
index 62db4841078b..249b6531f119 100644
--- a/drivers/rtc/rtc-tile.c
+++ b/drivers/rtc/rtc-tile.c
@@ -80,8 +80,8 @@ static int tile_rtc_probe(struct platform_device *dev)
80{ 80{
81 struct rtc_device *rtc; 81 struct rtc_device *rtc;
82 82
83 rtc = rtc_device_register("tile", 83 rtc = devm_rtc_device_register(&dev->dev, "tile",
84 &dev->dev, &tile_rtc_ops, THIS_MODULE); 84 &tile_rtc_ops, THIS_MODULE);
85 85
86 if (IS_ERR(rtc)) 86 if (IS_ERR(rtc))
87 return PTR_ERR(rtc); 87 return PTR_ERR(rtc);
@@ -96,11 +96,6 @@ static int tile_rtc_probe(struct platform_device *dev)
96 */ 96 */
97static int tile_rtc_remove(struct platform_device *dev) 97static int tile_rtc_remove(struct platform_device *dev)
98{ 98{
99 struct rtc_device *rtc = platform_get_drvdata(dev);
100
101 if (rtc)
102 rtc_device_unregister(rtc);
103
104 platform_set_drvdata(dev, NULL); 99 platform_set_drvdata(dev, NULL);
105 100
106 return 0; 101 return 0;
diff --git a/drivers/rtc/rtc-tps6586x.c b/drivers/rtc/rtc-tps6586x.c
index aab4e8c93622..459c2ffc95a6 100644
--- a/drivers/rtc/rtc-tps6586x.c
+++ b/drivers/rtc/rtc-tps6586x.c
@@ -274,7 +274,7 @@ static int tps6586x_rtc_probe(struct platform_device *pdev)
274 } 274 }
275 275
276 platform_set_drvdata(pdev, rtc); 276 platform_set_drvdata(pdev, rtc);
277 rtc->rtc = rtc_device_register(dev_name(&pdev->dev), &pdev->dev, 277 rtc->rtc = devm_rtc_device_register(&pdev->dev, dev_name(&pdev->dev),
278 &tps6586x_rtc_ops, THIS_MODULE); 278 &tps6586x_rtc_ops, THIS_MODULE);
279 if (IS_ERR(rtc->rtc)) { 279 if (IS_ERR(rtc->rtc)) {
280 ret = PTR_ERR(rtc->rtc); 280 ret = PTR_ERR(rtc->rtc);
@@ -289,15 +289,12 @@ static int tps6586x_rtc_probe(struct platform_device *pdev)
289 if (ret < 0) { 289 if (ret < 0) {
290 dev_err(&pdev->dev, "request IRQ(%d) failed with ret %d\n", 290 dev_err(&pdev->dev, "request IRQ(%d) failed with ret %d\n",
291 rtc->irq, ret); 291 rtc->irq, ret);
292 goto fail_req_irq; 292 goto fail_rtc_register;
293 } 293 }
294 disable_irq(rtc->irq); 294 disable_irq(rtc->irq);
295 device_set_wakeup_capable(&pdev->dev, 1); 295 device_set_wakeup_capable(&pdev->dev, 1);
296 return 0; 296 return 0;
297 297
298fail_req_irq:
299 rtc_device_unregister(rtc->rtc);
300
301fail_rtc_register: 298fail_rtc_register:
302 tps6586x_update(tps_dev, RTC_CTRL, 0, 299 tps6586x_update(tps_dev, RTC_CTRL, 0,
303 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); 300 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK);
@@ -306,12 +303,10 @@ fail_rtc_register:
306 303
307static int tps6586x_rtc_remove(struct platform_device *pdev) 304static int tps6586x_rtc_remove(struct platform_device *pdev)
308{ 305{
309 struct tps6586x_rtc *rtc = platform_get_drvdata(pdev);
310 struct device *tps_dev = to_tps6586x_dev(&pdev->dev); 306 struct device *tps_dev = to_tps6586x_dev(&pdev->dev);
311 307
312 tps6586x_update(tps_dev, RTC_CTRL, 0, 308 tps6586x_update(tps_dev, RTC_CTRL, 0,
313 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK); 309 RTC_ENABLE | OSC_SRC_SEL | PRE_BYPASS | CL_SEL_MASK);
314 rtc_device_unregister(rtc->rtc);
315 return 0; 310 return 0;
316} 311}
317 312
@@ -335,9 +330,8 @@ static int tps6586x_rtc_resume(struct device *dev)
335} 330}
336#endif 331#endif
337 332
338static const struct dev_pm_ops tps6586x_pm_ops = { 333static SIMPLE_DEV_PM_OPS(tps6586x_pm_ops, tps6586x_rtc_suspend,
339 SET_SYSTEM_SLEEP_PM_OPS(tps6586x_rtc_suspend, tps6586x_rtc_resume) 334 tps6586x_rtc_resume);
340};
341 335
342static struct platform_driver tps6586x_rtc_driver = { 336static struct platform_driver tps6586x_rtc_driver = {
343 .driver = { 337 .driver = {
diff --git a/drivers/rtc/rtc-tps65910.c b/drivers/rtc/rtc-tps65910.c
index 8bd8115329b5..a9caf043b0ce 100644
--- a/drivers/rtc/rtc-tps65910.c
+++ b/drivers/rtc/rtc-tps65910.c
@@ -263,7 +263,7 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
263 if (irq <= 0) { 263 if (irq <= 0) {
264 dev_warn(&pdev->dev, "Wake up is not possible as irq = %d\n", 264 dev_warn(&pdev->dev, "Wake up is not possible as irq = %d\n",
265 irq); 265 irq);
266 return ret; 266 return -ENXIO;
267 } 267 }
268 268
269 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, 269 ret = devm_request_threaded_irq(&pdev->dev, irq, NULL,
@@ -276,7 +276,7 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
276 tps_rtc->irq = irq; 276 tps_rtc->irq = irq;
277 device_set_wakeup_capable(&pdev->dev, 1); 277 device_set_wakeup_capable(&pdev->dev, 1);
278 278
279 tps_rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 279 tps_rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
280 &tps65910_rtc_ops, THIS_MODULE); 280 &tps65910_rtc_ops, THIS_MODULE);
281 if (IS_ERR(tps_rtc->rtc)) { 281 if (IS_ERR(tps_rtc->rtc)) {
282 ret = PTR_ERR(tps_rtc->rtc); 282 ret = PTR_ERR(tps_rtc->rtc);
@@ -295,12 +295,8 @@ static int tps65910_rtc_probe(struct platform_device *pdev)
295 */ 295 */
296static int tps65910_rtc_remove(struct platform_device *pdev) 296static int tps65910_rtc_remove(struct platform_device *pdev)
297{ 297{
298 /* leave rtc running, but disable irqs */
299 struct tps65910_rtc *tps_rtc = platform_get_drvdata(pdev);
300
301 tps65910_rtc_alarm_irq_enable(&pdev->dev, 0); 298 tps65910_rtc_alarm_irq_enable(&pdev->dev, 0);
302 299
303 rtc_device_unregister(tps_rtc->rtc);
304 return 0; 300 return 0;
305} 301}
306 302
@@ -324,9 +320,8 @@ static int tps65910_rtc_resume(struct device *dev)
324} 320}
325#endif 321#endif
326 322
327static const struct dev_pm_ops tps65910_rtc_pm_ops = { 323static SIMPLE_DEV_PM_OPS(tps65910_rtc_pm_ops, tps65910_rtc_suspend,
328 SET_SYSTEM_SLEEP_PM_OPS(tps65910_rtc_suspend, tps65910_rtc_resume) 324 tps65910_rtc_resume);
329};
330 325
331static struct platform_driver tps65910_rtc_driver = { 326static struct platform_driver tps65910_rtc_driver = {
332 .probe = tps65910_rtc_probe, 327 .probe = tps65910_rtc_probe,
diff --git a/drivers/rtc/rtc-tps80031.c b/drivers/rtc/rtc-tps80031.c
index 9aaf8aaebae9..72662eafb938 100644
--- a/drivers/rtc/rtc-tps80031.c
+++ b/drivers/rtc/rtc-tps80031.c
@@ -277,7 +277,7 @@ static int tps80031_rtc_probe(struct platform_device *pdev)
277 return ret; 277 return ret;
278 } 278 }
279 279
280 rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, 280 rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
281 &tps80031_rtc_ops, THIS_MODULE); 281 &tps80031_rtc_ops, THIS_MODULE);
282 if (IS_ERR(rtc->rtc)) { 282 if (IS_ERR(rtc->rtc)) {
283 ret = PTR_ERR(rtc->rtc); 283 ret = PTR_ERR(rtc->rtc);
@@ -292,7 +292,6 @@ static int tps80031_rtc_probe(struct platform_device *pdev)
292 if (ret < 0) { 292 if (ret < 0) {
293 dev_err(&pdev->dev, "request IRQ:%d failed, err = %d\n", 293 dev_err(&pdev->dev, "request IRQ:%d failed, err = %d\n",
294 rtc->irq, ret); 294 rtc->irq, ret);
295 rtc_device_unregister(rtc->rtc);
296 return ret; 295 return ret;
297 } 296 }
298 device_set_wakeup_capable(&pdev->dev, 1); 297 device_set_wakeup_capable(&pdev->dev, 1);
@@ -301,9 +300,6 @@ static int tps80031_rtc_probe(struct platform_device *pdev)
301 300
302static int tps80031_rtc_remove(struct platform_device *pdev) 301static int tps80031_rtc_remove(struct platform_device *pdev)
303{ 302{
304 struct tps80031_rtc *rtc = platform_get_drvdata(pdev);
305
306 rtc_device_unregister(rtc->rtc);
307 return 0; 303 return 0;
308} 304}
309 305
@@ -327,9 +323,8 @@ static int tps80031_rtc_resume(struct device *dev)
327}; 323};
328#endif 324#endif
329 325
330static const struct dev_pm_ops tps80031_pm_ops = { 326static SIMPLE_DEV_PM_OPS(tps80031_pm_ops, tps80031_rtc_suspend,
331 SET_SYSTEM_SLEEP_PM_OPS(tps80031_rtc_suspend, tps80031_rtc_resume) 327 tps80031_rtc_resume);
332};
333 328
334static struct platform_driver tps80031_rtc_driver = { 329static struct platform_driver tps80031_rtc_driver = {
335 .driver = { 330 .driver = {
diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
index 8bc6c80b184c..8751a5240c99 100644
--- a/drivers/rtc/rtc-twl.c
+++ b/drivers/rtc/rtc-twl.c
@@ -566,11 +566,10 @@ static void twl_rtc_shutdown(struct platform_device *pdev)
566 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M); 566 mask_rtc_irq_bit(BIT_RTC_INTERRUPTS_REG_IT_TIMER_M);
567} 567}
568 568
569#ifdef CONFIG_PM 569#ifdef CONFIG_PM_SLEEP
570
571static unsigned char irqstat; 570static unsigned char irqstat;
572 571
573static int twl_rtc_suspend(struct platform_device *pdev, pm_message_t state) 572static int twl_rtc_suspend(struct device *dev)
574{ 573{
575 irqstat = rtc_irq_bits; 574 irqstat = rtc_irq_bits;
576 575
@@ -578,17 +577,15 @@ static int twl_rtc_suspend(struct platform_device *pdev, pm_message_t state)
578 return 0; 577 return 0;
579} 578}
580 579
581static int twl_rtc_resume(struct platform_device *pdev) 580static int twl_rtc_resume(struct device *dev)
582{ 581{
583 set_rtc_irq_bit(irqstat); 582 set_rtc_irq_bit(irqstat);
584 return 0; 583 return 0;
585} 584}
586
587#else
588#define twl_rtc_suspend NULL
589#define twl_rtc_resume NULL
590#endif 585#endif
591 586
587static SIMPLE_DEV_PM_OPS(twl_rtc_pm_ops, twl_rtc_suspend, twl_rtc_resume);
588
592#ifdef CONFIG_OF 589#ifdef CONFIG_OF
593static const struct of_device_id twl_rtc_of_match[] = { 590static const struct of_device_id twl_rtc_of_match[] = {
594 {.compatible = "ti,twl4030-rtc", }, 591 {.compatible = "ti,twl4030-rtc", },
@@ -603,11 +600,10 @@ static struct platform_driver twl4030rtc_driver = {
603 .probe = twl_rtc_probe, 600 .probe = twl_rtc_probe,
604 .remove = twl_rtc_remove, 601 .remove = twl_rtc_remove,
605 .shutdown = twl_rtc_shutdown, 602 .shutdown = twl_rtc_shutdown,
606 .suspend = twl_rtc_suspend,
607 .resume = twl_rtc_resume,
608 .driver = { 603 .driver = {
609 .owner = THIS_MODULE, 604 .owner = THIS_MODULE,
610 .name = "twl_rtc", 605 .name = "twl_rtc",
606 .pm = &twl_rtc_pm_ops,
611 .of_match_table = of_match_ptr(twl_rtc_of_match), 607 .of_match_table = of_match_ptr(twl_rtc_of_match),
612 }, 608 },
613}; 609};
diff --git a/drivers/rtc/rtc-tx4939.c b/drivers/rtc/rtc-tx4939.c
index a12bfac49d36..f9a0677e4e3b 100644
--- a/drivers/rtc/rtc-tx4939.c
+++ b/drivers/rtc/rtc-tx4939.c
@@ -268,14 +268,13 @@ static int __init tx4939_rtc_probe(struct platform_device *pdev)
268 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt, 268 if (devm_request_irq(&pdev->dev, irq, tx4939_rtc_interrupt,
269 0, pdev->name, &pdev->dev) < 0) 269 0, pdev->name, &pdev->dev) < 0)
270 return -EBUSY; 270 return -EBUSY;
271 rtc = rtc_device_register(pdev->name, &pdev->dev, 271 rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
272 &tx4939_rtc_ops, THIS_MODULE); 272 &tx4939_rtc_ops, THIS_MODULE);
273 if (IS_ERR(rtc)) 273 if (IS_ERR(rtc))
274 return PTR_ERR(rtc); 274 return PTR_ERR(rtc);
275 pdata->rtc = rtc; 275 pdata->rtc = rtc;
276 ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); 276 ret = sysfs_create_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
277 if (ret) 277
278 rtc_device_unregister(rtc);
279 return ret; 278 return ret;
280} 279}
281 280
@@ -284,7 +283,6 @@ static int __exit tx4939_rtc_remove(struct platform_device *pdev)
284 struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev); 283 struct tx4939rtc_plat_data *pdata = platform_get_drvdata(pdev);
285 284
286 sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr); 285 sysfs_remove_bin_file(&pdev->dev.kobj, &tx4939_rtc_nvram_attr);
287 rtc_device_unregister(pdata->rtc);
288 spin_lock_irq(&pdata->lock); 286 spin_lock_irq(&pdata->lock);
289 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP); 287 tx4939_rtc_cmd(pdata->rtcreg, TX4939_RTCCTL_COMMAND_NOP);
290 spin_unlock_irq(&pdata->lock); 288 spin_unlock_irq(&pdata->lock);
@@ -299,18 +297,7 @@ static struct platform_driver tx4939_rtc_driver = {
299 }, 297 },
300}; 298};
301 299
302static int __init tx4939rtc_init(void) 300module_platform_driver_probe(tx4939_rtc_driver, tx4939_rtc_probe);
303{
304 return platform_driver_probe(&tx4939_rtc_driver, tx4939_rtc_probe);
305}
306
307static void __exit tx4939rtc_exit(void)
308{
309 platform_driver_unregister(&tx4939_rtc_driver);
310}
311
312module_init(tx4939rtc_init);
313module_exit(tx4939rtc_exit);
314 301
315MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>"); 302MODULE_AUTHOR("Atsushi Nemoto <anemo@mba.ocn.ne.jp>");
316MODULE_DESCRIPTION("TX4939 internal RTC driver"); 303MODULE_DESCRIPTION("TX4939 internal RTC driver");
diff --git a/drivers/rtc/rtc-v3020.c b/drivers/rtc/rtc-v3020.c
index bca5d677bc85..6e0cba8f47d5 100644
--- a/drivers/rtc/rtc-v3020.c
+++ b/drivers/rtc/rtc-v3020.c
@@ -309,7 +309,7 @@ static int rtc_probe(struct platform_device *pdev)
309 int i; 309 int i;
310 int temp; 310 int temp;
311 311
312 chip = kzalloc(sizeof *chip, GFP_KERNEL); 312 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
313 if (!chip) 313 if (!chip)
314 return -ENOMEM; 314 return -ENOMEM;
315 315
@@ -353,8 +353,8 @@ static int rtc_probe(struct platform_device *pdev)
353 353
354 platform_set_drvdata(pdev, chip); 354 platform_set_drvdata(pdev, chip);
355 355
356 chip->rtc = rtc_device_register("v3020", 356 chip->rtc = devm_rtc_device_register(&pdev->dev, "v3020",
357 &pdev->dev, &v3020_rtc_ops, THIS_MODULE); 357 &v3020_rtc_ops, THIS_MODULE);
358 if (IS_ERR(chip->rtc)) { 358 if (IS_ERR(chip->rtc)) {
359 retval = PTR_ERR(chip->rtc); 359 retval = PTR_ERR(chip->rtc);
360 goto err_io; 360 goto err_io;
@@ -365,21 +365,14 @@ static int rtc_probe(struct platform_device *pdev)
365err_io: 365err_io:
366 chip->ops->unmap_io(chip); 366 chip->ops->unmap_io(chip);
367err_chip: 367err_chip:
368 kfree(chip);
369
370 return retval; 368 return retval;
371} 369}
372 370
373static int rtc_remove(struct platform_device *dev) 371static int rtc_remove(struct platform_device *dev)
374{ 372{
375 struct v3020 *chip = platform_get_drvdata(dev); 373 struct v3020 *chip = platform_get_drvdata(dev);
376 struct rtc_device *rtc = chip->rtc;
377
378 if (rtc)
379 rtc_device_unregister(rtc);
380 374
381 chip->ops->unmap_io(chip); 375 chip->ops->unmap_io(chip);
382 kfree(chip);
383 376
384 return 0; 377 return 0;
385} 378}
diff --git a/drivers/rtc/rtc-vt8500.c b/drivers/rtc/rtc-vt8500.c
index a000bc0a8bff..d89efee6d29e 100644
--- a/drivers/rtc/rtc-vt8500.c
+++ b/drivers/rtc/rtc-vt8500.c
@@ -252,7 +252,7 @@ static int vt8500_rtc_probe(struct platform_device *pdev)
252 writel(VT8500_RTC_CR_ENABLE, 252 writel(VT8500_RTC_CR_ENABLE,
253 vt8500_rtc->regbase + VT8500_RTC_CR); 253 vt8500_rtc->regbase + VT8500_RTC_CR);
254 254
255 vt8500_rtc->rtc = rtc_device_register("vt8500-rtc", &pdev->dev, 255 vt8500_rtc->rtc = devm_rtc_device_register(&pdev->dev, "vt8500-rtc",
256 &vt8500_rtc_ops, THIS_MODULE); 256 &vt8500_rtc_ops, THIS_MODULE);
257 if (IS_ERR(vt8500_rtc->rtc)) { 257 if (IS_ERR(vt8500_rtc->rtc)) {
258 ret = PTR_ERR(vt8500_rtc->rtc); 258 ret = PTR_ERR(vt8500_rtc->rtc);
@@ -266,13 +266,11 @@ static int vt8500_rtc_probe(struct platform_device *pdev)
266 if (ret < 0) { 266 if (ret < 0) {
267 dev_err(&pdev->dev, "can't get irq %i, err %d\n", 267 dev_err(&pdev->dev, "can't get irq %i, err %d\n",
268 vt8500_rtc->irq_alarm, ret); 268 vt8500_rtc->irq_alarm, ret);
269 goto err_unreg; 269 goto err_return;
270 } 270 }
271 271
272 return 0; 272 return 0;
273 273
274err_unreg:
275 rtc_device_unregister(vt8500_rtc->rtc);
276err_return: 274err_return:
277 return ret; 275 return ret;
278} 276}
@@ -281,8 +279,6 @@ static int vt8500_rtc_remove(struct platform_device *pdev)
281{ 279{
282 struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev); 280 struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev);
283 281
284 rtc_device_unregister(vt8500_rtc->rtc);
285
286 /* Disable alarm matching */ 282 /* Disable alarm matching */
287 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS); 283 writel(0, vt8500_rtc->regbase + VT8500_RTC_IS);
288 284
diff --git a/drivers/rtc/rtc-wm831x.c b/drivers/rtc/rtc-wm831x.c
index 2f0ac7b30a0c..8d65b94e5a7e 100644
--- a/drivers/rtc/rtc-wm831x.c
+++ b/drivers/rtc/rtc-wm831x.c
@@ -436,7 +436,7 @@ static int wm831x_rtc_probe(struct platform_device *pdev)
436 436
437 device_init_wakeup(&pdev->dev, 1); 437 device_init_wakeup(&pdev->dev, 1);
438 438
439 wm831x_rtc->rtc = rtc_device_register("wm831x", &pdev->dev, 439 wm831x_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm831x",
440 &wm831x_rtc_ops, THIS_MODULE); 440 &wm831x_rtc_ops, THIS_MODULE);
441 if (IS_ERR(wm831x_rtc->rtc)) { 441 if (IS_ERR(wm831x_rtc->rtc)) {
442 ret = PTR_ERR(wm831x_rtc->rtc); 442 ret = PTR_ERR(wm831x_rtc->rtc);
@@ -462,10 +462,6 @@ err:
462 462
463static int wm831x_rtc_remove(struct platform_device *pdev) 463static int wm831x_rtc_remove(struct platform_device *pdev)
464{ 464{
465 struct wm831x_rtc *wm831x_rtc = platform_get_drvdata(pdev);
466
467 rtc_device_unregister(wm831x_rtc->rtc);
468
469 return 0; 465 return 0;
470} 466}
471 467
diff --git a/drivers/rtc/rtc-wm8350.c b/drivers/rtc/rtc-wm8350.c
index 8ad86ae0d30f..fa247deb9cf4 100644
--- a/drivers/rtc/rtc-wm8350.c
+++ b/drivers/rtc/rtc-wm8350.c
@@ -339,7 +339,7 @@ static const struct rtc_class_ops wm8350_rtc_ops = {
339 .alarm_irq_enable = wm8350_rtc_alarm_irq_enable, 339 .alarm_irq_enable = wm8350_rtc_alarm_irq_enable,
340}; 340};
341 341
342#ifdef CONFIG_PM 342#ifdef CONFIG_PM_SLEEP
343static int wm8350_rtc_suspend(struct device *dev) 343static int wm8350_rtc_suspend(struct device *dev)
344{ 344{
345 struct platform_device *pdev = to_platform_device(dev); 345 struct platform_device *pdev = to_platform_device(dev);
@@ -375,10 +375,6 @@ static int wm8350_rtc_resume(struct device *dev)
375 375
376 return 0; 376 return 0;
377} 377}
378
379#else
380#define wm8350_rtc_suspend NULL
381#define wm8350_rtc_resume NULL
382#endif 378#endif
383 379
384static int wm8350_rtc_probe(struct platform_device *pdev) 380static int wm8350_rtc_probe(struct platform_device *pdev)
@@ -439,8 +435,8 @@ static int wm8350_rtc_probe(struct platform_device *pdev)
439 435
440 device_init_wakeup(&pdev->dev, 1); 436 device_init_wakeup(&pdev->dev, 1);
441 437
442 wm_rtc->rtc = rtc_device_register("wm8350", &pdev->dev, 438 wm_rtc->rtc = devm_rtc_device_register(&pdev->dev, "wm8350",
443 &wm8350_rtc_ops, THIS_MODULE); 439 &wm8350_rtc_ops, THIS_MODULE);
444 if (IS_ERR(wm_rtc->rtc)) { 440 if (IS_ERR(wm_rtc->rtc)) {
445 ret = PTR_ERR(wm_rtc->rtc); 441 ret = PTR_ERR(wm_rtc->rtc);
446 dev_err(&pdev->dev, "failed to register RTC: %d\n", ret); 442 dev_err(&pdev->dev, "failed to register RTC: %d\n", ret);
@@ -462,20 +458,15 @@ static int wm8350_rtc_probe(struct platform_device *pdev)
462static int wm8350_rtc_remove(struct platform_device *pdev) 458static int wm8350_rtc_remove(struct platform_device *pdev)
463{ 459{
464 struct wm8350 *wm8350 = platform_get_drvdata(pdev); 460 struct wm8350 *wm8350 = platform_get_drvdata(pdev);
465 struct wm8350_rtc *wm_rtc = &wm8350->rtc;
466 461
467 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_SEC, wm8350); 462 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_SEC, wm8350);
468 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_ALM, wm8350); 463 wm8350_free_irq(wm8350, WM8350_IRQ_RTC_ALM, wm8350);
469 464
470 rtc_device_unregister(wm_rtc->rtc);
471
472 return 0; 465 return 0;
473} 466}
474 467
475static struct dev_pm_ops wm8350_rtc_pm_ops = { 468static SIMPLE_DEV_PM_OPS(wm8350_rtc_pm_ops, wm8350_rtc_suspend,
476 .suspend = wm8350_rtc_suspend, 469 wm8350_rtc_resume);
477 .resume = wm8350_rtc_resume,
478};
479 470
480static struct platform_driver wm8350_rtc_driver = { 471static struct platform_driver wm8350_rtc_driver = {
481 .probe = wm8350_rtc_probe, 472 .probe = wm8350_rtc_probe,
diff --git a/drivers/rtc/rtc-x1205.c b/drivers/rtc/rtc-x1205.c
index f36e59c6bc01..fa9b0679fb60 100644
--- a/drivers/rtc/rtc-x1205.c
+++ b/drivers/rtc/rtc-x1205.c
@@ -630,8 +630,8 @@ static int x1205_probe(struct i2c_client *client,
630 630
631 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n"); 631 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
632 632
633 rtc = rtc_device_register(x1205_driver.driver.name, &client->dev, 633 rtc = devm_rtc_device_register(&client->dev, x1205_driver.driver.name,
634 &x1205_rtc_ops, THIS_MODULE); 634 &x1205_rtc_ops, THIS_MODULE);
635 635
636 if (IS_ERR(rtc)) 636 if (IS_ERR(rtc))
637 return PTR_ERR(rtc); 637 return PTR_ERR(rtc);
@@ -653,21 +653,13 @@ static int x1205_probe(struct i2c_client *client,
653 653
654 err = x1205_sysfs_register(&client->dev); 654 err = x1205_sysfs_register(&client->dev);
655 if (err) 655 if (err)
656 goto exit_devreg; 656 return err;
657 657
658 return 0; 658 return 0;
659
660exit_devreg:
661 rtc_device_unregister(rtc);
662
663 return err;
664} 659}
665 660
666static int x1205_remove(struct i2c_client *client) 661static int x1205_remove(struct i2c_client *client)
667{ 662{
668 struct rtc_device *rtc = i2c_get_clientdata(client);
669
670 rtc_device_unregister(rtc);
671 x1205_sysfs_unregister(&client->dev); 663 x1205_sysfs_unregister(&client->dev);
672 return 0; 664 return 0;
673} 665}
diff --git a/drivers/scsi/fcoe/fcoe_ctlr.c b/drivers/scsi/fcoe/fcoe_ctlr.c
index a76247201be5..cd743c545ce9 100644
--- a/drivers/scsi/fcoe/fcoe_ctlr.c
+++ b/drivers/scsi/fcoe/fcoe_ctlr.c
@@ -2161,7 +2161,7 @@ static void fcoe_ctlr_vn_restart(struct fcoe_ctlr *fip)
2161 2161
2162 if (fip->probe_tries < FIP_VN_RLIM_COUNT) { 2162 if (fip->probe_tries < FIP_VN_RLIM_COUNT) {
2163 fip->probe_tries++; 2163 fip->probe_tries++;
2164 wait = random32() % FIP_VN_PROBE_WAIT; 2164 wait = prandom_u32() % FIP_VN_PROBE_WAIT;
2165 } else 2165 } else
2166 wait = FIP_VN_RLIM_INT; 2166 wait = FIP_VN_RLIM_INT;
2167 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait)); 2167 mod_timer(&fip->timer, jiffies + msecs_to_jiffies(wait));
@@ -2794,7 +2794,7 @@ static void fcoe_ctlr_vn_timeout(struct fcoe_ctlr *fip)
2794 fcoe_all_vn2vn, 0); 2794 fcoe_all_vn2vn, 0);
2795 fip->port_ka_time = jiffies + 2795 fip->port_ka_time = jiffies +
2796 msecs_to_jiffies(FIP_VN_BEACON_INT + 2796 msecs_to_jiffies(FIP_VN_BEACON_INT +
2797 (random32() % FIP_VN_BEACON_FUZZ)); 2797 (prandom_u32() % FIP_VN_BEACON_FUZZ));
2798 } 2798 }
2799 if (time_before(fip->port_ka_time, next_time)) 2799 if (time_before(fip->port_ka_time, next_time))
2800 next_time = fip->port_ka_time; 2800 next_time = fip->port_ka_time;
diff --git a/drivers/scsi/lpfc/lpfc_hbadisc.c b/drivers/scsi/lpfc/lpfc_hbadisc.c
index d7096ad94d3f..bfda18467ee6 100644
--- a/drivers/scsi/lpfc/lpfc_hbadisc.c
+++ b/drivers/scsi/lpfc/lpfc_hbadisc.c
@@ -1732,7 +1732,7 @@ lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1732 * use through a sequence of @fcf_cnt eligible FCF records with equal 1732 * use through a sequence of @fcf_cnt eligible FCF records with equal
1733 * probability. To perform integer manunipulation of random numbers with 1733 * probability. To perform integer manunipulation of random numbers with
1734 * size unit32_t, the lower 16 bits of the 32-bit random number returned 1734 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1735 * from random32() are taken as the random random number generated. 1735 * from prandom_u32() are taken as the random random number generated.
1736 * 1736 *
1737 * Returns true when outcome is for the newly read FCF record should be 1737 * Returns true when outcome is for the newly read FCF record should be
1738 * chosen; otherwise, return false when outcome is for keeping the previously 1738 * chosen; otherwise, return false when outcome is for keeping the previously
@@ -1744,7 +1744,7 @@ lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1744 uint32_t rand_num; 1744 uint32_t rand_num;
1745 1745
1746 /* Get 16-bit uniform random number */ 1746 /* Get 16-bit uniform random number */
1747 rand_num = (0xFFFF & random32()); 1747 rand_num = 0xFFFF & prandom_u32();
1748 1748
1749 /* Decision with probability 1/fcf_cnt */ 1749 /* Decision with probability 1/fcf_cnt */
1750 if ((fcf_cnt * rand_num) < 0xFFFF) 1750 if ((fcf_cnt * rand_num) < 0xFFFF)
@@ -2380,7 +2380,7 @@ lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2380 phba->fcf.eligible_fcf_cnt = 1; 2380 phba->fcf.eligible_fcf_cnt = 1;
2381 /* Seeding the random number generator for random selection */ 2381 /* Seeding the random number generator for random selection */
2382 seed = (uint32_t)(0xFFFFFFFF & jiffies); 2382 seed = (uint32_t)(0xFFFFFFFF & jiffies);
2383 srandom32(seed); 2383 prandom_seed(seed);
2384 } 2384 }
2385 spin_unlock_irq(&phba->hbalock); 2385 spin_unlock_irq(&phba->hbalock);
2386 goto read_next_fcf; 2386 goto read_next_fcf;
diff --git a/drivers/uwb/rsv.c b/drivers/uwb/rsv.c
index 0b0d8bce842e..f4ae05f78c42 100644
--- a/drivers/uwb/rsv.c
+++ b/drivers/uwb/rsv.c
@@ -231,7 +231,7 @@ void uwb_rsv_backoff_win_increment(struct uwb_rc *rc)
231 return; 231 return;
232 232
233 bow->window <<= 1; 233 bow->window <<= 1;
234 bow->n = random32() & (bow->window - 1); 234 bow->n = prandom_u32() & (bow->window - 1);
235 dev_dbg(dev, "new_window=%d, n=%d\n: ", bow->window, bow->n); 235 dev_dbg(dev, "new_window=%d, n=%d\n: ", bow->window, bow->n);
236 236
237 /* reset the timer associated variables */ 237 /* reset the timer associated variables */
@@ -557,7 +557,7 @@ int uwb_rsv_establish(struct uwb_rsv *rsv)
557 if (ret) 557 if (ret)
558 goto out; 558 goto out;
559 559
560 rsv->tiebreaker = random32() & 1; 560 rsv->tiebreaker = prandom_u32() & 1;
561 /* get available mas bitmap */ 561 /* get available mas bitmap */
562 uwb_drp_available(rc, &available); 562 uwb_drp_available(rc, &available);
563 563
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index db10d0120d2b..2e166c3fc4c3 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -59,6 +59,13 @@ config LCD_LTV350QV
59 59
60 The LTV350QV panel is present on all ATSTK1000 boards. 60 The LTV350QV panel is present on all ATSTK1000 boards.
61 61
62config LCD_ILI922X
63 tristate "ILI Technology ILI9221/ILI9222 support"
64 depends on SPI
65 help
66 If you have a panel based on the ILI9221/9222 controller
67 chip then say y to include a driver for it.
68
62config LCD_ILI9320 69config LCD_ILI9320
63 tristate "ILI Technology ILI9320 controller support" 70 tristate "ILI Technology ILI9320 controller support"
64 depends on SPI 71 depends on SPI
@@ -161,7 +168,7 @@ if BACKLIGHT_CLASS_DEVICE
161config BACKLIGHT_ATMEL_LCDC 168config BACKLIGHT_ATMEL_LCDC
162 bool "Atmel LCDC Contrast-as-Backlight control" 169 bool "Atmel LCDC Contrast-as-Backlight control"
163 depends on FB_ATMEL 170 depends on FB_ATMEL
164 default y if MACH_SAM9261EK || MACH_SAM9G10EK || MACH_SAM9263EK 171 default y if MACH_AT91SAM9261EK || MACH_AT91SAM9G10EK || MACH_AT91SAM9263EK
165 help 172 help
166 This provides a backlight control internal to the Atmel LCDC 173 This provides a backlight control internal to the Atmel LCDC
167 driver. If the LCD "contrast control" on your board is wired 174 driver. If the LCD "contrast control" on your board is wired
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 96c4d620c5ce..92711fe60464 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -5,6 +5,7 @@ obj-$(CONFIG_LCD_CLASS_DEVICE) += lcd.o
5obj-$(CONFIG_LCD_CORGI) += corgi_lcd.o 5obj-$(CONFIG_LCD_CORGI) += corgi_lcd.o
6obj-$(CONFIG_LCD_HP700) += jornada720_lcd.o 6obj-$(CONFIG_LCD_HP700) += jornada720_lcd.o
7obj-$(CONFIG_LCD_HX8357) += hx8357.o 7obj-$(CONFIG_LCD_HX8357) += hx8357.o
8obj-$(CONFIG_LCD_ILI922X) += ili922x.o
8obj-$(CONFIG_LCD_ILI9320) += ili9320.o 9obj-$(CONFIG_LCD_ILI9320) += ili9320.o
9obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.o 10obj-$(CONFIG_LCD_L4F00242T03) += l4f00242t03.o
10obj-$(CONFIG_LCD_LD9040) += ld9040.o 11obj-$(CONFIG_LCD_LD9040) += ld9040.o
diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c
index a1e41d4faa71..c84701b7ca6e 100644
--- a/drivers/video/backlight/adp5520_bl.c
+++ b/drivers/video/backlight/adp5520_bl.c
@@ -143,13 +143,16 @@ static int adp5520_bl_setup(struct backlight_device *bl)
143static ssize_t adp5520_show(struct device *dev, char *buf, int reg) 143static ssize_t adp5520_show(struct device *dev, char *buf, int reg)
144{ 144{
145 struct adp5520_bl *data = dev_get_drvdata(dev); 145 struct adp5520_bl *data = dev_get_drvdata(dev);
146 int error; 146 int ret;
147 uint8_t reg_val; 147 uint8_t reg_val;
148 148
149 mutex_lock(&data->lock); 149 mutex_lock(&data->lock);
150 error = adp5520_read(data->master, reg, &reg_val); 150 ret = adp5520_read(data->master, reg, &reg_val);
151 mutex_unlock(&data->lock); 151 mutex_unlock(&data->lock);
152 152
153 if (ret < 0)
154 return ret;
155
153 return sprintf(buf, "%u\n", reg_val); 156 return sprintf(buf, "%u\n", reg_val);
154} 157}
155 158
@@ -349,35 +352,34 @@ static int adp5520_bl_remove(struct platform_device *pdev)
349 return 0; 352 return 0;
350} 353}
351 354
352#ifdef CONFIG_PM 355#ifdef CONFIG_PM_SLEEP
353static int adp5520_bl_suspend(struct platform_device *pdev, 356static int adp5520_bl_suspend(struct device *dev)
354 pm_message_t state)
355{ 357{
356 struct backlight_device *bl = platform_get_drvdata(pdev); 358 struct backlight_device *bl = dev_get_drvdata(dev);
359
357 return adp5520_bl_set(bl, 0); 360 return adp5520_bl_set(bl, 0);
358} 361}
359 362
360static int adp5520_bl_resume(struct platform_device *pdev) 363static int adp5520_bl_resume(struct device *dev)
361{ 364{
362 struct backlight_device *bl = platform_get_drvdata(pdev); 365 struct backlight_device *bl = dev_get_drvdata(dev);
363 366
364 backlight_update_status(bl); 367 backlight_update_status(bl);
365 return 0; 368 return 0;
366} 369}
367#else
368#define adp5520_bl_suspend NULL
369#define adp5520_bl_resume NULL
370#endif 370#endif
371 371
372static SIMPLE_DEV_PM_OPS(adp5520_bl_pm_ops, adp5520_bl_suspend,
373 adp5520_bl_resume);
374
372static struct platform_driver adp5520_bl_driver = { 375static struct platform_driver adp5520_bl_driver = {
373 .driver = { 376 .driver = {
374 .name = "adp5520-backlight", 377 .name = "adp5520-backlight",
375 .owner = THIS_MODULE, 378 .owner = THIS_MODULE,
379 .pm = &adp5520_bl_pm_ops,
376 }, 380 },
377 .probe = adp5520_bl_probe, 381 .probe = adp5520_bl_probe,
378 .remove = adp5520_bl_remove, 382 .remove = adp5520_bl_remove,
379 .suspend = adp5520_bl_suspend,
380 .resume = adp5520_bl_resume,
381}; 383};
382 384
383module_platform_driver(adp5520_bl_driver); 385module_platform_driver(adp5520_bl_driver);
diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c
index a77c9cad3320..75b10f876127 100644
--- a/drivers/video/backlight/adp8860_bl.c
+++ b/drivers/video/backlight/adp8860_bl.c
@@ -249,12 +249,14 @@ static int adp8860_led_probe(struct i2c_client *client)
249 if (led_dat->id > 7 || led_dat->id < 1) { 249 if (led_dat->id > 7 || led_dat->id < 1) {
250 dev_err(&client->dev, "Invalid LED ID %d\n", 250 dev_err(&client->dev, "Invalid LED ID %d\n",
251 led_dat->id); 251 led_dat->id);
252 ret = -EINVAL;
252 goto err; 253 goto err;
253 } 254 }
254 255
255 if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) { 256 if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) {
256 dev_err(&client->dev, "LED %d used by Backlight\n", 257 dev_err(&client->dev, "LED %d used by Backlight\n",
257 led_dat->id); 258 led_dat->id);
259 ret = -EBUSY;
258 goto err; 260 goto err;
259 } 261 }
260 262
@@ -773,25 +775,29 @@ static int adp8860_remove(struct i2c_client *client)
773 return 0; 775 return 0;
774} 776}
775 777
776#ifdef CONFIG_PM 778#ifdef CONFIG_PM_SLEEP
777static int adp8860_i2c_suspend(struct i2c_client *client, pm_message_t message) 779static int adp8860_i2c_suspend(struct device *dev)
778{ 780{
781 struct i2c_client *client = to_i2c_client(dev);
782
779 adp8860_clr_bits(client, ADP8860_MDCR, NSTBY); 783 adp8860_clr_bits(client, ADP8860_MDCR, NSTBY);
780 784
781 return 0; 785 return 0;
782} 786}
783 787
784static int adp8860_i2c_resume(struct i2c_client *client) 788static int adp8860_i2c_resume(struct device *dev)
785{ 789{
790 struct i2c_client *client = to_i2c_client(dev);
791
786 adp8860_set_bits(client, ADP8860_MDCR, NSTBY | BLEN); 792 adp8860_set_bits(client, ADP8860_MDCR, NSTBY | BLEN);
787 793
788 return 0; 794 return 0;
789} 795}
790#else
791#define adp8860_i2c_suspend NULL
792#define adp8860_i2c_resume NULL
793#endif 796#endif
794 797
798static SIMPLE_DEV_PM_OPS(adp8860_i2c_pm_ops, adp8860_i2c_suspend,
799 adp8860_i2c_resume);
800
795static const struct i2c_device_id adp8860_id[] = { 801static const struct i2c_device_id adp8860_id[] = {
796 { "adp8860", adp8860 }, 802 { "adp8860", adp8860 },
797 { "adp8861", adp8861 }, 803 { "adp8861", adp8861 },
@@ -802,12 +808,11 @@ MODULE_DEVICE_TABLE(i2c, adp8860_id);
802 808
803static struct i2c_driver adp8860_driver = { 809static struct i2c_driver adp8860_driver = {
804 .driver = { 810 .driver = {
805 .name = KBUILD_MODNAME, 811 .name = KBUILD_MODNAME,
812 .pm = &adp8860_i2c_pm_ops,
806 }, 813 },
807 .probe = adp8860_probe, 814 .probe = adp8860_probe,
808 .remove = adp8860_remove, 815 .remove = adp8860_remove,
809 .suspend = adp8860_i2c_suspend,
810 .resume = adp8860_i2c_resume,
811 .id_table = adp8860_id, 816 .id_table = adp8860_id,
812}; 817};
813 818
diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c
index 712c25a0d8fe..90049d7b5c60 100644
--- a/drivers/video/backlight/adp8870_bl.c
+++ b/drivers/video/backlight/adp8870_bl.c
@@ -274,12 +274,14 @@ static int adp8870_led_probe(struct i2c_client *client)
274 if (led_dat->id > 7 || led_dat->id < 1) { 274 if (led_dat->id > 7 || led_dat->id < 1) {
275 dev_err(&client->dev, "Invalid LED ID %d\n", 275 dev_err(&client->dev, "Invalid LED ID %d\n",
276 led_dat->id); 276 led_dat->id);
277 ret = -EINVAL;
277 goto err; 278 goto err;
278 } 279 }
279 280
280 if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) { 281 if (pdata->bl_led_assign & (1 << (led_dat->id - 1))) {
281 dev_err(&client->dev, "LED %d used by Backlight\n", 282 dev_err(&client->dev, "LED %d used by Backlight\n",
282 led_dat->id); 283 led_dat->id);
284 ret = -EBUSY;
283 goto err; 285 goto err;
284 } 286 }
285 287
@@ -895,13 +897,13 @@ static int adp8870_probe(struct i2c_client *client,
895 897
896 data->bl = bl; 898 data->bl = bl;
897 899
898 if (pdata->en_ambl_sens) 900 if (pdata->en_ambl_sens) {
899 ret = sysfs_create_group(&bl->dev.kobj, 901 ret = sysfs_create_group(&bl->dev.kobj,
900 &adp8870_bl_attr_group); 902 &adp8870_bl_attr_group);
901 903 if (ret) {
902 if (ret) { 904 dev_err(&client->dev, "failed to register sysfs\n");
903 dev_err(&client->dev, "failed to register sysfs\n"); 905 goto out1;
904 goto out1; 906 }
905 } 907 }
906 908
907 ret = adp8870_bl_setup(bl); 909 ret = adp8870_bl_setup(bl);
@@ -947,25 +949,29 @@ static int adp8870_remove(struct i2c_client *client)
947 return 0; 949 return 0;
948} 950}
949 951
950#ifdef CONFIG_PM 952#ifdef CONFIG_PM_SLEEP
951static int adp8870_i2c_suspend(struct i2c_client *client, pm_message_t message) 953static int adp8870_i2c_suspend(struct device *dev)
952{ 954{
955 struct i2c_client *client = to_i2c_client(dev);
956
953 adp8870_clr_bits(client, ADP8870_MDCR, NSTBY); 957 adp8870_clr_bits(client, ADP8870_MDCR, NSTBY);
954 958
955 return 0; 959 return 0;
956} 960}
957 961
958static int adp8870_i2c_resume(struct i2c_client *client) 962static int adp8870_i2c_resume(struct device *dev)
959{ 963{
964 struct i2c_client *client = to_i2c_client(dev);
965
960 adp8870_set_bits(client, ADP8870_MDCR, NSTBY | BLEN); 966 adp8870_set_bits(client, ADP8870_MDCR, NSTBY | BLEN);
961 967
962 return 0; 968 return 0;
963} 969}
964#else
965#define adp8870_i2c_suspend NULL
966#define adp8870_i2c_resume NULL
967#endif 970#endif
968 971
972static SIMPLE_DEV_PM_OPS(adp8870_i2c_pm_ops, adp8870_i2c_suspend,
973 adp8870_i2c_resume);
974
969static const struct i2c_device_id adp8870_id[] = { 975static const struct i2c_device_id adp8870_id[] = {
970 { "adp8870", 0 }, 976 { "adp8870", 0 },
971 { } 977 { }
@@ -974,12 +980,11 @@ MODULE_DEVICE_TABLE(i2c, adp8870_id);
974 980
975static struct i2c_driver adp8870_driver = { 981static struct i2c_driver adp8870_driver = {
976 .driver = { 982 .driver = {
977 .name = KBUILD_MODNAME, 983 .name = KBUILD_MODNAME,
984 .pm = &adp8870_i2c_pm_ops,
978 }, 985 },
979 .probe = adp8870_probe, 986 .probe = adp8870_probe,
980 .remove = adp8870_remove, 987 .remove = adp8870_remove,
981 .suspend = adp8870_i2c_suspend,
982 .resume = adp8870_i2c_resume,
983 .id_table = adp8870_id, 988 .id_table = adp8870_id,
984}; 989};
985 990
diff --git a/drivers/video/backlight/ams369fg06.c b/drivers/video/backlight/ams369fg06.c
index c02aa2c2575a..319fef6cb422 100644
--- a/drivers/video/backlight/ams369fg06.c
+++ b/drivers/video/backlight/ams369fg06.c
@@ -533,12 +533,12 @@ static int ams369fg06_remove(struct spi_device *spi)
533 return 0; 533 return 0;
534} 534}
535 535
536#if defined(CONFIG_PM) 536#ifdef CONFIG_PM_SLEEP
537static int ams369fg06_suspend(struct spi_device *spi, pm_message_t mesg) 537static int ams369fg06_suspend(struct device *dev)
538{ 538{
539 struct ams369fg06 *lcd = spi_get_drvdata(spi); 539 struct ams369fg06 *lcd = dev_get_drvdata(dev);
540 540
541 dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power); 541 dev_dbg(dev, "lcd->power = %d\n", lcd->power);
542 542
543 /* 543 /*
544 * when lcd panel is suspend, lcd panel becomes off 544 * when lcd panel is suspend, lcd panel becomes off
@@ -547,19 +547,19 @@ static int ams369fg06_suspend(struct spi_device *spi, pm_message_t mesg)
547 return ams369fg06_power(lcd, FB_BLANK_POWERDOWN); 547 return ams369fg06_power(lcd, FB_BLANK_POWERDOWN);
548} 548}
549 549
550static int ams369fg06_resume(struct spi_device *spi) 550static int ams369fg06_resume(struct device *dev)
551{ 551{
552 struct ams369fg06 *lcd = spi_get_drvdata(spi); 552 struct ams369fg06 *lcd = dev_get_drvdata(dev);
553 553
554 lcd->power = FB_BLANK_POWERDOWN; 554 lcd->power = FB_BLANK_POWERDOWN;
555 555
556 return ams369fg06_power(lcd, FB_BLANK_UNBLANK); 556 return ams369fg06_power(lcd, FB_BLANK_UNBLANK);
557} 557}
558#else
559#define ams369fg06_suspend NULL
560#define ams369fg06_resume NULL
561#endif 558#endif
562 559
560static SIMPLE_DEV_PM_OPS(ams369fg06_pm_ops, ams369fg06_suspend,
561 ams369fg06_resume);
562
563static void ams369fg06_shutdown(struct spi_device *spi) 563static void ams369fg06_shutdown(struct spi_device *spi)
564{ 564{
565 struct ams369fg06 *lcd = spi_get_drvdata(spi); 565 struct ams369fg06 *lcd = spi_get_drvdata(spi);
@@ -571,12 +571,11 @@ static struct spi_driver ams369fg06_driver = {
571 .driver = { 571 .driver = {
572 .name = "ams369fg06", 572 .name = "ams369fg06",
573 .owner = THIS_MODULE, 573 .owner = THIS_MODULE,
574 .pm = &ams369fg06_pm_ops,
574 }, 575 },
575 .probe = ams369fg06_probe, 576 .probe = ams369fg06_probe,
576 .remove = ams369fg06_remove, 577 .remove = ams369fg06_remove,
577 .shutdown = ams369fg06_shutdown, 578 .shutdown = ams369fg06_shutdown,
578 .suspend = ams369fg06_suspend,
579 .resume = ams369fg06_resume,
580}; 579};
581 580
582module_spi_driver(ams369fg06_driver); 581module_spi_driver(ams369fg06_driver);
diff --git a/drivers/video/backlight/as3711_bl.c b/drivers/video/backlight/as3711_bl.c
index 41d52fe52543..123887cd76bd 100644
--- a/drivers/video/backlight/as3711_bl.c
+++ b/drivers/video/backlight/as3711_bl.c
@@ -258,6 +258,109 @@ static int as3711_bl_register(struct platform_device *pdev,
258 return 0; 258 return 0;
259} 259}
260 260
261static int as3711_backlight_parse_dt(struct device *dev)
262{
263 struct as3711_bl_pdata *pdata = dev_get_platdata(dev);
264 struct device_node *bl =
265 of_find_node_by_name(dev->parent->of_node, "backlight"), *fb;
266 int ret;
267
268 if (!bl) {
269 dev_dbg(dev, "backlight node not found\n");
270 return -ENODEV;
271 }
272
273 fb = of_parse_phandle(bl, "su1-dev", 0);
274 if (fb) {
275 pdata->su1_fb = fb->full_name;
276
277 ret = of_property_read_u32(bl, "su1-max-uA", &pdata->su1_max_uA);
278 if (pdata->su1_max_uA <= 0)
279 ret = -EINVAL;
280 if (ret < 0)
281 return ret;
282 }
283
284 fb = of_parse_phandle(bl, "su2-dev", 0);
285 if (fb) {
286 int count = 0;
287
288 pdata->su2_fb = fb->full_name;
289
290 ret = of_property_read_u32(bl, "su2-max-uA", &pdata->su2_max_uA);
291 if (pdata->su2_max_uA <= 0)
292 ret = -EINVAL;
293 if (ret < 0)
294 return ret;
295
296 if (of_find_property(bl, "su2-feedback-voltage", NULL)) {
297 pdata->su2_feedback = AS3711_SU2_VOLTAGE;
298 count++;
299 }
300 if (of_find_property(bl, "su2-feedback-curr1", NULL)) {
301 pdata->su2_feedback = AS3711_SU2_CURR1;
302 count++;
303 }
304 if (of_find_property(bl, "su2-feedback-curr2", NULL)) {
305 pdata->su2_feedback = AS3711_SU2_CURR2;
306 count++;
307 }
308 if (of_find_property(bl, "su2-feedback-curr3", NULL)) {
309 pdata->su2_feedback = AS3711_SU2_CURR3;
310 count++;
311 }
312 if (of_find_property(bl, "su2-feedback-curr-auto", NULL)) {
313 pdata->su2_feedback = AS3711_SU2_CURR_AUTO;
314 count++;
315 }
316 if (count != 1)
317 return -EINVAL;
318
319 count = 0;
320 if (of_find_property(bl, "su2-fbprot-lx-sd4", NULL)) {
321 pdata->su2_fbprot = AS3711_SU2_LX_SD4;
322 count++;
323 }
324 if (of_find_property(bl, "su2-fbprot-gpio2", NULL)) {
325 pdata->su2_fbprot = AS3711_SU2_GPIO2;
326 count++;
327 }
328 if (of_find_property(bl, "su2-fbprot-gpio3", NULL)) {
329 pdata->su2_fbprot = AS3711_SU2_GPIO3;
330 count++;
331 }
332 if (of_find_property(bl, "su2-fbprot-gpio4", NULL)) {
333 pdata->su2_fbprot = AS3711_SU2_GPIO4;
334 count++;
335 }
336 if (count != 1)
337 return -EINVAL;
338
339 count = 0;
340 if (of_find_property(bl, "su2-auto-curr1", NULL)) {
341 pdata->su2_auto_curr1 = true;
342 count++;
343 }
344 if (of_find_property(bl, "su2-auto-curr2", NULL)) {
345 pdata->su2_auto_curr2 = true;
346 count++;
347 }
348 if (of_find_property(bl, "su2-auto-curr3", NULL)) {
349 pdata->su2_auto_curr3 = true;
350 count++;
351 }
352
353 /*
354 * At least one su2-auto-curr* must be specified iff
355 * AS3711_SU2_CURR_AUTO is used
356 */
357 if (!count ^ (pdata->su2_feedback != AS3711_SU2_CURR_AUTO))
358 return -EINVAL;
359 }
360
361 return 0;
362}
363
261static int as3711_backlight_probe(struct platform_device *pdev) 364static int as3711_backlight_probe(struct platform_device *pdev)
262{ 365{
263 struct as3711_bl_pdata *pdata = dev_get_platdata(&pdev->dev); 366 struct as3711_bl_pdata *pdata = dev_get_platdata(&pdev->dev);
@@ -267,11 +370,24 @@ static int as3711_backlight_probe(struct platform_device *pdev)
267 unsigned int max_brightness; 370 unsigned int max_brightness;
268 int ret; 371 int ret;
269 372
270 if (!pdata || (!pdata->su1_fb && !pdata->su2_fb)) { 373 if (!pdata) {
271 dev_err(&pdev->dev, "No platform data, exiting...\n"); 374 dev_err(&pdev->dev, "No platform data, exiting...\n");
272 return -ENODEV; 375 return -ENODEV;
273 } 376 }
274 377
378 if (pdev->dev.parent->of_node) {
379 ret = as3711_backlight_parse_dt(&pdev->dev);
380 if (ret < 0) {
381 dev_err(&pdev->dev, "DT parsing failed: %d\n", ret);
382 return ret;
383 }
384 }
385
386 if (!pdata->su1_fb && !pdata->su2_fb) {
387 dev_err(&pdev->dev, "No framebuffer specified\n");
388 return -EINVAL;
389 }
390
275 /* 391 /*
276 * Due to possible hardware damage I chose to block all modes, 392 * Due to possible hardware damage I chose to block all modes,
277 * unsupported on my hardware. Anyone, wishing to use any of those modes 393 * unsupported on my hardware. Anyone, wishing to use any of those modes
diff --git a/drivers/video/backlight/atmel-pwm-bl.c b/drivers/video/backlight/atmel-pwm-bl.c
index de5e5e74e2a7..a60d6afca97c 100644
--- a/drivers/video/backlight/atmel-pwm-bl.c
+++ b/drivers/video/backlight/atmel-pwm-bl.c
@@ -118,7 +118,7 @@ static const struct backlight_ops atmel_pwm_bl_ops = {
118 .update_status = atmel_pwm_bl_set_intensity, 118 .update_status = atmel_pwm_bl_set_intensity,
119}; 119};
120 120
121static int atmel_pwm_bl_probe(struct platform_device *pdev) 121static int __init atmel_pwm_bl_probe(struct platform_device *pdev)
122{ 122{
123 struct backlight_properties props; 123 struct backlight_properties props;
124 const struct atmel_pwm_bl_platform_data *pdata; 124 const struct atmel_pwm_bl_platform_data *pdata;
@@ -225,17 +225,7 @@ static struct platform_driver atmel_pwm_bl_driver = {
225 .remove = __exit_p(atmel_pwm_bl_remove), 225 .remove = __exit_p(atmel_pwm_bl_remove),
226}; 226};
227 227
228static int __init atmel_pwm_bl_init(void) 228module_platform_driver_probe(atmel_pwm_bl_driver, atmel_pwm_bl_probe);
229{
230 return platform_driver_probe(&atmel_pwm_bl_driver, atmel_pwm_bl_probe);
231}
232module_init(atmel_pwm_bl_init);
233
234static void __exit atmel_pwm_bl_exit(void)
235{
236 platform_driver_unregister(&atmel_pwm_bl_driver);
237}
238module_exit(atmel_pwm_bl_exit);
239 229
240MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>"); 230MODULE_AUTHOR("Hans-Christian egtvedt <hans-christian.egtvedt@atmel.com>");
241MODULE_DESCRIPTION("Atmel PWM backlight driver"); 231MODULE_DESCRIPTION("Atmel PWM backlight driver");
diff --git a/drivers/video/backlight/corgi_lcd.c b/drivers/video/backlight/corgi_lcd.c
index aa782f302983..c97867a717a7 100644
--- a/drivers/video/backlight/corgi_lcd.c
+++ b/drivers/video/backlight/corgi_lcd.c
@@ -457,10 +457,10 @@ static const struct backlight_ops corgi_bl_ops = {
457 .update_status = corgi_bl_update_status, 457 .update_status = corgi_bl_update_status,
458}; 458};
459 459
460#ifdef CONFIG_PM 460#ifdef CONFIG_PM_SLEEP
461static int corgi_lcd_suspend(struct spi_device *spi, pm_message_t state) 461static int corgi_lcd_suspend(struct device *dev)
462{ 462{
463 struct corgi_lcd *lcd = spi_get_drvdata(spi); 463 struct corgi_lcd *lcd = dev_get_drvdata(dev);
464 464
465 corgibl_flags |= CORGIBL_SUSPENDED; 465 corgibl_flags |= CORGIBL_SUSPENDED;
466 corgi_bl_set_intensity(lcd, 0); 466 corgi_bl_set_intensity(lcd, 0);
@@ -468,20 +468,19 @@ static int corgi_lcd_suspend(struct spi_device *spi, pm_message_t state)
468 return 0; 468 return 0;
469} 469}
470 470
471static int corgi_lcd_resume(struct spi_device *spi) 471static int corgi_lcd_resume(struct device *dev)
472{ 472{
473 struct corgi_lcd *lcd = spi_get_drvdata(spi); 473 struct corgi_lcd *lcd = dev_get_drvdata(dev);
474 474
475 corgibl_flags &= ~CORGIBL_SUSPENDED; 475 corgibl_flags &= ~CORGIBL_SUSPENDED;
476 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_UNBLANK); 476 corgi_lcd_set_power(lcd->lcd_dev, FB_BLANK_UNBLANK);
477 backlight_update_status(lcd->bl_dev); 477 backlight_update_status(lcd->bl_dev);
478 return 0; 478 return 0;
479} 479}
480#else
481#define corgi_lcd_suspend NULL
482#define corgi_lcd_resume NULL
483#endif 480#endif
484 481
482static SIMPLE_DEV_PM_OPS(corgi_lcd_pm_ops, corgi_lcd_suspend, corgi_lcd_resume);
483
485static int setup_gpio_backlight(struct corgi_lcd *lcd, 484static int setup_gpio_backlight(struct corgi_lcd *lcd,
486 struct corgi_lcd_platform_data *pdata) 485 struct corgi_lcd_platform_data *pdata)
487{ 486{
@@ -611,11 +610,10 @@ static struct spi_driver corgi_lcd_driver = {
611 .driver = { 610 .driver = {
612 .name = "corgi-lcd", 611 .name = "corgi-lcd",
613 .owner = THIS_MODULE, 612 .owner = THIS_MODULE,
613 .pm = &corgi_lcd_pm_ops,
614 }, 614 },
615 .probe = corgi_lcd_probe, 615 .probe = corgi_lcd_probe,
616 .remove = corgi_lcd_remove, 616 .remove = corgi_lcd_remove,
617 .suspend = corgi_lcd_suspend,
618 .resume = corgi_lcd_resume,
619}; 617};
620 618
621module_spi_driver(corgi_lcd_driver); 619module_spi_driver(corgi_lcd_driver);
diff --git a/drivers/video/backlight/da903x_bl.c b/drivers/video/backlight/da903x_bl.c
index 8179cef0730f..67cadd30e273 100644
--- a/drivers/video/backlight/da903x_bl.c
+++ b/drivers/video/backlight/da903x_bl.c
@@ -88,16 +88,21 @@ static int da903x_backlight_update_status(struct backlight_device *bl)
88 if (bl->props.fb_blank != FB_BLANK_UNBLANK) 88 if (bl->props.fb_blank != FB_BLANK_UNBLANK)
89 brightness = 0; 89 brightness = 0;
90 90
91 if (bl->props.state & BL_CORE_SUSPENDED)
92 brightness = 0;
93
91 return da903x_backlight_set(bl, brightness); 94 return da903x_backlight_set(bl, brightness);
92} 95}
93 96
94static int da903x_backlight_get_brightness(struct backlight_device *bl) 97static int da903x_backlight_get_brightness(struct backlight_device *bl)
95{ 98{
96 struct da903x_backlight_data *data = bl_get_data(bl); 99 struct da903x_backlight_data *data = bl_get_data(bl);
100
97 return data->current_brightness; 101 return data->current_brightness;
98} 102}
99 103
100static const struct backlight_ops da903x_backlight_ops = { 104static const struct backlight_ops da903x_backlight_ops = {
105 .options = BL_CORE_SUSPENDRESUME,
101 .update_status = da903x_backlight_update_status, 106 .update_status = da903x_backlight_update_status,
102 .get_brightness = da903x_backlight_get_brightness, 107 .get_brightness = da903x_backlight_get_brightness,
103}; 108};
@@ -161,35 +166,10 @@ static int da903x_backlight_remove(struct platform_device *pdev)
161 return 0; 166 return 0;
162} 167}
163 168
164#ifdef CONFIG_PM
165static int da903x_backlight_suspend(struct device *dev)
166{
167 struct backlight_device *bl = dev_get_drvdata(dev);
168
169 return da903x_backlight_set(bl, 0);
170}
171
172static int da903x_backlight_resume(struct device *dev)
173{
174 struct backlight_device *bl = dev_get_drvdata(dev);
175
176 backlight_update_status(bl);
177 return 0;
178}
179
180static const struct dev_pm_ops da903x_backlight_pm_ops = {
181 .suspend = da903x_backlight_suspend,
182 .resume = da903x_backlight_resume,
183};
184#endif
185
186static struct platform_driver da903x_backlight_driver = { 169static struct platform_driver da903x_backlight_driver = {
187 .driver = { 170 .driver = {
188 .name = "da903x-backlight", 171 .name = "da903x-backlight",
189 .owner = THIS_MODULE, 172 .owner = THIS_MODULE,
190#ifdef CONFIG_PM
191 .pm = &da903x_backlight_pm_ops,
192#endif
193 }, 173 },
194 .probe = da903x_backlight_probe, 174 .probe = da903x_backlight_probe,
195 .remove = da903x_backlight_remove, 175 .remove = da903x_backlight_remove,
diff --git a/drivers/video/backlight/ep93xx_bl.c b/drivers/video/backlight/ep93xx_bl.c
index ef3e21e8f825..33455821dd31 100644
--- a/drivers/video/backlight/ep93xx_bl.c
+++ b/drivers/video/backlight/ep93xx_bl.c
@@ -60,7 +60,7 @@ static const struct backlight_ops ep93xxbl_ops = {
60 .get_brightness = ep93xxbl_get_brightness, 60 .get_brightness = ep93xxbl_get_brightness,
61}; 61};
62 62
63static int __init ep93xxbl_probe(struct platform_device *dev) 63static int ep93xxbl_probe(struct platform_device *dev)
64{ 64{
65 struct ep93xxbl *ep93xxbl; 65 struct ep93xxbl *ep93xxbl;
66 struct backlight_device *bl; 66 struct backlight_device *bl;
@@ -115,35 +115,33 @@ static int ep93xxbl_remove(struct platform_device *dev)
115 return 0; 115 return 0;
116} 116}
117 117
118#ifdef CONFIG_PM 118#ifdef CONFIG_PM_SLEEP
119static int ep93xxbl_suspend(struct platform_device *dev, pm_message_t state) 119static int ep93xxbl_suspend(struct device *dev)
120{ 120{
121 struct backlight_device *bl = platform_get_drvdata(dev); 121 struct backlight_device *bl = dev_get_drvdata(dev);
122 122
123 return ep93xxbl_set(bl, 0); 123 return ep93xxbl_set(bl, 0);
124} 124}
125 125
126static int ep93xxbl_resume(struct platform_device *dev) 126static int ep93xxbl_resume(struct device *dev)
127{ 127{
128 struct backlight_device *bl = platform_get_drvdata(dev); 128 struct backlight_device *bl = dev_get_drvdata(dev);
129 129
130 backlight_update_status(bl); 130 backlight_update_status(bl);
131 return 0; 131 return 0;
132} 132}
133#else
134#define ep93xxbl_suspend NULL
135#define ep93xxbl_resume NULL
136#endif 133#endif
137 134
135static SIMPLE_DEV_PM_OPS(ep93xxbl_pm_ops, ep93xxbl_suspend, ep93xxbl_resume);
136
138static struct platform_driver ep93xxbl_driver = { 137static struct platform_driver ep93xxbl_driver = {
139 .driver = { 138 .driver = {
140 .name = "ep93xx-bl", 139 .name = "ep93xx-bl",
141 .owner = THIS_MODULE, 140 .owner = THIS_MODULE,
141 .pm = &ep93xxbl_pm_ops,
142 }, 142 },
143 .probe = ep93xxbl_probe, 143 .probe = ep93xxbl_probe,
144 .remove = ep93xxbl_remove, 144 .remove = ep93xxbl_remove,
145 .suspend = ep93xxbl_suspend,
146 .resume = ep93xxbl_resume,
147}; 145};
148 146
149module_platform_driver(ep93xxbl_driver); 147module_platform_driver(ep93xxbl_driver);
diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
index 0ae155be9c89..19e393b41438 100644
--- a/drivers/video/backlight/generic_bl.c
+++ b/drivers/video/backlight/generic_bl.c
@@ -9,8 +9,6 @@
9 * 9 *
10 */ 10 */
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/module.h> 12#include <linux/module.h>
15#include <linux/kernel.h> 13#include <linux/kernel.h>
16#include <linux/init.h> 14#include <linux/init.h>
@@ -108,7 +106,7 @@ static int genericbl_probe(struct platform_device *pdev)
108 106
109 generic_backlight_device = bd; 107 generic_backlight_device = bd;
110 108
111 pr_info("Generic Backlight Driver Initialized.\n"); 109 dev_info(&pdev->dev, "Generic Backlight Driver Initialized.\n");
112 return 0; 110 return 0;
113} 111}
114 112
@@ -122,7 +120,7 @@ static int genericbl_remove(struct platform_device *pdev)
122 120
123 backlight_device_unregister(bd); 121 backlight_device_unregister(bd);
124 122
125 pr_info("Generic Backlight Driver Unloaded\n"); 123 dev_info(&pdev->dev, "Generic Backlight Driver Unloaded\n");
126 return 0; 124 return 0;
127} 125}
128 126
diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
index 5cefd73526f8..00076ecfe9b8 100644
--- a/drivers/video/backlight/hp680_bl.c
+++ b/drivers/video/backlight/hp680_bl.c
@@ -64,29 +64,28 @@ static void hp680bl_send_intensity(struct backlight_device *bd)
64} 64}
65 65
66 66
67#ifdef CONFIG_PM 67#ifdef CONFIG_PM_SLEEP
68static int hp680bl_suspend(struct platform_device *pdev, pm_message_t state) 68static int hp680bl_suspend(struct device *dev)
69{ 69{
70 struct backlight_device *bd = platform_get_drvdata(pdev); 70 struct backlight_device *bd = dev_get_drvdata(dev);
71 71
72 hp680bl_suspended = 1; 72 hp680bl_suspended = 1;
73 hp680bl_send_intensity(bd); 73 hp680bl_send_intensity(bd);
74 return 0; 74 return 0;
75} 75}
76 76
77static int hp680bl_resume(struct platform_device *pdev) 77static int hp680bl_resume(struct device *dev)
78{ 78{
79 struct backlight_device *bd = platform_get_drvdata(pdev); 79 struct backlight_device *bd = dev_get_drvdata(dev);
80 80
81 hp680bl_suspended = 0; 81 hp680bl_suspended = 0;
82 hp680bl_send_intensity(bd); 82 hp680bl_send_intensity(bd);
83 return 0; 83 return 0;
84} 84}
85#else
86#define hp680bl_suspend NULL
87#define hp680bl_resume NULL
88#endif 85#endif
89 86
87static SIMPLE_DEV_PM_OPS(hp680bl_pm_ops, hp680bl_suspend, hp680bl_resume);
88
90static int hp680bl_set_intensity(struct backlight_device *bd) 89static int hp680bl_set_intensity(struct backlight_device *bd)
91{ 90{
92 hp680bl_send_intensity(bd); 91 hp680bl_send_intensity(bd);
@@ -140,10 +139,9 @@ static int hp680bl_remove(struct platform_device *pdev)
140static struct platform_driver hp680bl_driver = { 139static struct platform_driver hp680bl_driver = {
141 .probe = hp680bl_probe, 140 .probe = hp680bl_probe,
142 .remove = hp680bl_remove, 141 .remove = hp680bl_remove,
143 .suspend = hp680bl_suspend,
144 .resume = hp680bl_resume,
145 .driver = { 142 .driver = {
146 .name = "hp680-bl", 143 .name = "hp680-bl",
144 .pm = &hp680bl_pm_ops,
147 }, 145 },
148}; 146};
149 147
diff --git a/drivers/video/backlight/ili922x.c b/drivers/video/backlight/ili922x.c
new file mode 100644
index 000000000000..d9f65c2d9b01
--- /dev/null
+++ b/drivers/video/backlight/ili922x.c
@@ -0,0 +1,555 @@
1/*
2 * (C) Copyright 2008
3 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This driver implements a lcd device for the ILITEK 922x display
11 * controller. The interface to the display is SPI and the display's
12 * memory is cyclically updated over the RGB interface.
13 */
14
15#include <linux/fb.h>
16#include <linux/delay.h>
17#include <linux/errno.h>
18#include <linux/init.h>
19#include <linux/kernel.h>
20#include <linux/lcd.h>
21#include <linux/module.h>
22#include <linux/of.h>
23#include <linux/slab.h>
24#include <linux/spi/spi.h>
25#include <linux/string.h>
26
27/* Register offset, see manual section 8.2 */
28#define REG_START_OSCILLATION 0x00
29#define REG_DRIVER_CODE_READ 0x00
30#define REG_DRIVER_OUTPUT_CONTROL 0x01
31#define REG_LCD_AC_DRIVEING_CONTROL 0x02
32#define REG_ENTRY_MODE 0x03
33#define REG_COMPARE_1 0x04
34#define REG_COMPARE_2 0x05
35#define REG_DISPLAY_CONTROL_1 0x07
36#define REG_DISPLAY_CONTROL_2 0x08
37#define REG_DISPLAY_CONTROL_3 0x09
38#define REG_FRAME_CYCLE_CONTROL 0x0B
39#define REG_EXT_INTF_CONTROL 0x0C
40#define REG_POWER_CONTROL_1 0x10
41#define REG_POWER_CONTROL_2 0x11
42#define REG_POWER_CONTROL_3 0x12
43#define REG_POWER_CONTROL_4 0x13
44#define REG_RAM_ADDRESS_SET 0x21
45#define REG_WRITE_DATA_TO_GRAM 0x22
46#define REG_RAM_WRITE_MASK1 0x23
47#define REG_RAM_WRITE_MASK2 0x24
48#define REG_GAMMA_CONTROL_1 0x30
49#define REG_GAMMA_CONTROL_2 0x31
50#define REG_GAMMA_CONTROL_3 0x32
51#define REG_GAMMA_CONTROL_4 0x33
52#define REG_GAMMA_CONTROL_5 0x34
53#define REG_GAMMA_CONTROL_6 0x35
54#define REG_GAMMA_CONTROL_7 0x36
55#define REG_GAMMA_CONTROL_8 0x37
56#define REG_GAMMA_CONTROL_9 0x38
57#define REG_GAMMA_CONTROL_10 0x39
58#define REG_GATE_SCAN_CONTROL 0x40
59#define REG_VERT_SCROLL_CONTROL 0x41
60#define REG_FIRST_SCREEN_DRIVE_POS 0x42
61#define REG_SECOND_SCREEN_DRIVE_POS 0x43
62#define REG_RAM_ADDR_POS_H 0x44
63#define REG_RAM_ADDR_POS_V 0x45
64#define REG_OSCILLATOR_CONTROL 0x4F
65#define REG_GPIO 0x60
66#define REG_OTP_VCM_PROGRAMMING 0x61
67#define REG_OTP_VCM_STATUS_ENABLE 0x62
68#define REG_OTP_PROGRAMMING_ID_KEY 0x65
69
70/*
71 * maximum frequency for register access
72 * (not for the GRAM access)
73 */
74#define ILITEK_MAX_FREQ_REG 4000000
75
76/*
77 * Device ID as found in the datasheet (supports 9221 and 9222)
78 */
79#define ILITEK_DEVICE_ID 0x9220
80#define ILITEK_DEVICE_ID_MASK 0xFFF0
81
82/* Last two bits in the START BYTE */
83#define START_RS_INDEX 0
84#define START_RS_REG 1
85#define START_RW_WRITE 0
86#define START_RW_READ 1
87
88/**
89 * START_BYTE(id, rs, rw)
90 *
91 * Set the start byte according to the required operation.
92 * The start byte is defined as:
93 * ----------------------------------
94 * | 0 | 1 | 1 | 1 | 0 | ID | RS | RW |
95 * ----------------------------------
96 * @id: display's id as set by the manufacturer
97 * @rs: operation type bit, one of:
98 * - START_RS_INDEX set the index register
99 * - START_RS_REG write/read registers/GRAM
100 * @rw: read/write operation
101 * - START_RW_WRITE write
102 * - START_RW_READ read
103 */
104#define START_BYTE(id, rs, rw) \
105 (0x70 | (((id) & 0x01) << 2) | (((rs) & 0x01) << 1) | ((rw) & 0x01))
106
107/**
108 * CHECK_FREQ_REG(spi_device s, spi_transfer x) - Check the frequency
109 * for the SPI transfer. According to the datasheet, the controller
110 * accept higher frequency for the GRAM transfer, but it requires
111 * lower frequency when the registers are read/written.
112 * The macro sets the frequency in the spi_transfer structure if
113 * the frequency exceeds the maximum value.
114 */
115#define CHECK_FREQ_REG(s, x) \
116 do { \
117 if (s->max_speed_hz > ILITEK_MAX_FREQ_REG) \
118 ((struct spi_transfer *)x)->speed_hz = \
119 ILITEK_MAX_FREQ_REG; \
120 } while (0)
121
122#define CMD_BUFSIZE 16
123
124#define POWER_IS_ON(pwr) ((pwr) <= FB_BLANK_NORMAL)
125
126#define set_tx_byte(b) (tx_invert ? ~(b) : b)
127
128/**
129 * ili922x_id - id as set by manufacturer
130 */
131static int ili922x_id = 1;
132module_param(ili922x_id, int, 0);
133
134static int tx_invert;
135module_param(tx_invert, int, 0);
136
137/**
138 * driver's private structure
139 */
140struct ili922x {
141 struct spi_device *spi;
142 struct lcd_device *ld;
143 int power;
144};
145
146/**
147 * ili922x_read_status - read status register from display
148 * @spi: spi device
149 * @rs: output value
150 */
151static int ili922x_read_status(struct spi_device *spi, u16 *rs)
152{
153 struct spi_message msg;
154 struct spi_transfer xfer;
155 unsigned char tbuf[CMD_BUFSIZE];
156 unsigned char rbuf[CMD_BUFSIZE];
157 int ret, i;
158
159 memset(&xfer, 0, sizeof(struct spi_transfer));
160 spi_message_init(&msg);
161 xfer.tx_buf = tbuf;
162 xfer.rx_buf = rbuf;
163 xfer.cs_change = 1;
164 CHECK_FREQ_REG(spi, &xfer);
165
166 tbuf[0] = set_tx_byte(START_BYTE(ili922x_id, START_RS_INDEX,
167 START_RW_READ));
168 /*
169 * we need 4-byte xfer here due to invalid dummy byte
170 * received after start byte
171 */
172 for (i = 1; i < 4; i++)
173 tbuf[i] = set_tx_byte(0); /* dummy */
174
175 xfer.bits_per_word = 8;
176 xfer.len = 4;
177 spi_message_add_tail(&xfer, &msg);
178 ret = spi_sync(spi, &msg);
179 if (ret < 0) {
180 dev_dbg(&spi->dev, "Error sending SPI message 0x%x", ret);
181 return ret;
182 }
183
184 *rs = (rbuf[2] << 8) + rbuf[3];
185 return 0;
186}
187
188/**
189 * ili922x_read - read register from display
190 * @spi: spi device
191 * @reg: offset of the register to be read
192 * @rx: output value
193 */
194static int ili922x_read(struct spi_device *spi, u8 reg, u16 *rx)
195{
196 struct spi_message msg;
197 struct spi_transfer xfer_regindex, xfer_regvalue;
198 unsigned char tbuf[CMD_BUFSIZE];
199 unsigned char rbuf[CMD_BUFSIZE];
200 int ret, len = 0, send_bytes;
201
202 memset(&xfer_regindex, 0, sizeof(struct spi_transfer));
203 memset(&xfer_regvalue, 0, sizeof(struct spi_transfer));
204 spi_message_init(&msg);
205 xfer_regindex.tx_buf = tbuf;
206 xfer_regindex.rx_buf = rbuf;
207 xfer_regindex.cs_change = 1;
208 CHECK_FREQ_REG(spi, &xfer_regindex);
209
210 tbuf[0] = set_tx_byte(START_BYTE(ili922x_id, START_RS_INDEX,
211 START_RW_WRITE));
212 tbuf[1] = set_tx_byte(0);
213 tbuf[2] = set_tx_byte(reg);
214 xfer_regindex.bits_per_word = 8;
215 len = xfer_regindex.len = 3;
216 spi_message_add_tail(&xfer_regindex, &msg);
217
218 send_bytes = len;
219
220 tbuf[len++] = set_tx_byte(START_BYTE(ili922x_id, START_RS_REG,
221 START_RW_READ));
222 tbuf[len++] = set_tx_byte(0);
223 tbuf[len] = set_tx_byte(0);
224
225 xfer_regvalue.cs_change = 1;
226 xfer_regvalue.len = 3;
227 xfer_regvalue.tx_buf = &tbuf[send_bytes];
228 xfer_regvalue.rx_buf = &rbuf[send_bytes];
229 CHECK_FREQ_REG(spi, &xfer_regvalue);
230
231 spi_message_add_tail(&xfer_regvalue, &msg);
232 ret = spi_sync(spi, &msg);
233 if (ret < 0) {
234 dev_dbg(&spi->dev, "Error sending SPI message 0x%x", ret);
235 return ret;
236 }
237
238 *rx = (rbuf[1 + send_bytes] << 8) + rbuf[2 + send_bytes];
239 return 0;
240}
241
242/**
243 * ili922x_write - write a controller register
244 * @spi: struct spi_device *
245 * @reg: offset of the register to be written
246 * @value: value to be written
247 */
248static int ili922x_write(struct spi_device *spi, u8 reg, u16 value)
249{
250 struct spi_message msg;
251 struct spi_transfer xfer_regindex, xfer_regvalue;
252 unsigned char tbuf[CMD_BUFSIZE];
253 unsigned char rbuf[CMD_BUFSIZE];
254 int ret, len = 0;
255
256 memset(&xfer_regindex, 0, sizeof(struct spi_transfer));
257 memset(&xfer_regvalue, 0, sizeof(struct spi_transfer));
258
259 spi_message_init(&msg);
260 xfer_regindex.tx_buf = tbuf;
261 xfer_regindex.rx_buf = rbuf;
262 xfer_regindex.cs_change = 1;
263 CHECK_FREQ_REG(spi, &xfer_regindex);
264
265 tbuf[0] = set_tx_byte(START_BYTE(ili922x_id, START_RS_INDEX,
266 START_RW_WRITE));
267 tbuf[1] = set_tx_byte(0);
268 tbuf[2] = set_tx_byte(reg);
269 xfer_regindex.bits_per_word = 8;
270 xfer_regindex.len = 3;
271 spi_message_add_tail(&xfer_regindex, &msg);
272
273 ret = spi_sync(spi, &msg);
274
275 spi_message_init(&msg);
276 len = 0;
277 tbuf[0] = set_tx_byte(START_BYTE(ili922x_id, START_RS_REG,
278 START_RW_WRITE));
279 tbuf[1] = set_tx_byte((value & 0xFF00) >> 8);
280 tbuf[2] = set_tx_byte(value & 0x00FF);
281
282 xfer_regvalue.cs_change = 1;
283 xfer_regvalue.len = 3;
284 xfer_regvalue.tx_buf = tbuf;
285 xfer_regvalue.rx_buf = rbuf;
286 CHECK_FREQ_REG(spi, &xfer_regvalue);
287
288 spi_message_add_tail(&xfer_regvalue, &msg);
289
290 ret = spi_sync(spi, &msg);
291 if (ret < 0) {
292 dev_err(&spi->dev, "Error sending SPI message 0x%x", ret);
293 return ret;
294 }
295 return 0;
296}
297
298#ifdef DEBUG
299/**
300 * ili922x_reg_dump - dump all registers
301 */
302static void ili922x_reg_dump(struct spi_device *spi)
303{
304 u8 reg;
305 u16 rx;
306
307 dev_dbg(&spi->dev, "ILI922x configuration registers:\n");
308 for (reg = REG_START_OSCILLATION;
309 reg <= REG_OTP_PROGRAMMING_ID_KEY; reg++) {
310 ili922x_read(spi, reg, &rx);
311 dev_dbg(&spi->dev, "reg @ 0x%02X: 0x%04X\n", reg, rx);
312 }
313}
314#else
315static inline void ili922x_reg_dump(struct spi_device *spi) {}
316#endif
317
318/**
319 * set_write_to_gram_reg - initialize the display to write the GRAM
320 * @spi: spi device
321 */
322static void set_write_to_gram_reg(struct spi_device *spi)
323{
324 struct spi_message msg;
325 struct spi_transfer xfer;
326 unsigned char tbuf[CMD_BUFSIZE];
327
328 memset(&xfer, 0, sizeof(struct spi_transfer));
329
330 spi_message_init(&msg);
331 xfer.tx_buf = tbuf;
332 xfer.rx_buf = NULL;
333 xfer.cs_change = 1;
334
335 tbuf[0] = START_BYTE(ili922x_id, START_RS_INDEX, START_RW_WRITE);
336 tbuf[1] = 0;
337 tbuf[2] = REG_WRITE_DATA_TO_GRAM;
338
339 xfer.bits_per_word = 8;
340 xfer.len = 3;
341 spi_message_add_tail(&xfer, &msg);
342 spi_sync(spi, &msg);
343}
344
345/**
346 * ili922x_poweron - turn the display on
347 * @spi: spi device
348 *
349 * The sequence to turn on the display is taken from
350 * the datasheet and/or the example code provided by the
351 * manufacturer.
352 */
353static int ili922x_poweron(struct spi_device *spi)
354{
355 int ret;
356
357 /* Power on */
358 ret = ili922x_write(spi, REG_POWER_CONTROL_1, 0x0000);
359 usleep_range(10000, 10500);
360 ret += ili922x_write(spi, REG_POWER_CONTROL_2, 0x0000);
361 ret += ili922x_write(spi, REG_POWER_CONTROL_3, 0x0000);
362 msleep(40);
363 ret += ili922x_write(spi, REG_POWER_CONTROL_4, 0x0000);
364 msleep(40);
365 /* register 0x56 is not documented in the datasheet */
366 ret += ili922x_write(spi, 0x56, 0x080F);
367 ret += ili922x_write(spi, REG_POWER_CONTROL_1, 0x4240);
368 usleep_range(10000, 10500);
369 ret += ili922x_write(spi, REG_POWER_CONTROL_2, 0x0000);
370 ret += ili922x_write(spi, REG_POWER_CONTROL_3, 0x0014);
371 msleep(40);
372 ret += ili922x_write(spi, REG_POWER_CONTROL_4, 0x1319);
373 msleep(40);
374
375 return ret;
376}
377
378/**
379 * ili922x_poweroff - turn the display off
380 * @spi: spi device
381 */
382static int ili922x_poweroff(struct spi_device *spi)
383{
384 int ret;
385
386 /* Power off */
387 ret = ili922x_write(spi, REG_POWER_CONTROL_1, 0x0000);
388 usleep_range(10000, 10500);
389 ret += ili922x_write(spi, REG_POWER_CONTROL_2, 0x0000);
390 ret += ili922x_write(spi, REG_POWER_CONTROL_3, 0x0000);
391 msleep(40);
392 ret += ili922x_write(spi, REG_POWER_CONTROL_4, 0x0000);
393 msleep(40);
394
395 return ret;
396}
397
398/**
399 * ili922x_display_init - initialize the display by setting
400 * the configuration registers
401 * @spi: spi device
402 */
403static void ili922x_display_init(struct spi_device *spi)
404{
405 ili922x_write(spi, REG_START_OSCILLATION, 1);
406 usleep_range(10000, 10500);
407 ili922x_write(spi, REG_DRIVER_OUTPUT_CONTROL, 0x691B);
408 ili922x_write(spi, REG_LCD_AC_DRIVEING_CONTROL, 0x0700);
409 ili922x_write(spi, REG_ENTRY_MODE, 0x1030);
410 ili922x_write(spi, REG_COMPARE_1, 0x0000);
411 ili922x_write(spi, REG_COMPARE_2, 0x0000);
412 ili922x_write(spi, REG_DISPLAY_CONTROL_1, 0x0037);
413 ili922x_write(spi, REG_DISPLAY_CONTROL_2, 0x0202);
414 ili922x_write(spi, REG_DISPLAY_CONTROL_3, 0x0000);
415 ili922x_write(spi, REG_FRAME_CYCLE_CONTROL, 0x0000);
416
417 /* Set RGB interface */
418 ili922x_write(spi, REG_EXT_INTF_CONTROL, 0x0110);
419
420 ili922x_poweron(spi);
421
422 ili922x_write(spi, REG_GAMMA_CONTROL_1, 0x0302);
423 ili922x_write(spi, REG_GAMMA_CONTROL_2, 0x0407);
424 ili922x_write(spi, REG_GAMMA_CONTROL_3, 0x0304);
425 ili922x_write(spi, REG_GAMMA_CONTROL_4, 0x0203);
426 ili922x_write(spi, REG_GAMMA_CONTROL_5, 0x0706);
427 ili922x_write(spi, REG_GAMMA_CONTROL_6, 0x0407);
428 ili922x_write(spi, REG_GAMMA_CONTROL_7, 0x0706);
429 ili922x_write(spi, REG_GAMMA_CONTROL_8, 0x0000);
430 ili922x_write(spi, REG_GAMMA_CONTROL_9, 0x0C06);
431 ili922x_write(spi, REG_GAMMA_CONTROL_10, 0x0F00);
432 ili922x_write(spi, REG_RAM_ADDRESS_SET, 0x0000);
433 ili922x_write(spi, REG_GATE_SCAN_CONTROL, 0x0000);
434 ili922x_write(spi, REG_VERT_SCROLL_CONTROL, 0x0000);
435 ili922x_write(spi, REG_FIRST_SCREEN_DRIVE_POS, 0xDB00);
436 ili922x_write(spi, REG_SECOND_SCREEN_DRIVE_POS, 0xDB00);
437 ili922x_write(spi, REG_RAM_ADDR_POS_H, 0xAF00);
438 ili922x_write(spi, REG_RAM_ADDR_POS_V, 0xDB00);
439 ili922x_reg_dump(spi);
440 set_write_to_gram_reg(spi);
441}
442
443static int ili922x_lcd_power(struct ili922x *lcd, int power)
444{
445 int ret = 0;
446
447 if (POWER_IS_ON(power) && !POWER_IS_ON(lcd->power))
448 ret = ili922x_poweron(lcd->spi);
449 else if (!POWER_IS_ON(power) && POWER_IS_ON(lcd->power))
450 ret = ili922x_poweroff(lcd->spi);
451
452 if (!ret)
453 lcd->power = power;
454
455 return ret;
456}
457
458static int ili922x_set_power(struct lcd_device *ld, int power)
459{
460 struct ili922x *ili = lcd_get_data(ld);
461
462 return ili922x_lcd_power(ili, power);
463}
464
465static int ili922x_get_power(struct lcd_device *ld)
466{
467 struct ili922x *ili = lcd_get_data(ld);
468
469 return ili->power;
470}
471
472static struct lcd_ops ili922x_ops = {
473 .get_power = ili922x_get_power,
474 .set_power = ili922x_set_power,
475};
476
477static int ili922x_probe(struct spi_device *spi)
478{
479 struct ili922x *ili;
480 struct lcd_device *lcd;
481 int ret;
482 u16 reg = 0;
483
484 ili = devm_kzalloc(&spi->dev, sizeof(*ili), GFP_KERNEL);
485 if (!ili) {
486 dev_err(&spi->dev, "cannot alloc priv data\n");
487 return -ENOMEM;
488 }
489
490 ili->spi = spi;
491 spi_set_drvdata(spi, ili);
492
493 /* check if the device is connected */
494 ret = ili922x_read(spi, REG_DRIVER_CODE_READ, &reg);
495 if (ret || ((reg & ILITEK_DEVICE_ID_MASK) != ILITEK_DEVICE_ID)) {
496 dev_err(&spi->dev,
497 "no LCD found: Chip ID 0x%x, ret %d\n",
498 reg, ret);
499 return -ENODEV;
500 } else {
501 dev_info(&spi->dev, "ILI%x found, SPI freq %d, mode %d\n",
502 reg, spi->max_speed_hz, spi->mode);
503 }
504
505 ret = ili922x_read_status(spi, &reg);
506 if (ret) {
507 dev_err(&spi->dev, "reading RS failed...\n");
508 return ret;
509 } else
510 dev_dbg(&spi->dev, "status: 0x%x\n", reg);
511
512 ili922x_display_init(spi);
513
514 ili->power = FB_BLANK_POWERDOWN;
515
516 lcd = lcd_device_register("ili922xlcd", &spi->dev, ili,
517 &ili922x_ops);
518 if (IS_ERR(lcd)) {
519 dev_err(&spi->dev, "cannot register LCD\n");
520 return PTR_ERR(lcd);
521 }
522
523 ili->ld = lcd;
524 spi_set_drvdata(spi, ili);
525
526 ili922x_lcd_power(ili, FB_BLANK_UNBLANK);
527
528 return 0;
529}
530
531static int ili922x_remove(struct spi_device *spi)
532{
533 struct ili922x *ili = spi_get_drvdata(spi);
534
535 ili922x_poweroff(spi);
536 lcd_device_unregister(ili->ld);
537 return 0;
538}
539
540static struct spi_driver ili922x_driver = {
541 .driver = {
542 .name = "ili922x",
543 .owner = THIS_MODULE,
544 },
545 .probe = ili922x_probe,
546 .remove = ili922x_remove,
547};
548
549module_spi_driver(ili922x_driver);
550
551MODULE_AUTHOR("Stefano Babic <sbabic@denx.de>");
552MODULE_DESCRIPTION("ILI9221/9222 LCD driver");
553MODULE_LICENSE("GPL");
554MODULE_PARM_DESC(ili922x_id, "set controller identifier (default=1)");
555MODULE_PARM_DESC(tx_invert, "invert bytes before sending");
diff --git a/drivers/video/backlight/ili9320.c b/drivers/video/backlight/ili9320.c
index 1235bf9defc4..f8be90c5dedc 100644
--- a/drivers/video/backlight/ili9320.c
+++ b/drivers/video/backlight/ili9320.c
@@ -231,7 +231,7 @@ int ili9320_probe_spi(struct spi_device *spi,
231 ili->power = FB_BLANK_POWERDOWN; 231 ili->power = FB_BLANK_POWERDOWN;
232 ili->platdata = cfg; 232 ili->platdata = cfg;
233 233
234 dev_set_drvdata(&spi->dev, ili); 234 spi_set_drvdata(spi, ili);
235 235
236 ili9320_setup_spi(ili, spi); 236 ili9320_setup_spi(ili, spi);
237 237
@@ -270,27 +270,21 @@ int ili9320_remove(struct ili9320 *ili)
270} 270}
271EXPORT_SYMBOL_GPL(ili9320_remove); 271EXPORT_SYMBOL_GPL(ili9320_remove);
272 272
273#ifdef CONFIG_PM 273#ifdef CONFIG_PM_SLEEP
274int ili9320_suspend(struct ili9320 *lcd, pm_message_t state) 274int ili9320_suspend(struct ili9320 *lcd)
275{ 275{
276 int ret; 276 int ret;
277 277
278 dev_dbg(lcd->dev, "%s: event %d\n", __func__, state.event); 278 ret = ili9320_power(lcd, FB_BLANK_POWERDOWN);
279 279
280 if (state.event == PM_EVENT_SUSPEND) { 280 if (lcd->platdata->suspend == ILI9320_SUSPEND_DEEP) {
281 ret = ili9320_power(lcd, FB_BLANK_POWERDOWN); 281 ili9320_write(lcd, ILI9320_POWER1, lcd->power1 |
282 282 ILI9320_POWER1_SLP |
283 if (lcd->platdata->suspend == ILI9320_SUSPEND_DEEP) { 283 ILI9320_POWER1_DSTB);
284 ili9320_write(lcd, ILI9320_POWER1, lcd->power1 | 284 lcd->initialised = 0;
285 ILI9320_POWER1_SLP |
286 ILI9320_POWER1_DSTB);
287 lcd->initialised = 0;
288 }
289
290 return ret;
291 } 285 }
292 286
293 return 0; 287 return ret;
294} 288}
295EXPORT_SYMBOL_GPL(ili9320_suspend); 289EXPORT_SYMBOL_GPL(ili9320_suspend);
296 290
diff --git a/drivers/video/backlight/ili9320.h b/drivers/video/backlight/ili9320.h
index e0db738f7bb9..42329e7aa9a8 100644
--- a/drivers/video/backlight/ili9320.h
+++ b/drivers/video/backlight/ili9320.h
@@ -76,5 +76,5 @@ extern void ili9320_shutdown(struct ili9320 *lcd);
76 76
77/* PM */ 77/* PM */
78 78
79extern int ili9320_suspend(struct ili9320 *lcd, pm_message_t state); 79extern int ili9320_suspend(struct ili9320 *lcd);
80extern int ili9320_resume(struct ili9320 *lcd); 80extern int ili9320_resume(struct ili9320 *lcd);
diff --git a/drivers/video/backlight/jornada720_bl.c b/drivers/video/backlight/jornada720_bl.c
index fef6ce4fad71..3ccb89340f22 100644
--- a/drivers/video/backlight/jornada720_bl.c
+++ b/drivers/video/backlight/jornada720_bl.c
@@ -9,8 +9,6 @@
9 * 9 *
10 */ 10 */
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/backlight.h> 12#include <linux/backlight.h>
15#include <linux/device.h> 13#include <linux/device.h>
16#include <linux/fb.h> 14#include <linux/fb.h>
@@ -40,11 +38,13 @@ static int jornada_bl_get_brightness(struct backlight_device *bd)
40 ret = jornada_ssp_byte(GETBRIGHTNESS); 38 ret = jornada_ssp_byte(GETBRIGHTNESS);
41 39
42 if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) { 40 if (jornada_ssp_byte(GETBRIGHTNESS) != TXDUMMY) {
43 pr_err("get brightness timeout\n"); 41 dev_err(&bd->dev, "get brightness timeout\n");
44 jornada_ssp_end(); 42 jornada_ssp_end();
45 return -ETIMEDOUT; 43 return -ETIMEDOUT;
46 } else /* exchange txdummy for value */ 44 } else {
45 /* exchange txdummy for value */
47 ret = jornada_ssp_byte(TXDUMMY); 46 ret = jornada_ssp_byte(TXDUMMY);
47 }
48 48
49 jornada_ssp_end(); 49 jornada_ssp_end();
50 50
@@ -61,7 +61,7 @@ static int jornada_bl_update_status(struct backlight_device *bd)
61 if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) { 61 if ((bd->props.power != FB_BLANK_UNBLANK) || (bd->props.fb_blank != FB_BLANK_UNBLANK)) {
62 ret = jornada_ssp_byte(BRIGHTNESSOFF); 62 ret = jornada_ssp_byte(BRIGHTNESSOFF);
63 if (ret != TXDUMMY) { 63 if (ret != TXDUMMY) {
64 pr_info("brightness off timeout\n"); 64 dev_info(&bd->dev, "brightness off timeout\n");
65 /* turn off backlight */ 65 /* turn off backlight */
66 PPSR &= ~PPC_LDD1; 66 PPSR &= ~PPC_LDD1;
67 PPDR |= PPC_LDD1; 67 PPDR |= PPC_LDD1;
@@ -72,7 +72,7 @@ static int jornada_bl_update_status(struct backlight_device *bd)
72 72
73 /* send command to our mcu */ 73 /* send command to our mcu */
74 if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) { 74 if (jornada_ssp_byte(SETBRIGHTNESS) != TXDUMMY) {
75 pr_info("failed to set brightness\n"); 75 dev_info(&bd->dev, "failed to set brightness\n");
76 ret = -ETIMEDOUT; 76 ret = -ETIMEDOUT;
77 goto out; 77 goto out;
78 } 78 }
@@ -86,7 +86,7 @@ static int jornada_bl_update_status(struct backlight_device *bd)
86 */ 86 */
87 if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness) 87 if (jornada_ssp_byte(BL_MAX_BRIGHT - bd->props.brightness)
88 != TXDUMMY) { 88 != TXDUMMY) {
89 pr_err("set brightness failed\n"); 89 dev_err(&bd->dev, "set brightness failed\n");
90 ret = -ETIMEDOUT; 90 ret = -ETIMEDOUT;
91 } 91 }
92 92
@@ -120,7 +120,7 @@ static int jornada_bl_probe(struct platform_device *pdev)
120 120
121 if (IS_ERR(bd)) { 121 if (IS_ERR(bd)) {
122 ret = PTR_ERR(bd); 122 ret = PTR_ERR(bd);
123 pr_err("failed to register device, err=%x\n", ret); 123 dev_err(&pdev->dev, "failed to register device, err=%x\n", ret);
124 return ret; 124 return ret;
125 } 125 }
126 126
@@ -134,7 +134,7 @@ static int jornada_bl_probe(struct platform_device *pdev)
134 jornada_bl_update_status(bd); 134 jornada_bl_update_status(bd);
135 135
136 platform_set_drvdata(pdev, bd); 136 platform_set_drvdata(pdev, bd);
137 pr_info("HP Jornada 700 series backlight driver\n"); 137 dev_info(&pdev->dev, "HP Jornada 700 series backlight driver\n");
138 138
139 return 0; 139 return 0;
140} 140}
diff --git a/drivers/video/backlight/jornada720_lcd.c b/drivers/video/backlight/jornada720_lcd.c
index 635b30523fd5..b061413f1a65 100644
--- a/drivers/video/backlight/jornada720_lcd.c
+++ b/drivers/video/backlight/jornada720_lcd.c
@@ -9,8 +9,6 @@
9 * 9 *
10 */ 10 */
11 11
12#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
14#include <linux/device.h> 12#include <linux/device.h>
15#include <linux/fb.h> 13#include <linux/fb.h>
16#include <linux/kernel.h> 14#include <linux/kernel.h>
@@ -27,7 +25,7 @@
27#define LCD_MAX_CONTRAST 0xff 25#define LCD_MAX_CONTRAST 0xff
28#define LCD_DEF_CONTRAST 0x80 26#define LCD_DEF_CONTRAST 0x80
29 27
30static int jornada_lcd_get_power(struct lcd_device *dev) 28static int jornada_lcd_get_power(struct lcd_device *ld)
31{ 29{
32 /* LDD2 in PPC = LCD POWER */ 30 /* LDD2 in PPC = LCD POWER */
33 if (PPSR & PPC_LDD2) 31 if (PPSR & PPC_LDD2)
@@ -36,17 +34,17 @@ static int jornada_lcd_get_power(struct lcd_device *dev)
36 return FB_BLANK_POWERDOWN; /* PW OFF */ 34 return FB_BLANK_POWERDOWN; /* PW OFF */
37} 35}
38 36
39static int jornada_lcd_get_contrast(struct lcd_device *dev) 37static int jornada_lcd_get_contrast(struct lcd_device *ld)
40{ 38{
41 int ret; 39 int ret;
42 40
43 if (jornada_lcd_get_power(dev) != FB_BLANK_UNBLANK) 41 if (jornada_lcd_get_power(ld) != FB_BLANK_UNBLANK)
44 return 0; 42 return 0;
45 43
46 jornada_ssp_start(); 44 jornada_ssp_start();
47 45
48 if (jornada_ssp_byte(GETCONTRAST) != TXDUMMY) { 46 if (jornada_ssp_byte(GETCONTRAST) != TXDUMMY) {
49 pr_err("get contrast failed\n"); 47 dev_err(&ld->dev, "get contrast failed\n");
50 jornada_ssp_end(); 48 jornada_ssp_end();
51 return -ETIMEDOUT; 49 return -ETIMEDOUT;
52 } else { 50 } else {
@@ -56,7 +54,7 @@ static int jornada_lcd_get_contrast(struct lcd_device *dev)
56 } 54 }
57} 55}
58 56
59static int jornada_lcd_set_contrast(struct lcd_device *dev, int value) 57static int jornada_lcd_set_contrast(struct lcd_device *ld, int value)
60{ 58{
61 int ret; 59 int ret;
62 60
@@ -67,7 +65,7 @@ static int jornada_lcd_set_contrast(struct lcd_device *dev, int value)
67 65
68 /* push the new value */ 66 /* push the new value */
69 if (jornada_ssp_byte(value) != TXDUMMY) { 67 if (jornada_ssp_byte(value) != TXDUMMY) {
70 pr_err("set contrast failed\n"); 68 dev_err(&ld->dev, "set contrast failed\n");
71 jornada_ssp_end(); 69 jornada_ssp_end();
72 return -ETIMEDOUT; 70 return -ETIMEDOUT;
73 } 71 }
@@ -78,13 +76,14 @@ static int jornada_lcd_set_contrast(struct lcd_device *dev, int value)
78 return 0; 76 return 0;
79} 77}
80 78
81static int jornada_lcd_set_power(struct lcd_device *dev, int power) 79static int jornada_lcd_set_power(struct lcd_device *ld, int power)
82{ 80{
83 if (power != FB_BLANK_UNBLANK) { 81 if (power != FB_BLANK_UNBLANK) {
84 PPSR &= ~PPC_LDD2; 82 PPSR &= ~PPC_LDD2;
85 PPDR |= PPC_LDD2; 83 PPDR |= PPC_LDD2;
86 } else 84 } else {
87 PPSR |= PPC_LDD2; 85 PPSR |= PPC_LDD2;
86 }
88 87
89 return 0; 88 return 0;
90} 89}
@@ -105,7 +104,7 @@ static int jornada_lcd_probe(struct platform_device *pdev)
105 104
106 if (IS_ERR(lcd_device)) { 105 if (IS_ERR(lcd_device)) {
107 ret = PTR_ERR(lcd_device); 106 ret = PTR_ERR(lcd_device);
108 pr_err("failed to register device\n"); 107 dev_err(&pdev->dev, "failed to register device\n");
109 return ret; 108 return ret;
110 } 109 }
111 110
diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
index 6c5ed6b242cc..bca6ccc74dfb 100644
--- a/drivers/video/backlight/kb3886_bl.c
+++ b/drivers/video/backlight/kb3886_bl.c
@@ -106,29 +106,28 @@ static int kb3886bl_send_intensity(struct backlight_device *bd)
106 return 0; 106 return 0;
107} 107}
108 108
109#ifdef CONFIG_PM 109#ifdef CONFIG_PM_SLEEP
110static int kb3886bl_suspend(struct platform_device *pdev, pm_message_t state) 110static int kb3886bl_suspend(struct device *dev)
111{ 111{
112 struct backlight_device *bd = platform_get_drvdata(pdev); 112 struct backlight_device *bd = dev_get_drvdata(dev);
113 113
114 kb3886bl_flags |= KB3886BL_SUSPENDED; 114 kb3886bl_flags |= KB3886BL_SUSPENDED;
115 backlight_update_status(bd); 115 backlight_update_status(bd);
116 return 0; 116 return 0;
117} 117}
118 118
119static int kb3886bl_resume(struct platform_device *pdev) 119static int kb3886bl_resume(struct device *dev)
120{ 120{
121 struct backlight_device *bd = platform_get_drvdata(pdev); 121 struct backlight_device *bd = dev_get_drvdata(dev);
122 122
123 kb3886bl_flags &= ~KB3886BL_SUSPENDED; 123 kb3886bl_flags &= ~KB3886BL_SUSPENDED;
124 backlight_update_status(bd); 124 backlight_update_status(bd);
125 return 0; 125 return 0;
126} 126}
127#else
128#define kb3886bl_suspend NULL
129#define kb3886bl_resume NULL
130#endif 127#endif
131 128
129static SIMPLE_DEV_PM_OPS(kb3886bl_pm_ops, kb3886bl_suspend, kb3886bl_resume);
130
132static int kb3886bl_get_intensity(struct backlight_device *bd) 131static int kb3886bl_get_intensity(struct backlight_device *bd)
133{ 132{
134 return kb3886bl_intensity; 133 return kb3886bl_intensity;
@@ -179,10 +178,9 @@ static int kb3886bl_remove(struct platform_device *pdev)
179static struct platform_driver kb3886bl_driver = { 178static struct platform_driver kb3886bl_driver = {
180 .probe = kb3886bl_probe, 179 .probe = kb3886bl_probe,
181 .remove = kb3886bl_remove, 180 .remove = kb3886bl_remove,
182 .suspend = kb3886bl_suspend,
183 .resume = kb3886bl_resume,
184 .driver = { 181 .driver = {
185 .name = "kb3886-bl", 182 .name = "kb3886-bl",
183 .pm = &kb3886bl_pm_ops,
186 }, 184 },
187}; 185};
188 186
diff --git a/drivers/video/backlight/l4f00242t03.c b/drivers/video/backlight/l4f00242t03.c
index fb6155771326..a35a38c709cf 100644
--- a/drivers/video/backlight/l4f00242t03.c
+++ b/drivers/video/backlight/l4f00242t03.c
@@ -51,14 +51,33 @@ static void l4f00242t03_lcd_init(struct spi_device *spi)
51 struct l4f00242t03_pdata *pdata = spi->dev.platform_data; 51 struct l4f00242t03_pdata *pdata = spi->dev.platform_data;
52 struct l4f00242t03_priv *priv = spi_get_drvdata(spi); 52 struct l4f00242t03_priv *priv = spi_get_drvdata(spi);
53 const u16 cmd[] = { 0x36, param(0), 0x3A, param(0x60) }; 53 const u16 cmd[] = { 0x36, param(0), 0x3A, param(0x60) };
54 int ret;
54 55
55 dev_dbg(&spi->dev, "initializing LCD\n"); 56 dev_dbg(&spi->dev, "initializing LCD\n");
56 57
57 regulator_set_voltage(priv->io_reg, 1800000, 1800000); 58 ret = regulator_set_voltage(priv->io_reg, 1800000, 1800000);
58 regulator_enable(priv->io_reg); 59 if (ret) {
60 dev_err(&spi->dev, "failed to set the IO regulator voltage.\n");
61 return;
62 }
63 ret = regulator_enable(priv->io_reg);
64 if (ret) {
65 dev_err(&spi->dev, "failed to enable the IO regulator.\n");
66 return;
67 }
59 68
60 regulator_set_voltage(priv->core_reg, 2800000, 2800000); 69 ret = regulator_set_voltage(priv->core_reg, 2800000, 2800000);
61 regulator_enable(priv->core_reg); 70 if (ret) {
71 dev_err(&spi->dev, "failed to set the core regulator voltage.\n");
72 regulator_disable(priv->io_reg);
73 return;
74 }
75 ret = regulator_enable(priv->core_reg);
76 if (ret) {
77 dev_err(&spi->dev, "failed to enable the core regulator.\n");
78 regulator_disable(priv->io_reg);
79 return;
80 }
62 81
63 l4f00242t03_reset(pdata->reset_gpio); 82 l4f00242t03_reset(pdata->reset_gpio);
64 83
diff --git a/drivers/video/backlight/ld9040.c b/drivers/video/backlight/ld9040.c
index 1b642f5f381a..1e0a3093ce50 100644
--- a/drivers/video/backlight/ld9040.c
+++ b/drivers/video/backlight/ld9040.c
@@ -775,12 +775,12 @@ static int ld9040_remove(struct spi_device *spi)
775 return 0; 775 return 0;
776} 776}
777 777
778#if defined(CONFIG_PM) 778#ifdef CONFIG_PM_SLEEP
779static int ld9040_suspend(struct spi_device *spi, pm_message_t mesg) 779static int ld9040_suspend(struct device *dev)
780{ 780{
781 struct ld9040 *lcd = spi_get_drvdata(spi); 781 struct ld9040 *lcd = dev_get_drvdata(dev);
782 782
783 dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power); 783 dev_dbg(dev, "lcd->power = %d\n", lcd->power);
784 784
785 /* 785 /*
786 * when lcd panel is suspend, lcd panel becomes off 786 * when lcd panel is suspend, lcd panel becomes off
@@ -789,19 +789,18 @@ static int ld9040_suspend(struct spi_device *spi, pm_message_t mesg)
789 return ld9040_power(lcd, FB_BLANK_POWERDOWN); 789 return ld9040_power(lcd, FB_BLANK_POWERDOWN);
790} 790}
791 791
792static int ld9040_resume(struct spi_device *spi) 792static int ld9040_resume(struct device *dev)
793{ 793{
794 struct ld9040 *lcd = spi_get_drvdata(spi); 794 struct ld9040 *lcd = dev_get_drvdata(dev);
795 795
796 lcd->power = FB_BLANK_POWERDOWN; 796 lcd->power = FB_BLANK_POWERDOWN;
797 797
798 return ld9040_power(lcd, FB_BLANK_UNBLANK); 798 return ld9040_power(lcd, FB_BLANK_UNBLANK);
799} 799}
800#else
801#define ld9040_suspend NULL
802#define ld9040_resume NULL
803#endif 800#endif
804 801
802static SIMPLE_DEV_PM_OPS(ld9040_pm_ops, ld9040_suspend, ld9040_resume);
803
805/* Power down all displays on reboot, poweroff or halt. */ 804/* Power down all displays on reboot, poweroff or halt. */
806static void ld9040_shutdown(struct spi_device *spi) 805static void ld9040_shutdown(struct spi_device *spi)
807{ 806{
@@ -814,12 +813,11 @@ static struct spi_driver ld9040_driver = {
814 .driver = { 813 .driver = {
815 .name = "ld9040", 814 .name = "ld9040",
816 .owner = THIS_MODULE, 815 .owner = THIS_MODULE,
816 .pm = &ld9040_pm_ops,
817 }, 817 },
818 .probe = ld9040_probe, 818 .probe = ld9040_probe,
819 .remove = ld9040_remove, 819 .remove = ld9040_remove,
820 .shutdown = ld9040_shutdown, 820 .shutdown = ld9040_shutdown,
821 .suspend = ld9040_suspend,
822 .resume = ld9040_resume,
823}; 821};
824 822
825module_spi_driver(ld9040_driver); 823module_spi_driver(ld9040_driver);
diff --git a/drivers/video/backlight/lm3533_bl.c b/drivers/video/backlight/lm3533_bl.c
index 5d18d4d7f470..1d1dbfb789e3 100644
--- a/drivers/video/backlight/lm3533_bl.c
+++ b/drivers/video/backlight/lm3533_bl.c
@@ -368,29 +368,28 @@ static int lm3533_bl_remove(struct platform_device *pdev)
368 return 0; 368 return 0;
369} 369}
370 370
371#ifdef CONFIG_PM 371#ifdef CONFIG_PM_SLEEP
372static int lm3533_bl_suspend(struct platform_device *pdev, pm_message_t state) 372static int lm3533_bl_suspend(struct device *dev)
373{ 373{
374 struct lm3533_bl *bl = platform_get_drvdata(pdev); 374 struct lm3533_bl *bl = dev_get_drvdata(dev);
375 375
376 dev_dbg(&pdev->dev, "%s\n", __func__); 376 dev_dbg(dev, "%s\n", __func__);
377 377
378 return lm3533_ctrlbank_disable(&bl->cb); 378 return lm3533_ctrlbank_disable(&bl->cb);
379} 379}
380 380
381static int lm3533_bl_resume(struct platform_device *pdev) 381static int lm3533_bl_resume(struct device *dev)
382{ 382{
383 struct lm3533_bl *bl = platform_get_drvdata(pdev); 383 struct lm3533_bl *bl = dev_get_drvdata(dev);
384 384
385 dev_dbg(&pdev->dev, "%s\n", __func__); 385 dev_dbg(dev, "%s\n", __func__);
386 386
387 return lm3533_ctrlbank_enable(&bl->cb); 387 return lm3533_ctrlbank_enable(&bl->cb);
388} 388}
389#else
390#define lm3533_bl_suspend NULL
391#define lm3533_bl_resume NULL
392#endif 389#endif
393 390
391static SIMPLE_DEV_PM_OPS(lm3533_bl_pm_ops, lm3533_bl_suspend, lm3533_bl_resume);
392
394static void lm3533_bl_shutdown(struct platform_device *pdev) 393static void lm3533_bl_shutdown(struct platform_device *pdev)
395{ 394{
396 struct lm3533_bl *bl = platform_get_drvdata(pdev); 395 struct lm3533_bl *bl = platform_get_drvdata(pdev);
@@ -404,12 +403,11 @@ static struct platform_driver lm3533_bl_driver = {
404 .driver = { 403 .driver = {
405 .name = "lm3533-backlight", 404 .name = "lm3533-backlight",
406 .owner = THIS_MODULE, 405 .owner = THIS_MODULE,
406 .pm = &lm3533_bl_pm_ops,
407 }, 407 },
408 .probe = lm3533_bl_probe, 408 .probe = lm3533_bl_probe,
409 .remove = lm3533_bl_remove, 409 .remove = lm3533_bl_remove,
410 .shutdown = lm3533_bl_shutdown, 410 .shutdown = lm3533_bl_shutdown,
411 .suspend = lm3533_bl_suspend,
412 .resume = lm3533_bl_resume,
413}; 411};
414module_platform_driver(lm3533_bl_driver); 412module_platform_driver(lm3533_bl_driver);
415 413
diff --git a/drivers/video/backlight/lms501kf03.c b/drivers/video/backlight/lms501kf03.c
index b43882abefaf..cf01b9ac8131 100644
--- a/drivers/video/backlight/lms501kf03.c
+++ b/drivers/video/backlight/lms501kf03.c
@@ -387,13 +387,12 @@ static int lms501kf03_remove(struct spi_device *spi)
387 return 0; 387 return 0;
388} 388}
389 389
390#if defined(CONFIG_PM) 390#ifdef CONFIG_PM_SLEEP
391 391static int lms501kf03_suspend(struct device *dev)
392static int lms501kf03_suspend(struct spi_device *spi, pm_message_t mesg)
393{ 392{
394 struct lms501kf03 *lcd = spi_get_drvdata(spi); 393 struct lms501kf03 *lcd = dev_get_drvdata(dev);
395 394
396 dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power); 395 dev_dbg(dev, "lcd->power = %d\n", lcd->power);
397 396
398 /* 397 /*
399 * when lcd panel is suspend, lcd panel becomes off 398 * when lcd panel is suspend, lcd panel becomes off
@@ -402,19 +401,19 @@ static int lms501kf03_suspend(struct spi_device *spi, pm_message_t mesg)
402 return lms501kf03_power(lcd, FB_BLANK_POWERDOWN); 401 return lms501kf03_power(lcd, FB_BLANK_POWERDOWN);
403} 402}
404 403
405static int lms501kf03_resume(struct spi_device *spi) 404static int lms501kf03_resume(struct device *dev)
406{ 405{
407 struct lms501kf03 *lcd = spi_get_drvdata(spi); 406 struct lms501kf03 *lcd = dev_get_drvdata(dev);
408 407
409 lcd->power = FB_BLANK_POWERDOWN; 408 lcd->power = FB_BLANK_POWERDOWN;
410 409
411 return lms501kf03_power(lcd, FB_BLANK_UNBLANK); 410 return lms501kf03_power(lcd, FB_BLANK_UNBLANK);
412} 411}
413#else
414#define lms501kf03_suspend NULL
415#define lms501kf03_resume NULL
416#endif 412#endif
417 413
414static SIMPLE_DEV_PM_OPS(lms501kf03_pm_ops, lms501kf03_suspend,
415 lms501kf03_resume);
416
418static void lms501kf03_shutdown(struct spi_device *spi) 417static void lms501kf03_shutdown(struct spi_device *spi)
419{ 418{
420 struct lms501kf03 *lcd = spi_get_drvdata(spi); 419 struct lms501kf03 *lcd = spi_get_drvdata(spi);
@@ -426,12 +425,11 @@ static struct spi_driver lms501kf03_driver = {
426 .driver = { 425 .driver = {
427 .name = "lms501kf03", 426 .name = "lms501kf03",
428 .owner = THIS_MODULE, 427 .owner = THIS_MODULE,
428 .pm = &lms501kf03_pm_ops,
429 }, 429 },
430 .probe = lms501kf03_probe, 430 .probe = lms501kf03_probe,
431 .remove = lms501kf03_remove, 431 .remove = lms501kf03_remove,
432 .shutdown = lms501kf03_shutdown, 432 .shutdown = lms501kf03_shutdown,
433 .suspend = lms501kf03_suspend,
434 .resume = lms501kf03_resume,
435}; 433};
436 434
437module_spi_driver(lms501kf03_driver); 435module_spi_driver(lms501kf03_driver);
diff --git a/drivers/video/backlight/locomolcd.c b/drivers/video/backlight/locomolcd.c
index 146fea8aa431..6c3ec4259a60 100644
--- a/drivers/video/backlight/locomolcd.c
+++ b/drivers/video/backlight/locomolcd.c
@@ -157,25 +157,24 @@ static const struct backlight_ops locomobl_data = {
157 .update_status = locomolcd_set_intensity, 157 .update_status = locomolcd_set_intensity,
158}; 158};
159 159
160#ifdef CONFIG_PM 160#ifdef CONFIG_PM_SLEEP
161static int locomolcd_suspend(struct locomo_dev *dev, pm_message_t state) 161static int locomolcd_suspend(struct device *dev)
162{ 162{
163 locomolcd_flags |= LOCOMOLCD_SUSPENDED; 163 locomolcd_flags |= LOCOMOLCD_SUSPENDED;
164 locomolcd_set_intensity(locomolcd_bl_device); 164 locomolcd_set_intensity(locomolcd_bl_device);
165 return 0; 165 return 0;
166} 166}
167 167
168static int locomolcd_resume(struct locomo_dev *dev) 168static int locomolcd_resume(struct device *dev)
169{ 169{
170 locomolcd_flags &= ~LOCOMOLCD_SUSPENDED; 170 locomolcd_flags &= ~LOCOMOLCD_SUSPENDED;
171 locomolcd_set_intensity(locomolcd_bl_device); 171 locomolcd_set_intensity(locomolcd_bl_device);
172 return 0; 172 return 0;
173} 173}
174#else
175#define locomolcd_suspend NULL
176#define locomolcd_resume NULL
177#endif 174#endif
178 175
176static SIMPLE_DEV_PM_OPS(locomolcd_pm_ops, locomolcd_suspend, locomolcd_resume);
177
179static int locomolcd_probe(struct locomo_dev *ldev) 178static int locomolcd_probe(struct locomo_dev *ldev)
180{ 179{
181 struct backlight_properties props; 180 struct backlight_properties props;
@@ -230,13 +229,12 @@ static int locomolcd_remove(struct locomo_dev *dev)
230 229
231static struct locomo_driver poodle_lcd_driver = { 230static struct locomo_driver poodle_lcd_driver = {
232 .drv = { 231 .drv = {
233 .name = "locomo-backlight", 232 .name = "locomo-backlight",
233 .pm = &locomolcd_pm_ops,
234 }, 234 },
235 .devid = LOCOMO_DEVID_BACKLIGHT, 235 .devid = LOCOMO_DEVID_BACKLIGHT,
236 .probe = locomolcd_probe, 236 .probe = locomolcd_probe,
237 .remove = locomolcd_remove, 237 .remove = locomolcd_remove,
238 .suspend = locomolcd_suspend,
239 .resume = locomolcd_resume,
240}; 238};
241 239
242static int __init locomolcd_init(void) 240static int __init locomolcd_init(void)
diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index 7ae9ae6f4655..a0e1e02bdc2e 100644
--- a/drivers/video/backlight/lp855x_bl.c
+++ b/drivers/video/backlight/lp855x_bl.c
@@ -14,6 +14,7 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/backlight.h> 15#include <linux/backlight.h>
16#include <linux/err.h> 16#include <linux/err.h>
17#include <linux/of.h>
17#include <linux/platform_data/lp855x.h> 18#include <linux/platform_data/lp855x.h>
18#include <linux/pwm.h> 19#include <linux/pwm.h>
19 20
@@ -35,10 +36,14 @@
35#define LP8557_EPROM_START 0x10 36#define LP8557_EPROM_START 0x10
36#define LP8557_EPROM_END 0x1E 37#define LP8557_EPROM_END 0x1E
37 38
38#define BUF_SIZE 20
39#define DEFAULT_BL_NAME "lcd-backlight" 39#define DEFAULT_BL_NAME "lcd-backlight"
40#define MAX_BRIGHTNESS 255 40#define MAX_BRIGHTNESS 255
41 41
42enum lp855x_brightness_ctrl_mode {
43 PWM_BASED = 1,
44 REGISTER_BASED,
45};
46
42struct lp855x; 47struct lp855x;
43 48
44/* 49/*
@@ -58,6 +63,7 @@ struct lp855x_device_config {
58struct lp855x { 63struct lp855x {
59 const char *chipname; 64 const char *chipname;
60 enum lp855x_chip_id chip_id; 65 enum lp855x_chip_id chip_id;
66 enum lp855x_brightness_ctrl_mode mode;
61 struct lp855x_device_config *cfg; 67 struct lp855x_device_config *cfg;
62 struct i2c_client *client; 68 struct i2c_client *client;
63 struct backlight_device *bl; 69 struct backlight_device *bl;
@@ -187,7 +193,7 @@ static int lp855x_configure(struct lp855x *lp)
187 if (ret) 193 if (ret)
188 goto err; 194 goto err;
189 195
190 if (pd->load_new_rom_data && pd->size_program) { 196 if (pd->size_program > 0) {
191 for (i = 0; i < pd->size_program; i++) { 197 for (i = 0; i < pd->size_program; i++) {
192 addr = pd->rom_data[i].addr; 198 addr = pd->rom_data[i].addr;
193 val = pd->rom_data[i].val; 199 val = pd->rom_data[i].val;
@@ -239,18 +245,17 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
239static int lp855x_bl_update_status(struct backlight_device *bl) 245static int lp855x_bl_update_status(struct backlight_device *bl)
240{ 246{
241 struct lp855x *lp = bl_get_data(bl); 247 struct lp855x *lp = bl_get_data(bl);
242 enum lp855x_brightness_ctrl_mode mode = lp->pdata->mode;
243 248
244 if (bl->props.state & BL_CORE_SUSPENDED) 249 if (bl->props.state & BL_CORE_SUSPENDED)
245 bl->props.brightness = 0; 250 bl->props.brightness = 0;
246 251
247 if (mode == PWM_BASED) { 252 if (lp->mode == PWM_BASED) {
248 int br = bl->props.brightness; 253 int br = bl->props.brightness;
249 int max_br = bl->props.max_brightness; 254 int max_br = bl->props.max_brightness;
250 255
251 lp855x_pwm_ctrl(lp, br, max_br); 256 lp855x_pwm_ctrl(lp, br, max_br);
252 257
253 } else if (mode == REGISTER_BASED) { 258 } else if (lp->mode == REGISTER_BASED) {
254 u8 val = bl->props.brightness; 259 u8 val = bl->props.brightness;
255 lp855x_write_byte(lp, lp->cfg->reg_brightness, val); 260 lp855x_write_byte(lp, lp->cfg->reg_brightness, val);
256 } 261 }
@@ -274,7 +279,7 @@ static int lp855x_backlight_register(struct lp855x *lp)
274 struct backlight_device *bl; 279 struct backlight_device *bl;
275 struct backlight_properties props; 280 struct backlight_properties props;
276 struct lp855x_platform_data *pdata = lp->pdata; 281 struct lp855x_platform_data *pdata = lp->pdata;
277 char *name = pdata->name ? : DEFAULT_BL_NAME; 282 const char *name = pdata->name ? : DEFAULT_BL_NAME;
278 283
279 props.type = BACKLIGHT_PLATFORM; 284 props.type = BACKLIGHT_PLATFORM;
280 props.max_brightness = MAX_BRIGHTNESS; 285 props.max_brightness = MAX_BRIGHTNESS;
@@ -304,22 +309,21 @@ static ssize_t lp855x_get_chip_id(struct device *dev,
304 struct device_attribute *attr, char *buf) 309 struct device_attribute *attr, char *buf)
305{ 310{
306 struct lp855x *lp = dev_get_drvdata(dev); 311 struct lp855x *lp = dev_get_drvdata(dev);
307 return scnprintf(buf, BUF_SIZE, "%s\n", lp->chipname); 312 return scnprintf(buf, PAGE_SIZE, "%s\n", lp->chipname);
308} 313}
309 314
310static ssize_t lp855x_get_bl_ctl_mode(struct device *dev, 315static ssize_t lp855x_get_bl_ctl_mode(struct device *dev,
311 struct device_attribute *attr, char *buf) 316 struct device_attribute *attr, char *buf)
312{ 317{
313 struct lp855x *lp = dev_get_drvdata(dev); 318 struct lp855x *lp = dev_get_drvdata(dev);
314 enum lp855x_brightness_ctrl_mode mode = lp->pdata->mode;
315 char *strmode = NULL; 319 char *strmode = NULL;
316 320
317 if (mode == PWM_BASED) 321 if (lp->mode == PWM_BASED)
318 strmode = "pwm based"; 322 strmode = "pwm based";
319 else if (mode == REGISTER_BASED) 323 else if (lp->mode == REGISTER_BASED)
320 strmode = "register based"; 324 strmode = "register based";
321 325
322 return scnprintf(buf, BUF_SIZE, "%s\n", strmode); 326 return scnprintf(buf, PAGE_SIZE, "%s\n", strmode);
323} 327}
324 328
325static DEVICE_ATTR(chip_id, S_IRUGO, lp855x_get_chip_id, NULL); 329static DEVICE_ATTR(chip_id, S_IRUGO, lp855x_get_chip_id, NULL);
@@ -335,16 +339,71 @@ static const struct attribute_group lp855x_attr_group = {
335 .attrs = lp855x_attributes, 339 .attrs = lp855x_attributes,
336}; 340};
337 341
342#ifdef CONFIG_OF
343static int lp855x_parse_dt(struct device *dev, struct device_node *node)
344{
345 struct lp855x_platform_data *pdata;
346 int rom_length;
347
348 if (!node) {
349 dev_err(dev, "no platform data\n");
350 return -EINVAL;
351 }
352
353 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
354 if (!pdata)
355 return -ENOMEM;
356
357 of_property_read_string(node, "bl-name", &pdata->name);
358 of_property_read_u8(node, "dev-ctrl", &pdata->device_control);
359 of_property_read_u8(node, "init-brt", &pdata->initial_brightness);
360 of_property_read_u32(node, "pwm-period", &pdata->period_ns);
361
362 /* Fill ROM platform data if defined */
363 rom_length = of_get_child_count(node);
364 if (rom_length > 0) {
365 struct lp855x_rom_data *rom;
366 struct device_node *child;
367 int i = 0;
368
369 rom = devm_kzalloc(dev, sizeof(*rom) * rom_length, GFP_KERNEL);
370 if (!rom)
371 return -ENOMEM;
372
373 for_each_child_of_node(node, child) {
374 of_property_read_u8(child, "rom-addr", &rom[i].addr);
375 of_property_read_u8(child, "rom-val", &rom[i].val);
376 i++;
377 }
378
379 pdata->size_program = rom_length;
380 pdata->rom_data = &rom[0];
381 }
382
383 dev->platform_data = pdata;
384
385 return 0;
386}
387#else
388static int lp855x_parse_dt(struct device *dev, struct device_node *node)
389{
390 return -EINVAL;
391}
392#endif
393
338static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id) 394static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
339{ 395{
340 struct lp855x *lp; 396 struct lp855x *lp;
341 struct lp855x_platform_data *pdata = cl->dev.platform_data; 397 struct lp855x_platform_data *pdata = cl->dev.platform_data;
342 enum lp855x_brightness_ctrl_mode mode; 398 struct device_node *node = cl->dev.of_node;
343 int ret; 399 int ret;
344 400
345 if (!pdata) { 401 if (!pdata) {
346 dev_err(&cl->dev, "no platform data supplied\n"); 402 ret = lp855x_parse_dt(&cl->dev, node);
347 return -EINVAL; 403 if (ret < 0)
404 return ret;
405
406 pdata = cl->dev.platform_data;
348 } 407 }
349 408
350 if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) 409 if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
@@ -354,7 +413,11 @@ static int lp855x_probe(struct i2c_client *cl, const struct i2c_device_id *id)
354 if (!lp) 413 if (!lp)
355 return -ENOMEM; 414 return -ENOMEM;
356 415
357 mode = pdata->mode; 416 if (pdata->period_ns > 0)
417 lp->mode = PWM_BASED;
418 else
419 lp->mode = REGISTER_BASED;
420
358 lp->client = cl; 421 lp->client = cl;
359 lp->dev = &cl->dev; 422 lp->dev = &cl->dev;
360 lp->pdata = pdata; 423 lp->pdata = pdata;
@@ -402,6 +465,17 @@ static int lp855x_remove(struct i2c_client *cl)
402 return 0; 465 return 0;
403} 466}
404 467
468static const struct of_device_id lp855x_dt_ids[] = {
469 { .compatible = "ti,lp8550", },
470 { .compatible = "ti,lp8551", },
471 { .compatible = "ti,lp8552", },
472 { .compatible = "ti,lp8553", },
473 { .compatible = "ti,lp8556", },
474 { .compatible = "ti,lp8557", },
475 { }
476};
477MODULE_DEVICE_TABLE(of, lp855x_dt_ids);
478
405static const struct i2c_device_id lp855x_ids[] = { 479static const struct i2c_device_id lp855x_ids[] = {
406 {"lp8550", LP8550}, 480 {"lp8550", LP8550},
407 {"lp8551", LP8551}, 481 {"lp8551", LP8551},
@@ -416,6 +490,7 @@ MODULE_DEVICE_TABLE(i2c, lp855x_ids);
416static struct i2c_driver lp855x_driver = { 490static struct i2c_driver lp855x_driver = {
417 .driver = { 491 .driver = {
418 .name = "lp855x", 492 .name = "lp855x",
493 .of_match_table = of_match_ptr(lp855x_dt_ids),
419 }, 494 },
420 .probe = lp855x_probe, 495 .probe = lp855x_probe,
421 .remove = lp855x_remove, 496 .remove = lp855x_remove,
diff --git a/drivers/video/backlight/ltv350qv.c b/drivers/video/backlight/ltv350qv.c
index c0b4b8f2de98..ed1b39268131 100644
--- a/drivers/video/backlight/ltv350qv.c
+++ b/drivers/video/backlight/ltv350qv.c
@@ -271,25 +271,24 @@ static int ltv350qv_remove(struct spi_device *spi)
271 return 0; 271 return 0;
272} 272}
273 273
274#ifdef CONFIG_PM 274#ifdef CONFIG_PM_SLEEP
275static int ltv350qv_suspend(struct spi_device *spi, pm_message_t state) 275static int ltv350qv_suspend(struct device *dev)
276{ 276{
277 struct ltv350qv *lcd = spi_get_drvdata(spi); 277 struct ltv350qv *lcd = dev_get_drvdata(dev);
278 278
279 return ltv350qv_power(lcd, FB_BLANK_POWERDOWN); 279 return ltv350qv_power(lcd, FB_BLANK_POWERDOWN);
280} 280}
281 281
282static int ltv350qv_resume(struct spi_device *spi) 282static int ltv350qv_resume(struct device *dev)
283{ 283{
284 struct ltv350qv *lcd = spi_get_drvdata(spi); 284 struct ltv350qv *lcd = dev_get_drvdata(dev);
285 285
286 return ltv350qv_power(lcd, FB_BLANK_UNBLANK); 286 return ltv350qv_power(lcd, FB_BLANK_UNBLANK);
287} 287}
288#else
289#define ltv350qv_suspend NULL
290#define ltv350qv_resume NULL
291#endif 288#endif
292 289
290static SIMPLE_DEV_PM_OPS(ltv350qv_pm_ops, ltv350qv_suspend, ltv350qv_resume);
291
293/* Power down all displays on reboot, poweroff or halt */ 292/* Power down all displays on reboot, poweroff or halt */
294static void ltv350qv_shutdown(struct spi_device *spi) 293static void ltv350qv_shutdown(struct spi_device *spi)
295{ 294{
@@ -302,13 +301,12 @@ static struct spi_driver ltv350qv_driver = {
302 .driver = { 301 .driver = {
303 .name = "ltv350qv", 302 .name = "ltv350qv",
304 .owner = THIS_MODULE, 303 .owner = THIS_MODULE,
304 .pm = &ltv350qv_pm_ops,
305 }, 305 },
306 306
307 .probe = ltv350qv_probe, 307 .probe = ltv350qv_probe,
308 .remove = ltv350qv_remove, 308 .remove = ltv350qv_remove,
309 .shutdown = ltv350qv_shutdown, 309 .shutdown = ltv350qv_shutdown,
310 .suspend = ltv350qv_suspend,
311 .resume = ltv350qv_resume,
312}; 310};
313 311
314module_spi_driver(ltv350qv_driver); 312module_spi_driver(ltv350qv_driver);
diff --git a/drivers/video/backlight/omap1_bl.c b/drivers/video/backlight/omap1_bl.c
index 627110163067..812e22e35cab 100644
--- a/drivers/video/backlight/omap1_bl.c
+++ b/drivers/video/backlight/omap1_bl.c
@@ -18,8 +18,6 @@
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */ 19 */
20 20
21#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
23#include <linux/module.h> 21#include <linux/module.h>
24#include <linux/kernel.h> 22#include <linux/kernel.h>
25#include <linux/init.h> 23#include <linux/init.h>
@@ -73,27 +71,24 @@ static void omapbl_blank(struct omap_backlight *bl, int mode)
73 } 71 }
74} 72}
75 73
76#ifdef CONFIG_PM 74#ifdef CONFIG_PM_SLEEP
77static int omapbl_suspend(struct platform_device *pdev, pm_message_t state) 75static int omapbl_suspend(struct device *dev)
78{ 76{
79 struct backlight_device *dev = platform_get_drvdata(pdev); 77 struct backlight_device *bl_dev = dev_get_drvdata(dev);
80 struct omap_backlight *bl = bl_get_data(dev); 78 struct omap_backlight *bl = bl_get_data(bl_dev);
81 79
82 omapbl_blank(bl, FB_BLANK_POWERDOWN); 80 omapbl_blank(bl, FB_BLANK_POWERDOWN);
83 return 0; 81 return 0;
84} 82}
85 83
86static int omapbl_resume(struct platform_device *pdev) 84static int omapbl_resume(struct device *dev)
87{ 85{
88 struct backlight_device *dev = platform_get_drvdata(pdev); 86 struct backlight_device *bl_dev = dev_get_drvdata(dev);
89 struct omap_backlight *bl = bl_get_data(dev); 87 struct omap_backlight *bl = bl_get_data(bl_dev);
90 88
91 omapbl_blank(bl, bl->powermode); 89 omapbl_blank(bl, bl->powermode);
92 return 0; 90 return 0;
93} 91}
94#else
95#define omapbl_suspend NULL
96#define omapbl_resume NULL
97#endif 92#endif
98 93
99static int omapbl_set_power(struct backlight_device *dev, int state) 94static int omapbl_set_power(struct backlight_device *dev, int state)
@@ -170,7 +165,7 @@ static int omapbl_probe(struct platform_device *pdev)
170 dev->props.brightness = pdata->default_intensity; 165 dev->props.brightness = pdata->default_intensity;
171 omapbl_update_status(dev); 166 omapbl_update_status(dev);
172 167
173 pr_info("OMAP LCD backlight initialised\n"); 168 dev_info(&pdev->dev, "OMAP LCD backlight initialised\n");
174 169
175 return 0; 170 return 0;
176} 171}
@@ -184,13 +179,14 @@ static int omapbl_remove(struct platform_device *pdev)
184 return 0; 179 return 0;
185} 180}
186 181
182static SIMPLE_DEV_PM_OPS(omapbl_pm_ops, omapbl_suspend, omapbl_resume);
183
187static struct platform_driver omapbl_driver = { 184static struct platform_driver omapbl_driver = {
188 .probe = omapbl_probe, 185 .probe = omapbl_probe,
189 .remove = omapbl_remove, 186 .remove = omapbl_remove,
190 .suspend = omapbl_suspend,
191 .resume = omapbl_resume,
192 .driver = { 187 .driver = {
193 .name = "omap-bl", 188 .name = "omap-bl",
189 .pm = &omapbl_pm_ops,
194 }, 190 },
195}; 191};
196 192
diff --git a/drivers/video/backlight/platform_lcd.c b/drivers/video/backlight/platform_lcd.c
index 17a6b83f97af..056836706708 100644
--- a/drivers/video/backlight/platform_lcd.c
+++ b/drivers/video/backlight/platform_lcd.c
@@ -86,6 +86,12 @@ static int platform_lcd_probe(struct platform_device *pdev)
86 return -EINVAL; 86 return -EINVAL;
87 } 87 }
88 88
89 if (pdata->probe) {
90 err = pdata->probe(pdata);
91 if (err)
92 return err;
93 }
94
89 plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd), 95 plcd = devm_kzalloc(&pdev->dev, sizeof(struct platform_lcd),
90 GFP_KERNEL); 96 GFP_KERNEL);
91 if (!plcd) { 97 if (!plcd) {
@@ -121,7 +127,7 @@ static int platform_lcd_remove(struct platform_device *pdev)
121 return 0; 127 return 0;
122} 128}
123 129
124#ifdef CONFIG_PM 130#ifdef CONFIG_PM_SLEEP
125static int platform_lcd_suspend(struct device *dev) 131static int platform_lcd_suspend(struct device *dev)
126{ 132{
127 struct platform_lcd *plcd = dev_get_drvdata(dev); 133 struct platform_lcd *plcd = dev_get_drvdata(dev);
@@ -141,10 +147,10 @@ static int platform_lcd_resume(struct device *dev)
141 147
142 return 0; 148 return 0;
143} 149}
150#endif
144 151
145static SIMPLE_DEV_PM_OPS(platform_lcd_pm_ops, platform_lcd_suspend, 152static SIMPLE_DEV_PM_OPS(platform_lcd_pm_ops, platform_lcd_suspend,
146 platform_lcd_resume); 153 platform_lcd_resume);
147#endif
148 154
149#ifdef CONFIG_OF 155#ifdef CONFIG_OF
150static const struct of_device_id platform_lcd_of_match[] = { 156static const struct of_device_id platform_lcd_of_match[] = {
@@ -158,9 +164,7 @@ static struct platform_driver platform_lcd_driver = {
158 .driver = { 164 .driver = {
159 .name = "platform-lcd", 165 .name = "platform-lcd",
160 .owner = THIS_MODULE, 166 .owner = THIS_MODULE,
161#ifdef CONFIG_PM
162 .pm = &platform_lcd_pm_ops, 167 .pm = &platform_lcd_pm_ops,
163#endif
164 .of_match_table = of_match_ptr(platform_lcd_of_match), 168 .of_match_table = of_match_ptr(platform_lcd_of_match),
165 }, 169 },
166 .probe = platform_lcd_probe, 170 .probe = platform_lcd_probe,
diff --git a/drivers/video/backlight/s6e63m0.c b/drivers/video/backlight/s6e63m0.c
index 9c2677f0ef7d..b37bb1854bf4 100644
--- a/drivers/video/backlight/s6e63m0.c
+++ b/drivers/video/backlight/s6e63m0.c
@@ -817,12 +817,12 @@ static int s6e63m0_remove(struct spi_device *spi)
817 return 0; 817 return 0;
818} 818}
819 819
820#if defined(CONFIG_PM) 820#ifdef CONFIG_PM_SLEEP
821static int s6e63m0_suspend(struct spi_device *spi, pm_message_t mesg) 821static int s6e63m0_suspend(struct device *dev)
822{ 822{
823 struct s6e63m0 *lcd = spi_get_drvdata(spi); 823 struct s6e63m0 *lcd = dev_get_drvdata(dev);
824 824
825 dev_dbg(&spi->dev, "lcd->power = %d\n", lcd->power); 825 dev_dbg(dev, "lcd->power = %d\n", lcd->power);
826 826
827 /* 827 /*
828 * when lcd panel is suspend, lcd panel becomes off 828 * when lcd panel is suspend, lcd panel becomes off
@@ -831,19 +831,18 @@ static int s6e63m0_suspend(struct spi_device *spi, pm_message_t mesg)
831 return s6e63m0_power(lcd, FB_BLANK_POWERDOWN); 831 return s6e63m0_power(lcd, FB_BLANK_POWERDOWN);
832} 832}
833 833
834static int s6e63m0_resume(struct spi_device *spi) 834static int s6e63m0_resume(struct device *dev)
835{ 835{
836 struct s6e63m0 *lcd = spi_get_drvdata(spi); 836 struct s6e63m0 *lcd = dev_get_drvdata(dev);
837 837
838 lcd->power = FB_BLANK_POWERDOWN; 838 lcd->power = FB_BLANK_POWERDOWN;
839 839
840 return s6e63m0_power(lcd, FB_BLANK_UNBLANK); 840 return s6e63m0_power(lcd, FB_BLANK_UNBLANK);
841} 841}
842#else
843#define s6e63m0_suspend NULL
844#define s6e63m0_resume NULL
845#endif 842#endif
846 843
844static SIMPLE_DEV_PM_OPS(s6e63m0_pm_ops, s6e63m0_suspend, s6e63m0_resume);
845
847/* Power down all displays on reboot, poweroff or halt. */ 846/* Power down all displays on reboot, poweroff or halt. */
848static void s6e63m0_shutdown(struct spi_device *spi) 847static void s6e63m0_shutdown(struct spi_device *spi)
849{ 848{
@@ -856,12 +855,11 @@ static struct spi_driver s6e63m0_driver = {
856 .driver = { 855 .driver = {
857 .name = "s6e63m0", 856 .name = "s6e63m0",
858 .owner = THIS_MODULE, 857 .owner = THIS_MODULE,
858 .pm = &s6e63m0_pm_ops,
859 }, 859 },
860 .probe = s6e63m0_probe, 860 .probe = s6e63m0_probe,
861 .remove = s6e63m0_remove, 861 .remove = s6e63m0_remove,
862 .shutdown = s6e63m0_shutdown, 862 .shutdown = s6e63m0_shutdown,
863 .suspend = s6e63m0_suspend,
864 .resume = s6e63m0_resume,
865}; 863};
866 864
867module_spi_driver(s6e63m0_driver); 865module_spi_driver(s6e63m0_driver);
diff --git a/drivers/video/backlight/tdo24m.c b/drivers/video/backlight/tdo24m.c
index 00162085eec0..18cdf466d50a 100644
--- a/drivers/video/backlight/tdo24m.c
+++ b/drivers/video/backlight/tdo24m.c
@@ -412,25 +412,24 @@ static int tdo24m_remove(struct spi_device *spi)
412 return 0; 412 return 0;
413} 413}
414 414
415#ifdef CONFIG_PM 415#ifdef CONFIG_PM_SLEEP
416static int tdo24m_suspend(struct spi_device *spi, pm_message_t state) 416static int tdo24m_suspend(struct device *dev)
417{ 417{
418 struct tdo24m *lcd = spi_get_drvdata(spi); 418 struct tdo24m *lcd = dev_get_drvdata(dev);
419 419
420 return tdo24m_power(lcd, FB_BLANK_POWERDOWN); 420 return tdo24m_power(lcd, FB_BLANK_POWERDOWN);
421} 421}
422 422
423static int tdo24m_resume(struct spi_device *spi) 423static int tdo24m_resume(struct device *dev)
424{ 424{
425 struct tdo24m *lcd = spi_get_drvdata(spi); 425 struct tdo24m *lcd = dev_get_drvdata(dev);
426 426
427 return tdo24m_power(lcd, FB_BLANK_UNBLANK); 427 return tdo24m_power(lcd, FB_BLANK_UNBLANK);
428} 428}
429#else
430#define tdo24m_suspend NULL
431#define tdo24m_resume NULL
432#endif 429#endif
433 430
431static SIMPLE_DEV_PM_OPS(tdo24m_pm_ops, tdo24m_suspend, tdo24m_resume);
432
434/* Power down all displays on reboot, poweroff or halt */ 433/* Power down all displays on reboot, poweroff or halt */
435static void tdo24m_shutdown(struct spi_device *spi) 434static void tdo24m_shutdown(struct spi_device *spi)
436{ 435{
@@ -443,12 +442,11 @@ static struct spi_driver tdo24m_driver = {
443 .driver = { 442 .driver = {
444 .name = "tdo24m", 443 .name = "tdo24m",
445 .owner = THIS_MODULE, 444 .owner = THIS_MODULE,
445 .pm = &tdo24m_pm_ops,
446 }, 446 },
447 .probe = tdo24m_probe, 447 .probe = tdo24m_probe,
448 .remove = tdo24m_remove, 448 .remove = tdo24m_remove,
449 .shutdown = tdo24m_shutdown, 449 .shutdown = tdo24m_shutdown,
450 .suspend = tdo24m_suspend,
451 .resume = tdo24m_resume,
452}; 450};
453 451
454module_spi_driver(tdo24m_driver); 452module_spi_driver(tdo24m_driver);
diff --git a/drivers/video/backlight/tosa_bl.c b/drivers/video/backlight/tosa_bl.c
index 2326fa810c59..9df66ac68b34 100644
--- a/drivers/video/backlight/tosa_bl.c
+++ b/drivers/video/backlight/tosa_bl.c
@@ -134,28 +134,27 @@ static int tosa_bl_remove(struct i2c_client *client)
134 return 0; 134 return 0;
135} 135}
136 136
137#ifdef CONFIG_PM 137#ifdef CONFIG_PM_SLEEP
138static int tosa_bl_suspend(struct i2c_client *client, pm_message_t pm) 138static int tosa_bl_suspend(struct device *dev)
139{ 139{
140 struct tosa_bl_data *data = i2c_get_clientdata(client); 140 struct tosa_bl_data *data = dev_get_drvdata(dev);
141 141
142 tosa_bl_set_backlight(data, 0); 142 tosa_bl_set_backlight(data, 0);
143 143
144 return 0; 144 return 0;
145} 145}
146 146
147static int tosa_bl_resume(struct i2c_client *client) 147static int tosa_bl_resume(struct device *dev)
148{ 148{
149 struct tosa_bl_data *data = i2c_get_clientdata(client); 149 struct tosa_bl_data *data = dev_get_drvdata(dev);
150 150
151 backlight_update_status(data->bl); 151 backlight_update_status(data->bl);
152 return 0; 152 return 0;
153} 153}
154#else
155#define tosa_bl_suspend NULL
156#define tosa_bl_resume NULL
157#endif 154#endif
158 155
156static SIMPLE_DEV_PM_OPS(tosa_bl_pm_ops, tosa_bl_suspend, tosa_bl_resume);
157
159static const struct i2c_device_id tosa_bl_id[] = { 158static const struct i2c_device_id tosa_bl_id[] = {
160 { "tosa-bl", 0 }, 159 { "tosa-bl", 0 },
161 { }, 160 { },
@@ -165,11 +164,10 @@ static struct i2c_driver tosa_bl_driver = {
165 .driver = { 164 .driver = {
166 .name = "tosa-bl", 165 .name = "tosa-bl",
167 .owner = THIS_MODULE, 166 .owner = THIS_MODULE,
167 .pm = &tosa_bl_pm_ops,
168 }, 168 },
169 .probe = tosa_bl_probe, 169 .probe = tosa_bl_probe,
170 .remove = tosa_bl_remove, 170 .remove = tosa_bl_remove,
171 .suspend = tosa_bl_suspend,
172 .resume = tosa_bl_resume,
173 .id_table = tosa_bl_id, 171 .id_table = tosa_bl_id,
174}; 172};
175 173
diff --git a/drivers/video/backlight/tosa_lcd.c b/drivers/video/backlight/tosa_lcd.c
index 666fe2593ea4..bf081573e5b5 100644
--- a/drivers/video/backlight/tosa_lcd.c
+++ b/drivers/video/backlight/tosa_lcd.c
@@ -240,19 +240,19 @@ static int tosa_lcd_remove(struct spi_device *spi)
240 return 0; 240 return 0;
241} 241}
242 242
243#ifdef CONFIG_PM 243#ifdef CONFIG_PM_SLEEP
244static int tosa_lcd_suspend(struct spi_device *spi, pm_message_t state) 244static int tosa_lcd_suspend(struct device *dev)
245{ 245{
246 struct tosa_lcd_data *data = spi_get_drvdata(spi); 246 struct tosa_lcd_data *data = dev_get_drvdata(dev);
247 247
248 tosa_lcd_tg_off(data); 248 tosa_lcd_tg_off(data);
249 249
250 return 0; 250 return 0;
251} 251}
252 252
253static int tosa_lcd_resume(struct spi_device *spi) 253static int tosa_lcd_resume(struct device *dev)
254{ 254{
255 struct tosa_lcd_data *data = spi_get_drvdata(spi); 255 struct tosa_lcd_data *data = dev_get_drvdata(dev);
256 256
257 tosa_lcd_tg_init(data); 257 tosa_lcd_tg_init(data);
258 if (POWER_IS_ON(data->lcd_power)) 258 if (POWER_IS_ON(data->lcd_power))
@@ -262,20 +262,18 @@ static int tosa_lcd_resume(struct spi_device *spi)
262 262
263 return 0; 263 return 0;
264} 264}
265#else
266#define tosa_lcd_suspend NULL
267#define tosa_lcd_resume NULL
268#endif 265#endif
269 266
267static SIMPLE_DEV_PM_OPS(tosa_lcd_pm_ops, tosa_lcd_suspend, tosa_lcd_resume);
268
270static struct spi_driver tosa_lcd_driver = { 269static struct spi_driver tosa_lcd_driver = {
271 .driver = { 270 .driver = {
272 .name = "tosa-lcd", 271 .name = "tosa-lcd",
273 .owner = THIS_MODULE, 272 .owner = THIS_MODULE,
273 .pm = &tosa_lcd_pm_ops,
274 }, 274 },
275 .probe = tosa_lcd_probe, 275 .probe = tosa_lcd_probe,
276 .remove = tosa_lcd_remove, 276 .remove = tosa_lcd_remove,
277 .suspend = tosa_lcd_suspend,
278 .resume = tosa_lcd_resume,
279}; 277};
280 278
281module_spi_driver(tosa_lcd_driver); 279module_spi_driver(tosa_lcd_driver);
diff --git a/drivers/video/backlight/tps65217_bl.c b/drivers/video/backlight/tps65217_bl.c
index 70881633b45a..05782312aeb3 100644
--- a/drivers/video/backlight/tps65217_bl.c
+++ b/drivers/video/backlight/tps65217_bl.c
@@ -245,6 +245,18 @@ tps65217_bl_parse_dt(struct platform_device *pdev)
245 } 245 }
246 } 246 }
247 247
248 if (!of_property_read_u32(node, "default-brightness", &val)) {
249 if (val < 0 ||
250 val > 100) {
251 dev_err(&pdev->dev,
252 "invalid 'default-brightness' value in the device tree\n");
253 err = ERR_PTR(-EINVAL);
254 goto err;
255 }
256
257 pdata->dft_brightness = val;
258 }
259
248 of_node_put(node); 260 of_node_put(node);
249 261
250 return pdata; 262 return pdata;
@@ -311,7 +323,8 @@ static int tps65217_bl_probe(struct platform_device *pdev)
311 return PTR_ERR(tps65217_bl->bl); 323 return PTR_ERR(tps65217_bl->bl);
312 } 324 }
313 325
314 tps65217_bl->bl->props.brightness = 0; 326 tps65217_bl->bl->props.brightness = pdata->dft_brightness;
327 backlight_update_status(tps65217_bl->bl);
315 platform_set_drvdata(pdev, tps65217_bl); 328 platform_set_drvdata(pdev, tps65217_bl);
316 329
317 return 0; 330 return 0;
diff --git a/drivers/video/backlight/vgg2432a4.c b/drivers/video/backlight/vgg2432a4.c
index 84d582f591dc..d538947a67d3 100644
--- a/drivers/video/backlight/vgg2432a4.c
+++ b/drivers/video/backlight/vgg2432a4.c
@@ -205,18 +205,15 @@ static int vgg2432a4_lcd_init(struct ili9320 *lcd,
205 return ret; 205 return ret;
206} 206}
207 207
208#ifdef CONFIG_PM 208#ifdef CONFIG_PM_SLEEP
209static int vgg2432a4_suspend(struct spi_device *spi, pm_message_t state) 209static int vgg2432a4_suspend(struct device *dev)
210{ 210{
211 return ili9320_suspend(spi_get_drvdata(spi), state); 211 return ili9320_suspend(dev_get_drvdata(dev));
212} 212}
213static int vgg2432a4_resume(struct spi_device *spi) 213static int vgg2432a4_resume(struct device *dev)
214{ 214{
215 return ili9320_resume(spi_get_drvdata(spi)); 215 return ili9320_resume(dev_get_drvdata(dev));
216} 216}
217#else
218#define vgg2432a4_suspend NULL
219#define vgg2432a4_resume NULL
220#endif 217#endif
221 218
222static struct ili9320_client vgg2432a4_client = { 219static struct ili9320_client vgg2432a4_client = {
@@ -249,16 +246,17 @@ static void vgg2432a4_shutdown(struct spi_device *spi)
249 ili9320_shutdown(spi_get_drvdata(spi)); 246 ili9320_shutdown(spi_get_drvdata(spi));
250} 247}
251 248
249static SIMPLE_DEV_PM_OPS(vgg2432a4_pm_ops, vgg2432a4_suspend, vgg2432a4_resume);
250
252static struct spi_driver vgg2432a4_driver = { 251static struct spi_driver vgg2432a4_driver = {
253 .driver = { 252 .driver = {
254 .name = "VGG2432A4", 253 .name = "VGG2432A4",
255 .owner = THIS_MODULE, 254 .owner = THIS_MODULE,
255 .pm = &vgg2432a4_pm_ops,
256 }, 256 },
257 .probe = vgg2432a4_probe, 257 .probe = vgg2432a4_probe,
258 .remove = vgg2432a4_remove, 258 .remove = vgg2432a4_remove,
259 .shutdown = vgg2432a4_shutdown, 259 .shutdown = vgg2432a4_shutdown,
260 .suspend = vgg2432a4_suspend,
261 .resume = vgg2432a4_resume,
262}; 260};
263 261
264module_spi_driver(vgg2432a4_driver); 262module_spi_driver(vgg2432a4_driver);
diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
index d4284458377e..e328a61b64ba 100644
--- a/drivers/video/uvesafb.c
+++ b/drivers/video/uvesafb.c
@@ -166,7 +166,7 @@ static int uvesafb_exec(struct uvesafb_ktask *task)
166 memcpy(&m->id, &uvesafb_cn_id, sizeof(m->id)); 166 memcpy(&m->id, &uvesafb_cn_id, sizeof(m->id));
167 m->seq = seq; 167 m->seq = seq;
168 m->len = len; 168 m->len = len;
169 m->ack = random32(); 169 m->ack = prandom_u32();
170 170
171 /* uvesafb_task structure */ 171 /* uvesafb_task structure */
172 memcpy(m + 1, &task->t, sizeof(task->t)); 172 memcpy(m + 1, &task->t, sizeof(task->t));