xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 1 | /********************************************************************* |
| 2 | Copyright 2016 by ZIXC Corporation. |
| 3 | * |
| 4 | * FileName:: power.c |
| 5 | * File Mark: |
| 6 | * Description: |
| 7 | * Others: |
| 8 | * Version: v1.0 |
| 9 | * Author: zhouqi |
| 10 | * Date: 2014-1-15 |
| 11 | |
| 12 | * History 1: |
| 13 | * Date: |
| 14 | * Version: |
| 15 | * Author: |
| 16 | * Modification: |
| 17 | * History 2: |
| 18 | **********************************************************************/ |
| 19 | |
| 20 | #include <common.h> |
| 21 | #include <errno.h> |
| 22 | #include <command.h> |
| 23 | #include <malloc.h> |
| 24 | #include <asm/io.h> |
| 25 | #include <power.h> |
| 26 | #include <config.h> |
| 27 | |
| 28 | |
| 29 | static struct pmu_opt *s_pmu = NULL; |
| 30 | |
| 31 | /******************************************************************************* |
| 32 | * Function: power_init |
| 33 | * Description: |
| 34 | * Parameters: |
| 35 | * Input: |
| 36 | * |
| 37 | * Output: |
| 38 | * |
| 39 | * Returns: |
| 40 | * |
| 41 | * |
| 42 | * Others: |
| 43 | ********************************************************************************/ |
| 44 | int power_init(void) |
| 45 | { |
| 46 | /* ·ÖÅä½á¹¹Ìå¿Õ¼ä */ |
| 47 | s_pmu = malloc(sizeof(struct pmu_opt)); |
| 48 | if (!s_pmu) |
| 49 | { |
| 50 | printf( "power: out of memory for data structure pmu_opt\n"); |
| 51 | return -EIO; |
| 52 | } |
| 53 | |
| 54 | /* pmu³õʼ»¯ */ |
| 55 | pmu_init(); |
| 56 | |
| 57 | return 0; |
| 58 | |
| 59 | } |
| 60 | |
| 61 | |
| 62 | /******************************************************************************* |
| 63 | * Function: register_pmu_opt |
| 64 | * Description: |
| 65 | * Parameters: |
| 66 | * Input: |
| 67 | * |
| 68 | * Output: |
| 69 | * |
| 70 | * Returns: |
| 71 | * |
| 72 | * |
| 73 | * Others: |
| 74 | ********************************************************************************/ |
| 75 | int register_pmu_opt(struct pmu_opt *opt) |
| 76 | { |
| 77 | if( opt->read_reg ) |
| 78 | s_pmu->read_reg = opt->read_reg; |
| 79 | else |
| 80 | return -EIO; |
| 81 | |
| 82 | if( opt->write_reg ) |
| 83 | s_pmu->write_reg = opt->write_reg; |
| 84 | else |
| 85 | return -EIO; |
| 86 | |
| 87 | if( opt->get_boot_reason ) |
| 88 | s_pmu->get_boot_reason = opt->get_boot_reason; |
| 89 | else |
| 90 | return -EIO; |
| 91 | |
| 92 | if( opt->ps_hold_pull_on ) |
| 93 | s_pmu->ps_hold_pull_on = opt->ps_hold_pull_on; |
| 94 | else |
| 95 | return -EIO; |
| 96 | |
| 97 | if( opt->ps_hold_pull_off ) |
| 98 | s_pmu->ps_hold_pull_off = opt->ps_hold_pull_off; |
| 99 | else |
| 100 | return -EIO; |
| 101 | |
| 102 | if( opt->ps_hold2_pull_on ) |
| 103 | s_pmu->ps_hold2_pull_on = opt->ps_hold2_pull_on; |
| 104 | |
| 105 | if( opt->ps_hold2_pull_off ) |
| 106 | s_pmu->ps_hold2_pull_off = opt->ps_hold2_pull_off; |
| 107 | |
| 108 | if( opt->power_off ) |
| 109 | s_pmu->power_off = opt->power_off; |
| 110 | else |
| 111 | return -EIO; |
| 112 | |
| 113 | return SUCCESS; |
| 114 | } |
| 115 | |
| 116 | /******************************************************************************* |
| 117 | * Function: get_pmu_opt |
| 118 | * Description: |
| 119 | * Parameters: |
| 120 | * Input: |
| 121 | * |
| 122 | * Output: |
| 123 | * |
| 124 | * Returns: |
| 125 | * |
| 126 | * |
| 127 | * Others: |
| 128 | ********************************************************************************/ |
| 129 | struct pmu_opt * get_pmu_opt(void) |
| 130 | { |
| 131 | return s_pmu; |
| 132 | } |
| 133 | |