LCOV - code coverage report
Current view: top level - drivers/rtc - rtc-proc.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 43 66 65.2 %
Date: 2014-02-18 Functions: 3 6 50.0 %
Branches: 15 36 41.7 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * RTC subsystem, proc interface
       3                 :            :  *
       4                 :            :  * Copyright (C) 2005-06 Tower Technologies
       5                 :            :  * Author: Alessandro Zummo <a.zummo@towertech.it>
       6                 :            :  *
       7                 :            :  * based on arch/arm/common/rtctime.c
       8                 :            :  *
       9                 :            :  * This program is free software; you can redistribute it and/or modify
      10                 :            :  * it under the terms of the GNU General Public License version 2 as
      11                 :            :  * published by the Free Software Foundation.
      12                 :            : */
      13                 :            : 
      14                 :            : #include <linux/module.h>
      15                 :            : #include <linux/rtc.h>
      16                 :            : #include <linux/proc_fs.h>
      17                 :            : #include <linux/seq_file.h>
      18                 :            : 
      19                 :            : #include "rtc-core.h"
      20                 :            : 
      21                 :            : #define NAME_SIZE       10
      22                 :            : 
      23                 :            : #if defined(CONFIG_RTC_HCTOSYS_DEVICE)
      24                 :          0 : static bool is_rtc_hctosys(struct rtc_device *rtc)
      25                 :            : {
      26                 :            :         int size;
      27                 :            :         char name[NAME_SIZE];
      28                 :            : 
      29                 :          0 :         size = scnprintf(name, NAME_SIZE, "rtc%d", rtc->id);
      30         [ #  # ]:          0 :         if (size > NAME_SIZE)
      31                 :            :                 return false;
      32                 :            : 
      33                 :          0 :         return !strncmp(name, CONFIG_RTC_HCTOSYS_DEVICE, NAME_SIZE);
      34                 :            : }
      35                 :            : #else
      36                 :            : static bool is_rtc_hctosys(struct rtc_device *rtc)
      37                 :            : {
      38                 :            :         return (rtc->id == 0);
      39                 :            : }
      40                 :            : #endif
      41                 :            : 
      42                 :          0 : static int rtc_proc_show(struct seq_file *seq, void *offset)
      43                 :            : {
      44                 :            :         int err;
      45                 :          1 :         struct rtc_device *rtc = seq->private;
      46                 :          1 :         const struct rtc_class_ops *ops = rtc->ops;
      47                 :            :         struct rtc_wkalrm alrm;
      48                 :            :         struct rtc_time tm;
      49                 :            : 
      50                 :          1 :         err = rtc_read_time(rtc, &tm);
      51         [ +  - ]:          1 :         if (err == 0) {
      52                 :          1 :                 seq_printf(seq,
      53                 :            :                         "rtc_time\t: %02d:%02d:%02d\n"
      54                 :            :                         "rtc_date\t: %04d-%02d-%02d\n",
      55                 :            :                         tm.tm_hour, tm.tm_min, tm.tm_sec,
      56                 :          2 :                         tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday);
      57                 :            :         }
      58                 :            : 
      59                 :          1 :         err = rtc_read_alarm(rtc, &alrm);
      60         [ +  - ]:          1 :         if (err == 0) {
      61                 :          1 :                 seq_printf(seq, "alrm_time\t: ");
      62         [ +  - ]:          1 :                 if ((unsigned int)alrm.time.tm_hour <= 24)
      63                 :          1 :                         seq_printf(seq, "%02d:", alrm.time.tm_hour);
      64                 :            :                 else
      65                 :          0 :                         seq_printf(seq, "**:");
      66         [ +  - ]:          1 :                 if ((unsigned int)alrm.time.tm_min <= 59)
      67                 :          1 :                         seq_printf(seq, "%02d:", alrm.time.tm_min);
      68                 :            :                 else
      69                 :          0 :                         seq_printf(seq, "**:");
      70         [ +  - ]:          1 :                 if ((unsigned int)alrm.time.tm_sec <= 59)
      71                 :          1 :                         seq_printf(seq, "%02d\n", alrm.time.tm_sec);
      72                 :            :                 else
      73                 :          0 :                         seq_printf(seq, "**\n");
      74                 :            : 
      75                 :          1 :                 seq_printf(seq, "alrm_date\t: ");
      76         [ +  - ]:          1 :                 if ((unsigned int)alrm.time.tm_year <= 200)
      77                 :          1 :                         seq_printf(seq, "%04d-", alrm.time.tm_year + 1900);
      78                 :            :                 else
      79                 :          0 :                         seq_printf(seq, "****-");
      80         [ +  - ]:          1 :                 if ((unsigned int)alrm.time.tm_mon <= 11)
      81                 :          1 :                         seq_printf(seq, "%02d-", alrm.time.tm_mon + 1);
      82                 :            :                 else
      83                 :          0 :                         seq_printf(seq, "**-");
      84         [ +  - ]:          1 :                 if (alrm.time.tm_mday && (unsigned int)alrm.time.tm_mday <= 31)
      85                 :          1 :                         seq_printf(seq, "%02d\n", alrm.time.tm_mday);
      86                 :            :                 else
      87                 :          0 :                         seq_printf(seq, "**\n");
      88         [ +  - ]:          1 :                 seq_printf(seq, "alarm_IRQ\t: %s\n",
      89                 :          1 :                                 alrm.enabled ? "yes" : "no");
      90         [ +  - ]:          1 :                 seq_printf(seq, "alrm_pending\t: %s\n",
      91                 :          1 :                                 alrm.pending ? "yes" : "no");
      92         [ +  - ]:          1 :                 seq_printf(seq, "update IRQ enabled\t: %s\n",
      93                 :          1 :                         (rtc->uie_rtctimer.enabled) ? "yes" : "no");
      94         [ +  - ]:          1 :                 seq_printf(seq, "periodic IRQ enabled\t: %s\n",
      95                 :          1 :                         (rtc->pie_enabled) ? "yes" : "no");
      96                 :          1 :                 seq_printf(seq, "periodic IRQ frequency\t: %d\n",
      97                 :            :                         rtc->irq_freq);
      98                 :          1 :                 seq_printf(seq, "max user IRQ frequency\t: %d\n",
      99                 :            :                         rtc->max_user_freq);
     100                 :            :         }
     101                 :            : 
     102                 :          1 :         seq_printf(seq, "24hr\t\t: yes\n");
     103                 :            : 
     104         [ -  + ]:          1 :         if (ops->proc)
     105                 :          0 :                 ops->proc(rtc->dev.parent, seq);
     106                 :            : 
     107                 :          1 :         return 0;
     108                 :            : }
     109                 :            : 
     110                 :          0 : static int rtc_proc_open(struct inode *inode, struct file *file)
     111                 :            : {
     112                 :            :         int ret;
     113                 :          1 :         struct rtc_device *rtc = PDE_DATA(inode);
     114                 :            : 
     115         [ +  - ]:          1 :         if (!try_module_get(THIS_MODULE))
     116                 :            :                 return -ENODEV;
     117                 :            : 
     118                 :          1 :         ret = single_open(file, rtc_proc_show, rtc);
     119         [ -  + ]:          1 :         if (ret)
     120                 :          0 :                 module_put(THIS_MODULE);
     121                 :          1 :         return ret;
     122                 :            : }
     123                 :            : 
     124                 :          0 : static int rtc_proc_release(struct inode *inode, struct file *file)
     125                 :            : {
     126                 :          1 :         int res = single_release(inode, file);
     127                 :          1 :         module_put(THIS_MODULE);
     128                 :          1 :         return res;
     129                 :            : }
     130                 :            : 
     131                 :            : static const struct file_operations rtc_proc_fops = {
     132                 :            :         .open           = rtc_proc_open,
     133                 :            :         .read           = seq_read,
     134                 :            :         .llseek         = seq_lseek,
     135                 :            :         .release        = rtc_proc_release,
     136                 :            : };
     137                 :            : 
     138                 :          0 : void rtc_proc_add_device(struct rtc_device *rtc)
     139                 :            : {
     140         [ #  # ]:          0 :         if (is_rtc_hctosys(rtc))
     141                 :          0 :                 proc_create_data("driver/rtc", 0, NULL, &rtc_proc_fops, rtc);
     142                 :          0 : }
     143                 :            : 
     144                 :          0 : void rtc_proc_del_device(struct rtc_device *rtc)
     145                 :            : {
     146         [ #  # ]:          0 :         if (is_rtc_hctosys(rtc))
     147                 :          0 :                 remove_proc_entry("driver/rtc", NULL);
     148                 :          0 : }

Generated by: LCOV version 1.9