hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/clocksource/sh_mtu2.c
....@@ -1,16 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * SuperH Timer Support - MTU2
34 *
45 * Copyright (C) 2009 Magnus Damm
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License as published by
8
- * the Free Software Foundation; either version 2 of the License
9
- *
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.
146 */
157
168 #include <linux/clk.h>
....@@ -30,6 +22,10 @@
3022 #include <linux/sh_timer.h>
3123 #include <linux/slab.h>
3224 #include <linux/spinlock.h>
25
+
26
+#ifdef CONFIG_SUPERH
27
+#include <asm/platform_early.h>
28
+#endif
3329
3430 struct sh_mtu2_device;
3531
....@@ -301,12 +297,12 @@
301297
302298 static void sh_mtu2_clock_event_suspend(struct clock_event_device *ced)
303299 {
304
- pm_genpd_syscore_poweroff(&ced_to_sh_mtu2(ced)->mtu->pdev->dev);
300
+ dev_pm_genpd_suspend(&ced_to_sh_mtu2(ced)->mtu->pdev->dev);
305301 }
306302
307303 static void sh_mtu2_clock_event_resume(struct clock_event_device *ced)
308304 {
309
- pm_genpd_syscore_poweron(&ced_to_sh_mtu2(ced)->mtu->pdev->dev);
305
+ dev_pm_genpd_resume(&ced_to_sh_mtu2(ced)->mtu->pdev->dev);
310306 }
311307
312308 static void sh_mtu2_register_clockevent(struct sh_mtu2_channel *ch,
....@@ -336,12 +332,13 @@
336332 return 0;
337333 }
338334
335
+static const unsigned int sh_mtu2_channel_offsets[] = {
336
+ 0x300, 0x380, 0x000,
337
+};
338
+
339339 static int sh_mtu2_setup_channel(struct sh_mtu2_channel *ch, unsigned int index,
340340 struct sh_mtu2_device *mtu)
341341 {
342
- static const unsigned int channel_offsets[] = {
343
- 0x300, 0x380, 0x000,
344
- };
345342 char name[6];
346343 int irq;
347344 int ret;
....@@ -364,7 +361,7 @@
364361 return ret;
365362 }
366363
367
- ch->base = mtu->mapbase + channel_offsets[index];
364
+ ch->base = mtu->mapbase + sh_mtu2_channel_offsets[index];
368365 ch->index = index;
369366
370367 return sh_mtu2_register(ch, dev_name(&mtu->pdev->dev));
....@@ -380,7 +377,7 @@
380377 return -ENXIO;
381378 }
382379
383
- mtu->mapbase = ioremap_nocache(res->start, resource_size(res));
380
+ mtu->mapbase = ioremap(res->start, resource_size(res));
384381 if (mtu->mapbase == NULL)
385382 return -ENXIO;
386383
....@@ -416,7 +413,12 @@
416413 }
417414
418415 /* Allocate and setup the channels. */
419
- mtu->num_channels = 3;
416
+ ret = platform_irq_count(pdev);
417
+ if (ret < 0)
418
+ goto err_unmap;
419
+
420
+ mtu->num_channels = min_t(unsigned int, ret,
421
+ ARRAY_SIZE(sh_mtu2_channel_offsets));
420422
421423 mtu->channels = kcalloc(mtu->num_channels, sizeof(*mtu->channels),
422424 GFP_KERNEL);
....@@ -450,7 +452,7 @@
450452 struct sh_mtu2_device *mtu = platform_get_drvdata(pdev);
451453 int ret;
452454
453
- if (!is_early_platform_device(pdev)) {
455
+ if (!is_sh_early_platform_device(pdev)) {
454456 pm_runtime_set_active(&pdev->dev);
455457 pm_runtime_enable(&pdev->dev);
456458 }
....@@ -470,7 +472,7 @@
470472 pm_runtime_idle(&pdev->dev);
471473 return ret;
472474 }
473
- if (is_early_platform_device(pdev))
475
+ if (is_sh_early_platform_device(pdev))
474476 return 0;
475477
476478 out:
....@@ -519,7 +521,10 @@
519521 platform_driver_unregister(&sh_mtu2_device_driver);
520522 }
521523
522
-early_platform_init("earlytimer", &sh_mtu2_device_driver);
524
+#ifdef CONFIG_SUPERH
525
+sh_early_platform_init("earlytimer", &sh_mtu2_device_driver);
526
+#endif
527
+
523528 subsys_initcall(sh_mtu2_init);
524529 module_exit(sh_mtu2_exit);
525530