Version:  2.0.40 2.2.26 2.4.37 3.1 3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17

Linux/drivers/rtc/rtc-tile.c

  1 /*
  2  * Copyright 2011 Tilera Corporation. All Rights Reserved.
  3  *
  4  *   This program is free software; you can redistribute it and/or
  5  *   modify it under the terms of the GNU General Public License
  6  *   as published by the Free Software Foundation, version 2.
  7  *
  8  *   This program is distributed in the hope that it will be useful, but
  9  *   WITHOUT ANY WARRANTY; without even the implied warranty of
 10  *   MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
 11  *   NON INFRINGEMENT.  See the GNU General Public License for
 12  *   more details.
 13  *
 14  * Tilera-specific RTC driver.
 15  */
 16 
 17 #include <linux/module.h>
 18 #include <linux/device.h>
 19 #include <linux/rtc.h>
 20 #include <linux/platform_device.h>
 21 
 22 /* Platform device pointer. */
 23 static struct platform_device *tile_rtc_platform_device;
 24 
 25 /*
 26  * RTC read routine.  Gets time info from RTC chip via hypervisor syscall.
 27  */
 28 static int read_rtc_time(struct device *dev, struct rtc_time *tm)
 29 {
 30         HV_RTCTime hvtm = hv_get_rtc();
 31 
 32         tm->tm_sec = hvtm.tm_sec;
 33         tm->tm_min = hvtm.tm_min;
 34         tm->tm_hour = hvtm.tm_hour;
 35         tm->tm_mday = hvtm.tm_mday;
 36         tm->tm_mon = hvtm.tm_mon;
 37         tm->tm_year = hvtm.tm_year;
 38         tm->tm_wday = 0;
 39         tm->tm_yday = 0;
 40         tm->tm_isdst = 0;
 41 
 42         if (rtc_valid_tm(tm) < 0)
 43                 dev_warn(dev, "Read invalid date/time from RTC\n");
 44 
 45         return 0;
 46 }
 47 
 48 /*
 49  * RTC write routine.  Sends time info to hypervisor via syscall, to be
 50  * written to RTC chip.
 51  */
 52 static int set_rtc_time(struct device *dev, struct rtc_time *tm)
 53 {
 54         HV_RTCTime hvtm;
 55 
 56         hvtm.tm_sec = tm->tm_sec;
 57         hvtm.tm_min = tm->tm_min;
 58         hvtm.tm_hour = tm->tm_hour;
 59         hvtm.tm_mday = tm->tm_mday;
 60         hvtm.tm_mon = tm->tm_mon;
 61         hvtm.tm_year = tm->tm_year;
 62 
 63         hv_set_rtc(hvtm);
 64 
 65         return 0;
 66 }
 67 
 68 /*
 69  * RTC read/write ops.
 70  */
 71 static const struct rtc_class_ops tile_rtc_ops = {
 72         .read_time      = read_rtc_time,
 73         .set_time       = set_rtc_time,
 74 };
 75 
 76 /*
 77  * Device probe routine.
 78  */
 79 static int tile_rtc_probe(struct platform_device *dev)
 80 {
 81         struct rtc_device *rtc;
 82 
 83         rtc = devm_rtc_device_register(&dev->dev, "tile",
 84                                 &tile_rtc_ops, THIS_MODULE);
 85 
 86         if (IS_ERR(rtc))
 87                 return PTR_ERR(rtc);
 88 
 89         platform_set_drvdata(dev, rtc);
 90 
 91         return 0;
 92 }
 93 
 94 static struct platform_driver tile_rtc_platform_driver = {
 95         .driver         = {
 96                 .name   = "rtc-tile",
 97                 .owner  = THIS_MODULE,
 98         },
 99         .probe          = tile_rtc_probe,
100 };
101 
102 /*
103  * Driver init routine.
104  */
105 static int __init tile_rtc_driver_init(void)
106 {
107         int err;
108 
109         err = platform_driver_register(&tile_rtc_platform_driver);
110         if (err)
111                 return err;
112 
113         tile_rtc_platform_device = platform_device_alloc("rtc-tile", 0);
114         if (tile_rtc_platform_device == NULL) {
115                 err = -ENOMEM;
116                 goto exit_driver_unregister;
117         }
118 
119         err = platform_device_add(tile_rtc_platform_device);
120         if (err)
121                 goto exit_device_put;
122 
123         return 0;
124 
125 exit_device_put:
126         platform_device_put(tile_rtc_platform_device);
127 
128 exit_driver_unregister:
129         platform_driver_unregister(&tile_rtc_platform_driver);
130         return err;
131 }
132 
133 /*
134  * Driver cleanup routine.
135  */
136 static void __exit tile_rtc_driver_exit(void)
137 {
138         platform_device_unregister(tile_rtc_platform_device);
139         platform_driver_unregister(&tile_rtc_platform_driver);
140 }
141 
142 module_init(tile_rtc_driver_init);
143 module_exit(tile_rtc_driver_exit);
144 
145 MODULE_DESCRIPTION("Tilera-specific Real Time Clock Driver");
146 MODULE_LICENSE("GPL");
147 MODULE_ALIAS("platform:rtc-tile");
148 

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us