^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * SharpSL Battery/PM Driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (c) 2004-2005 Richard Purdie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef _MACH_SHARPSL_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define _MACH_SHARPSL_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) struct sharpsl_charger_machinfo {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) void (*init)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) void (*exit)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) int gpio_acin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) int gpio_batfull;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) int batfull_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) int gpio_batlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) int gpio_fatal;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) void (*discharge)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) void (*discharge1)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) void (*charge)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) void (*measure_temp)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) void (*presuspend)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) void (*postsuspend)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void (*earlyresume)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) unsigned long (*read_devdata)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define SHARPSL_BATT_VOLT 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define SHARPSL_BATT_TEMP 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define SHARPSL_ACIN_VOLT 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define SHARPSL_STATUS_ACIN 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define SHARPSL_STATUS_LOCK 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define SHARPSL_STATUS_CHRGFULL 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define SHARPSL_STATUS_FATAL 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) bool (*charger_wakeup)(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int (*should_wakeup)(unsigned int resume_on_alarm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) void (*backlight_limit)(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int (*backlight_get_status) (void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) int charge_on_volt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int charge_on_temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int charge_acin_high;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) int charge_acin_low;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) int fatal_acin_volt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int fatal_noacin_volt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int bat_levels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct battery_thresh *bat_levels_noac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct battery_thresh *bat_levels_acin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct battery_thresh *bat_levels_noac_bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) struct battery_thresh *bat_levels_acin_bl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int status_high_acin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) int status_low_acin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) int status_high_noac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) int status_low_noac;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct battery_thresh {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int voltage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) int percentage;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) struct battery_stat {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int ac_status; /* APM AC Present/Not Present */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) int mainbat_status; /* APM Main Battery Status */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) int mainbat_percent; /* Main Battery Percentage Charge */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) int mainbat_voltage; /* Main Battery Voltage */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct sharpsl_pm_status {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct timer_list ac_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct timer_list chrg_full_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int charge_mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) #define CHRG_ERROR (-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define CHRG_OFF (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) #define CHRG_ON (1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define CHRG_DONE (2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) unsigned int flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) #define SHARPSL_SUSPENDED (1 << 0) /* Device is Suspended */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) #define SHARPSL_ALARM_ACTIVE (1 << 1) /* Alarm is for charging event (not user) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define SHARPSL_BL_LIMIT (1 << 2) /* Backlight Intensity Limited */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define SHARPSL_APM_QUEUED (1 << 3) /* APM Event Queued */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define SHARPSL_DO_OFFLINE_CHRG (1 << 4) /* Trigger the offline charger */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int full_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) unsigned long charge_start_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct sharpsl_charger_machinfo *machinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct battery_stat battstat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) extern struct sharpsl_pm_status sharpsl_pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) extern struct battery_thresh sharpsl_battery_levels_acin[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) extern struct battery_thresh sharpsl_battery_levels_noac[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #define SHARPSL_LED_ERROR 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) #define SHARPSL_LED_ON 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) #define SHARPSL_LED_OFF 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) void sharpsl_battery_kick(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) void sharpsl_pm_led(int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /* MAX1111 Channel Definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #define MAX1111_BATT_VOLT 4u
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) #define MAX1111_BATT_TEMP 2u
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #define MAX1111_ACIN_VOLT 6u
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int sharpsl_pm_pxa_read_max1111(int channel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) void corgi_lcd_limit_intensity(int limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) #endif