Version:  2.0.40 2.2.26 2.4.37 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6 4.7 4.8

Linux/drivers/power/intel_mid_battery.c

  1 /*
  2  * intel_mid_battery.c - Intel MID PMIC Battery Driver
  3  *
  4  * Copyright (C) 2009 Intel Corporation
  5  *
  6  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7  *
  8  * This program is free software; you can redistribute it and/or modify
  9  * it under the terms of the GNU General Public License as published by
 10  * the Free Software Foundation; version 2 of the License.
 11  *
 12  * This program is distributed in the hope that it will be useful, but
 13  * WITHOUT ANY WARRANTY; without even the implied warranty of
 14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 15  * General Public License for more details.
 16  *
 17  * You should have received a copy of the GNU General Public License along
 18  * with this program; if not, write to the Free Software Foundation, Inc.,
 19  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 20  *
 21  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 22  * Author: Nithish Mahalingam <nithish.mahalingam@intel.com>
 23  */
 24 
 25 #include <linux/module.h>
 26 #include <linux/init.h>
 27 #include <linux/err.h>
 28 #include <linux/interrupt.h>
 29 #include <linux/workqueue.h>
 30 #include <linux/jiffies.h>
 31 #include <linux/param.h>
 32 #include <linux/device.h>
 33 #include <linux/spi/spi.h>
 34 #include <linux/platform_device.h>
 35 #include <linux/power_supply.h>
 36 
 37 #include <asm/intel_scu_ipc.h>
 38 
 39 #define DRIVER_NAME "pmic_battery"
 40 
 41 /*********************************************************************
 42  *              Generic defines
 43  *********************************************************************/
 44 
 45 static int debug;
 46 module_param(debug, int, 0444);
 47 MODULE_PARM_DESC(debug, "Flag to enable PMIC Battery debug messages.");
 48 
 49 #define PMIC_BATT_DRV_INFO_UPDATED      1
 50 #define PMIC_BATT_PRESENT               1
 51 #define PMIC_BATT_NOT_PRESENT           0
 52 #define PMIC_USB_PRESENT                PMIC_BATT_PRESENT
 53 #define PMIC_USB_NOT_PRESENT            PMIC_BATT_NOT_PRESENT
 54 
 55 /* pmic battery register related */
 56 #define PMIC_BATT_CHR_SCHRGINT_ADDR     0xD2
 57 #define PMIC_BATT_CHR_SBATOVP_MASK      (1 << 1)
 58 #define PMIC_BATT_CHR_STEMP_MASK        (1 << 2)
 59 #define PMIC_BATT_CHR_SCOMP_MASK        (1 << 3)
 60 #define PMIC_BATT_CHR_SUSBDET_MASK      (1 << 4)
 61 #define PMIC_BATT_CHR_SBATDET_MASK      (1 << 5)
 62 #define PMIC_BATT_CHR_SDCLMT_MASK       (1 << 6)
 63 #define PMIC_BATT_CHR_SUSBOVP_MASK      (1 << 7)
 64 #define PMIC_BATT_CHR_EXCPT_MASK        0x86
 65 
 66 #define PMIC_BATT_ADC_ACCCHRG_MASK      (1 << 31)
 67 #define PMIC_BATT_ADC_ACCCHRGVAL_MASK   0x7FFFFFFF
 68 
 69 /* pmic ipc related */
 70 #define PMIC_BATT_CHR_IPC_FCHRG_SUBID   0x4
 71 #define PMIC_BATT_CHR_IPC_TCHRG_SUBID   0x6
 72 
 73 /* types of battery charging */
 74 enum batt_charge_type {
 75         BATT_USBOTG_500MA_CHARGE,
 76         BATT_USBOTG_TRICKLE_CHARGE,
 77 };
 78 
 79 /* valid battery events */
 80 enum batt_event {
 81         BATT_EVENT_BATOVP_EXCPT,
 82         BATT_EVENT_USBOVP_EXCPT,
 83         BATT_EVENT_TEMP_EXCPT,
 84         BATT_EVENT_DCLMT_EXCPT,
 85         BATT_EVENT_EXCPT
 86 };
 87 
 88 
 89 /*********************************************************************
 90  *              Battery properties
 91  *********************************************************************/
 92 
 93 /*
 94  * pmic battery info
 95  */
 96 struct pmic_power_module_info {
 97         bool is_dev_info_updated;
 98         struct device *dev;
 99         /* pmic battery data */
100         unsigned long update_time;              /* jiffies when data read */
101         unsigned int usb_is_present;
102         unsigned int batt_is_present;
103         unsigned int batt_health;
104         unsigned int usb_health;
105         unsigned int batt_status;
106         unsigned int batt_charge_now;           /* in mAS */