diff options
author | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2017-07-06 05:41:58 -0400 |
---|---|---|
committer | Alexandre Belloni <alexandre.belloni@free-electrons.com> | 2017-07-07 07:14:06 -0400 |
commit | d1bec20facd6eae17cb2f39ebbf443c95c650490 (patch) | |
tree | 088d06e722ba1cf5bf8cface608413a8623246da /drivers/rtc | |
parent | 9a6757eadc14f01385fd41fe3906dc22dcdb919e (diff) |
rtc: class separate device allocation from registration
Create rtc_allocate_device to allocate memory for a struct rtc_device and
initialize it.
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Diffstat (limited to 'drivers/rtc')
-rw-r--r-- | drivers/rtc/class.c | 63 |
1 files changed, 37 insertions, 26 deletions
diff --git a/drivers/rtc/class.c b/drivers/rtc/class.c index 543c64cd3df0..fb39c1334d7b 100644 --- a/drivers/rtc/class.c +++ b/drivers/rtc/class.c | |||
@@ -150,6 +150,41 @@ static SIMPLE_DEV_PM_OPS(rtc_class_dev_pm_ops, rtc_suspend, rtc_resume); | |||
150 | #define RTC_CLASS_DEV_PM_OPS NULL | 150 | #define RTC_CLASS_DEV_PM_OPS NULL |
151 | #endif | 151 | #endif |
152 | 152 | ||
153 | static struct rtc_device *rtc_allocate_device(void) | ||
154 | { | ||
155 | struct rtc_device *rtc; | ||
156 | |||
157 | rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); | ||
158 | if (!rtc) | ||
159 | return NULL; | ||
160 | |||
161 | device_initialize(&rtc->dev); | ||
162 | |||
163 | rtc->irq_freq = 1; | ||
164 | rtc->max_user_freq = 64; | ||
165 | rtc->dev.class = rtc_class; | ||
166 | rtc->dev.groups = rtc_get_dev_attribute_groups(); | ||
167 | rtc->dev.release = rtc_device_release; | ||
168 | |||
169 | mutex_init(&rtc->ops_lock); | ||
170 | spin_lock_init(&rtc->irq_lock); | ||
171 | spin_lock_init(&rtc->irq_task_lock); | ||
172 | init_waitqueue_head(&rtc->irq_queue); | ||
173 | |||
174 | /* Init timerqueue */ | ||
175 | timerqueue_init_head(&rtc->timerqueue); | ||
176 | INIT_WORK(&rtc->irqwork, rtc_timer_do_work); | ||
177 | /* Init aie timer */ | ||
178 | rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, (void *)rtc); | ||
179 | /* Init uie timer */ | ||
180 | rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, (void *)rtc); | ||
181 | /* Init pie timer */ | ||
182 | hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
183 | rtc->pie_timer.function = rtc_pie_update_irq; | ||
184 | rtc->pie_enabled = 0; | ||
185 | |||
186 | return rtc; | ||
187 | } | ||
153 | 188 | ||
154 | /** | 189 | /** |
155 | * rtc_device_register - register w/ RTC class | 190 | * rtc_device_register - register w/ RTC class |
@@ -189,40 +224,16 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev, | |||
189 | } | 224 | } |
190 | } | 225 | } |
191 | 226 | ||
192 | rtc = kzalloc(sizeof(struct rtc_device), GFP_KERNEL); | 227 | rtc = rtc_allocate_device(); |
193 | if (rtc == NULL) { | 228 | if (!rtc) { |
194 | err = -ENOMEM; | 229 | err = -ENOMEM; |
195 | goto exit_ida; | 230 | goto exit_ida; |
196 | } | 231 | } |
197 | 232 | ||
198 | device_initialize(&rtc->dev); | ||
199 | |||
200 | rtc->id = id; | 233 | rtc->id = id; |
201 | rtc->ops = ops; | 234 | rtc->ops = ops; |
202 | rtc->owner = owner; | 235 | rtc->owner = owner; |
203 | rtc->irq_freq = 1; | ||
204 | rtc->max_user_freq = 64; | ||
205 | rtc->dev.parent = dev; | 236 | rtc->dev.parent = dev; |
206 | rtc->dev.class = rtc_class; | ||
207 | rtc->dev.groups = rtc_get_dev_attribute_groups(); | ||
208 | rtc->dev.release = rtc_device_release; | ||
209 | |||
210 | mutex_init(&rtc->ops_lock); | ||
211 | spin_lock_init(&rtc->irq_lock); | ||
212 | spin_lock_init(&rtc->irq_task_lock); | ||
213 | init_waitqueue_head(&rtc->irq_queue); | ||
214 | |||
215 | /* Init timerqueue */ | ||
216 | timerqueue_init_head(&rtc->timerqueue); | ||
217 | INIT_WORK(&rtc->irqwork, rtc_timer_do_work); | ||
218 | /* Init aie timer */ | ||
219 | rtc_timer_init(&rtc->aie_timer, rtc_aie_update_irq, (void *)rtc); | ||
220 | /* Init uie timer */ | ||
221 | rtc_timer_init(&rtc->uie_rtctimer, rtc_uie_update_irq, (void *)rtc); | ||
222 | /* Init pie timer */ | ||
223 | hrtimer_init(&rtc->pie_timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); | ||
224 | rtc->pie_timer.function = rtc_pie_update_irq; | ||
225 | rtc->pie_enabled = 0; | ||
226 | 237 | ||
227 | dev_set_name(&rtc->dev, "rtc%d", id); | 238 | dev_set_name(&rtc->dev, "rtc%d", id); |
228 | 239 | ||