LCOV - code coverage report
Current view: top level - drivers/power/reset - vexpress-poweroff.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 43 0.0 %
Date: 2014-02-18 Functions: 0 7 0.0 %
Branches: 0 18 0.0 %

           Branch data     Line data    Source code
       1                 :            : /*
       2                 :            :  * This program is free software; you can redistribute it and/or modify
       3                 :            :  * it under the terms of the GNU General Public License version 2 as
       4                 :            :  * published by the Free Software Foundation.
       5                 :            :  *
       6                 :            :  * This program is distributed in the hope that it will be useful,
       7                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       8                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       9                 :            :  * GNU General Public License for more details.
      10                 :            :  *
      11                 :            :  * Copyright (C) 2012 ARM Limited
      12                 :            :  */
      13                 :            : 
      14                 :            : #include <linux/jiffies.h>
      15                 :            : #include <linux/of.h>
      16                 :            : #include <linux/of_device.h>
      17                 :            : #include <linux/platform_device.h>
      18                 :            : #include <linux/stat.h>
      19                 :            : #include <linux/vexpress.h>
      20                 :            : 
      21                 :            : #include <asm/system_misc.h>
      22                 :            : 
      23                 :          0 : static void vexpress_reset_do(struct device *dev, const char *what)
      24                 :            : {
      25                 :            :         int err = -ENOENT;
      26                 :          0 :         struct vexpress_config_func *func =
      27                 :            :                         vexpress_config_func_get_by_dev(dev);
      28                 :            : 
      29         [ #  # ]:          0 :         if (func) {
      30                 :            :                 unsigned long timeout;
      31                 :            : 
      32                 :          0 :                 err = vexpress_config_write(func, 0, 0);
      33                 :            : 
      34                 :          0 :                 timeout = jiffies + HZ;
      35         [ #  # ]:          0 :                 while (time_before(jiffies, timeout))
      36                 :          0 :                         cpu_relax();
      37                 :            :         }
      38                 :            : 
      39                 :          0 :         dev_emerg(dev, "Unable to %s (%d)\n", what, err);
      40                 :          0 : }
      41                 :            : 
      42                 :            : static struct device *vexpress_power_off_device;
      43                 :            : 
      44                 :          0 : static void vexpress_power_off(void)
      45                 :            : {
      46                 :          0 :         vexpress_reset_do(vexpress_power_off_device, "power off");
      47                 :          0 : }
      48                 :            : 
      49                 :            : static struct device *vexpress_restart_device;
      50                 :            : 
      51                 :          0 : static void vexpress_restart(enum reboot_mode reboot_mode, const char *cmd)
      52                 :            : {
      53                 :          0 :         vexpress_reset_do(vexpress_restart_device, "restart");
      54                 :          0 : }
      55                 :            : 
      56                 :          0 : static ssize_t vexpress_reset_active_show(struct device *dev,
      57                 :            :                 struct device_attribute *attr, char *buf)
      58                 :            : {
      59                 :          0 :         return sprintf(buf, "%d\n", vexpress_restart_device == dev);
      60                 :            : }
      61                 :            : 
      62                 :          0 : static ssize_t vexpress_reset_active_store(struct device *dev,
      63                 :            :                 struct device_attribute *attr, const char *buf, size_t count)
      64                 :            : {
      65                 :            :         long value;
      66                 :            :         int err = kstrtol(buf, 0, &value);
      67                 :            : 
      68 [ #  # ][ #  # ]:          0 :         if (!err && value)
      69                 :          0 :                 vexpress_restart_device = dev;
      70                 :            : 
      71         [ #  # ]:          0 :         return err ? err : count;
      72                 :            : }
      73                 :            : 
      74                 :            : DEVICE_ATTR(active, S_IRUGO | S_IWUSR, vexpress_reset_active_show,
      75                 :            :                 vexpress_reset_active_store);
      76                 :            : 
      77                 :            : 
      78                 :            : enum vexpress_reset_func { FUNC_RESET, FUNC_SHUTDOWN, FUNC_REBOOT };
      79                 :            : 
      80                 :            : static struct of_device_id vexpress_reset_of_match[] = {
      81                 :            :         {
      82                 :            :                 .compatible = "arm,vexpress-reset",
      83                 :            :                 .data = (void *)FUNC_RESET,
      84                 :            :         }, {
      85                 :            :                 .compatible = "arm,vexpress-shutdown",
      86                 :            :                 .data = (void *)FUNC_SHUTDOWN
      87                 :            :         }, {
      88                 :            :                 .compatible = "arm,vexpress-reboot",
      89                 :            :                 .data = (void *)FUNC_REBOOT
      90                 :            :         },
      91                 :            :         {}
      92                 :            : };
      93                 :            : 
      94                 :          0 : static int vexpress_reset_probe(struct platform_device *pdev)
      95                 :            : {
      96                 :            :         enum vexpress_reset_func func;
      97                 :          0 :         const struct of_device_id *match =
      98                 :          0 :                         of_match_device(vexpress_reset_of_match, &pdev->dev);
      99                 :            : 
     100         [ #  # ]:          0 :         if (match)
     101                 :          0 :                 func = (enum vexpress_reset_func)match->data;
     102                 :            :         else
     103                 :          0 :                 func = pdev->id_entry->driver_data;
     104                 :            : 
     105   [ #  #  #  # ]:          0 :         switch (func) {
     106                 :            :         case FUNC_SHUTDOWN:
     107                 :          0 :                 vexpress_power_off_device = &pdev->dev;
     108                 :          0 :                 pm_power_off = vexpress_power_off;
     109                 :          0 :                 break;
     110                 :            :         case FUNC_RESET:
     111         [ #  # ]:          0 :                 if (!vexpress_restart_device)
     112                 :          0 :                         vexpress_restart_device = &pdev->dev;
     113                 :          0 :                 arm_pm_restart = vexpress_restart;
     114                 :          0 :                 device_create_file(&pdev->dev, &dev_attr_active);
     115                 :          0 :                 break;
     116                 :            :         case FUNC_REBOOT:
     117                 :          0 :                 vexpress_restart_device = &pdev->dev;
     118                 :          0 :                 arm_pm_restart = vexpress_restart;
     119                 :          0 :                 device_create_file(&pdev->dev, &dev_attr_active);
     120                 :          0 :                 break;
     121                 :            :         };
     122                 :            : 
     123                 :          0 :         return 0;
     124                 :            : }
     125                 :            : 
     126                 :            : static const struct platform_device_id vexpress_reset_id_table[] = {
     127                 :            :         { .name = "vexpress-reset", .driver_data = FUNC_RESET, },
     128                 :            :         { .name = "vexpress-shutdown", .driver_data = FUNC_SHUTDOWN, },
     129                 :            :         { .name = "vexpress-reboot", .driver_data = FUNC_REBOOT, },
     130                 :            :         {}
     131                 :            : };
     132                 :            : 
     133                 :            : static struct platform_driver vexpress_reset_driver = {
     134                 :            :         .probe = vexpress_reset_probe,
     135                 :            :         .driver = {
     136                 :            :                 .name = "vexpress-reset",
     137                 :            :                 .of_match_table = vexpress_reset_of_match,
     138                 :            :         },
     139                 :            :         .id_table = vexpress_reset_id_table,
     140                 :            : };
     141                 :            : 
     142                 :          0 : static int __init vexpress_reset_init(void)
     143                 :            : {
     144                 :          0 :         return platform_driver_register(&vexpress_reset_driver);
     145                 :            : }
     146                 :            : device_initcall(vexpress_reset_init);

Generated by: LCOV version 1.9