]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/meta-ti-glsdk.git/blob - recipes-kernel/linux/linux-3.0/sakoman/0010-rtc-twl-Fix-registration-vs.-init-order.patch
cf09b4e1c6a1e5412dac361e6644d78816796d49
[glsdk/meta-ti-glsdk.git] / recipes-kernel / linux / linux-3.0 / sakoman / 0010-rtc-twl-Fix-registration-vs.-init-order.patch
1 From 806a0fc320ad8f6c391b6e4a4d872af0ffc17fbc Mon Sep 17 00:00:00 2001
2 From: Todd Poynor <toddpoynor@google.com>
3 Date: Wed, 27 Jul 2011 07:07:21 +0000
4 Subject: [PATCH 10/14] rtc: twl: Fix registration vs. init order
6 Only register as an RTC device after the hardware has been
7 successfully initialized.  The RTC class driver will call
8 back to this driver to read a pending alarm, and other
9 drivers watching for new devices on the RTC class may
10 read the RTC time upon registration.  Such access might
11 occur while the RTC is stopped, prior to clearing
12 pending alarms, etc.
14 The new ordering also avoids leaving the platform
15 device drvdata set to an unregistered struct rtc_device *
16 on probe errors.
18 Signed-off-by: Todd Poynor <toddpoynor@google.com>
19 ---
20  drivers/rtc/rtc-twl.c |   52 ++++++++++++++++++++++--------------------------
21  1 files changed, 24 insertions(+), 28 deletions(-)
23 diff --git a/drivers/rtc/rtc-twl.c b/drivers/rtc/rtc-twl.c
24 index 3fee95e..a64494e 100644
25 --- a/drivers/rtc/rtc-twl.c
26 +++ b/drivers/rtc/rtc-twl.c
27 @@ -420,24 +420,12 @@ static struct rtc_class_ops twl_rtc_ops = {
28  static int __devinit twl_rtc_probe(struct platform_device *pdev)
29  {
30         struct rtc_device *rtc;
31 -       int ret = 0;
32 +       int ret = -EINVAL;
33         int irq = platform_get_irq(pdev, 0);
34         u8 rd_reg;
35  
36         if (irq <= 0)
37 -               return -EINVAL;
38 -
39 -       rtc = rtc_device_register(pdev->name,
40 -                                 &pdev->dev, &twl_rtc_ops, THIS_MODULE);
41 -       if (IS_ERR(rtc)) {
42 -               ret = PTR_ERR(rtc);
43 -               dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
44 -                       PTR_ERR(rtc));
45 -               goto out0;
46 -
47 -       }
48 -
49 -       platform_set_drvdata(pdev, rtc);
50 +               goto out1;
51  
52         ret = twl_rtc_read_u8(&rd_reg, REG_RTC_STATUS_REG);
53         if (ret < 0)
54 @@ -454,14 +442,6 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
55         if (ret < 0)
56                 goto out1;
57  
58 -       ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
59 -                                  IRQF_TRIGGER_RISING,
60 -                                  dev_name(&rtc->dev), rtc);
61 -       if (ret < 0) {
62 -               dev_err(&pdev->dev, "IRQ is not free.\n");
63 -               goto out1;
64 -       }
65 -
66         if (twl_class_is_6030()) {
67                 twl6030_interrupt_unmask(TWL6030_RTC_INT_MASK,
68                         REG_INT_MSK_LINE_A);
69 @@ -472,28 +452,44 @@ static int __devinit twl_rtc_probe(struct platform_device *pdev)
70         /* Check RTC module status, Enable if it is off */
71         ret = twl_rtc_read_u8(&rd_reg, REG_RTC_CTRL_REG);
72         if (ret < 0)
73 -               goto out2;
74 +               goto out1;
75  
76         if (!(rd_reg & BIT_RTC_CTRL_REG_STOP_RTC_M)) {
77                 dev_info(&pdev->dev, "Enabling TWL-RTC.\n");
78                 rd_reg = BIT_RTC_CTRL_REG_STOP_RTC_M;
79                 ret = twl_rtc_write_u8(rd_reg, REG_RTC_CTRL_REG);
80                 if (ret < 0)
81 -                       goto out2;
82 +                       goto out1;
83         }
84  
85         /* init cached IRQ enable bits */
86         ret = twl_rtc_read_u8(&rtc_irq_bits, REG_RTC_INTERRUPTS_REG);
87         if (ret < 0)
88 +               goto out1;
89 +
90 +       rtc = rtc_device_register(pdev->name,
91 +                                 &pdev->dev, &twl_rtc_ops, THIS_MODULE);
92 +       if (IS_ERR(rtc)) {
93 +               ret = PTR_ERR(rtc);
94 +               dev_err(&pdev->dev, "can't register RTC device, err %ld\n",
95 +                       PTR_ERR(rtc));
96 +               goto out1;
97 +       }
98 +
99 +       ret = request_threaded_irq(irq, NULL, twl_rtc_interrupt,
100 +                                  IRQF_TRIGGER_RISING,
101 +                                  dev_name(&rtc->dev), rtc);
102 +       if (ret < 0) {
103 +               dev_err(&pdev->dev, "IRQ is not free.\n");
104                 goto out2;
105 +       }
106  
107 -       return ret;
108 +       platform_set_drvdata(pdev, rtc);
109 +       return 0;
110  
111  out2:
112 -       free_irq(irq, rtc);
113 -out1:
114         rtc_device_unregister(rtc);
115 -out0:
116 +out1:
117         return ret;
118  }
119  
120 -- 
121 1.6.6.1