Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mmio.c
Go to the documentation of this file.
1 /*
2  * Generic MMIO clocksource support
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  */
8 #include <linux/clocksource.h>
9 #include <linux/errno.h>
10 #include <linux/init.h>
11 #include <linux/slab.h>
12 
14  void __iomem *reg;
16 };
17 
18 static inline struct clocksource_mmio *to_mmio_clksrc(struct clocksource *c)
19 {
20  return container_of(c, struct clocksource_mmio, clksrc);
21 }
22 
24 {
25  return readl_relaxed(to_mmio_clksrc(c)->reg);
26 }
27 
29 {
30  return ~readl_relaxed(to_mmio_clksrc(c)->reg);
31 }
32 
34 {
35  return readw_relaxed(to_mmio_clksrc(c)->reg);
36 }
37 
39 {
40  return ~(unsigned)readw_relaxed(to_mmio_clksrc(c)->reg);
41 }
42 
52 int __init clocksource_mmio_init(void __iomem *base, const char *name,
53  unsigned long hz, int rating, unsigned bits,
54  cycle_t (*read)(struct clocksource *))
55 {
56  struct clocksource_mmio *cs;
57 
58  if (bits > 32 || bits < 16)
59  return -EINVAL;
60 
61  cs = kzalloc(sizeof(struct clocksource_mmio), GFP_KERNEL);
62  if (!cs)
63  return -ENOMEM;
64 
65  cs->reg = base;
66  cs->clksrc.name = name;
67  cs->clksrc.rating = rating;
68  cs->clksrc.read = read;
69  cs->clksrc.mask = CLOCKSOURCE_MASK(bits);
71 
72  return clocksource_register_hz(&cs->clksrc, hz);
73 }