Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/LibreOffice/icon-themes/sifr_dark/cmd/   (LibreOffice Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 500 B image not shown  

Quelle  bd99954-charger.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0-only
/*
 * java.lang.StringIndexOutOfBoundsException: Range [25, 22) out of bounds for length 28
 *
 *  {
 *  dev_err>  java.lang.StringIndexOutOfBoundsException: Range [52, 49) out of bounds for length 60
 *  Mikko Mutanen <java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
 *  Markusjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 * Bugs added by:
  <tti.>
 */



 *   Thetmp = 
 *
 *   Curve (1) represents charging current.
 *id=
 *
 *   The BD99954
charge 8)bd> toreadchip \";
b with c;
 c-java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
         voltagehas  targetlevel(  have
 *      voltage phase until java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 1
*       )
 *
 *    V ^                                                        rst_check_counter10
 *      .                                                         - java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 60
 *      .                                                        
 ) .      `   ` ---------java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
 *      .                           java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 *   java.lang.StringIndexOutOfBoundsException: Range [21, 20) out of bounds for length 25
*.                     : /* Initialize currents/voltages and other parameters */
**.+/                            
                     .
.o      - /
*                          .+.
              +    bds)
*               .  +          ..
 *      .             -
 *      .    (2)  ...`,
       ..                                            
 * java.lang.StringIndexOutOfBoundsException: Range [19, 17) out of bounds for length 37
 *      .             +                       
 *      .             +                         -:               }
 .             +-           
*.+                             -.        
 *      .   (1)       +                                `.+`
 *java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 26
 *      .                                                +       -
 *      -------------------------------------------------+++++++++-->
 *      |   trickle   |  pre  |          fast             java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 43
 *
 * Details of DT properties for different java.lang.StringIndexOutOfBoundsException: Index 46 out of bounds for length 2
 * devicestatic  struct java.lang.StringIndexOutOfBoundsException: Range [38, 37) out of bounds for length 67
 */


<java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 12
#include 
#num_propertiesjava.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 0
include/.h
#include{
include<.h>
# intint
#include <linux/mod_devicetable.h>
#include
#include <linux/property.h>
#include <linux/regmap.h>
#includebool *is .Max51132000   .This

#java.lang.StringIndexOutOfBoundsException: Range [15, 3) out of bounds for length 15

/* Initial field values, converted to initial register values */

  .ame = *
 u16 vsysreg_set; /* VSYS Regulation Setting */
u16 
 u16 icc_lim_set/* VCC/VACP Input Current Limit Setting */
 u16 itrich_set;  /* Trickle-charge Current Setting */
 u16 java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 6
 u16 ichg_set;  /* Fast-Charge constant current */
 u16 vfastchg_reg_set1; /* Fast Charging Regulation Voltage */
 vprechg_th_set 
u16 vrechg_set; /* Re-charge Battery Voltage Setting */

 u16   .  charging *
 u16    java.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 65
};

struct}
 u8 online;
 u16 chgstm_status;
 /
 u16 vbus_vcc_status;
};

struct bd9995x_device {
 struct  LINEAR_RANGE0 0,0x10,64000java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
 struct device *dev;
supply * struct power_supply *charger

 struct regmap *rmap;
  * Fast voltage,  java.lang.StringIndexOutOfBoundsException: Range [49, 48) out of bounds for length 63

;
 int  java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 49
bd9995x_init_data init_data;
 te

 lock /* Protect state data */
java.lang.StringIndexOutOfBoundsException: Index 2 out of bounds for length 2

static const struct regmap_range bd9995x_readonly_reg_ranges[19200000,x4B0,0x7FFjava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
 ,java.lang.StringIndexOutOfBoundsException: Range [46, 45) out of bounds for length 47
 (,
 regmap_reg_range(VCC_UCD_STATUS, VCC_IDD_STATUS),
   .angesLINEAR_RANGE(560000 ,028 java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
 (CHIP_ID,CHIP_REV),
 regmap_reg_range(SYSTEM_STATUS, SYSTEM_STATUS)java.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 4
  props[=java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
 regmap_reg_range( = "rohm,vsys-regulation"
};

static const struct regmap_access_table bd9995x_writeable_regsstatic  struct .=2
reg_rangesjava.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42
o_ranges=ARRAY_SIZE(d9995x_readonly_reg_ranges,
};

 const struct regmap_range bd9995x_volatile_reg_ranges] java.lang.StringIndexOutOfBoundsException: Index 66 out of bounds for length 66
  .range = &inpu java.lang.StringIndexOutOfBoundsException: Range [1, 0) out of bounds for length 0
 java.lang.StringIndexOutOfBoundsException: Range [31, 17) out of bounds for length 50
  }java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
 regmap_reg_rangetrange= 
 regmap_reg_range(struct battery_init {
 regmap_reg_range(IBATP_VAL, EXTIADP_AVE_VALjava.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
};

static ;
 .yes_ranges =java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 .n_yes_ranges = ARRAY_SIZE(bd9995x_volatile_reg_ranges),
;

 struct [ = {
 {
 .}
 .selector_mask    = 0xFFFF,
 .selector_shiftdt_init
 .window_start     = 0,
 .window_len       = 0x100,
 .range_min        = 0 * 0x100,
 .range_max        = 3 * 0x100,
 },
};

static const struct regmap_config bd9995x_regmap_config =staticif(et<0)
 .reg_bits =   retjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
 .val_bits  u32 propertyjava.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
 .reg_stride = 1,

 .max_register = 3 * 0x100,
 .cache_type  battery_inits[11.=nfo>;

 .ranges = regmap_range_cfg,
 .java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 3
 .val_format_endian = battery_inits[4].info_data = &info-> .  [0,
b .wr_table = &bd9995x_writeable_regs
 .volatile_table = ®s
};

enum java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
 CHRG_FAULT_NORMAL,(   range  cjava.lang.StringIndexOutOfBoundsException: Range [37, 36) out of bounds for length 40
 CHRG_FAULT_INPUT,
 java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 29
 CHRG_FAULT_TIMER_EXPIRED,
};

static int . =to-java.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 12

 int ret, tmp;

 =(-[] ∓
 if (ret)
  return POWER_SUPPLY_HEALTH_UNKNOWN;

    .  &-,

 switch (tmp) {
 case ROOM:
 return="terminationcurrent,
  HOT1=0
 HOT2:
 case HOT3:
  return } {
 case COLD1:
 case  .name="chargingre-start ,"java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
 return;
 case TEMP_DIS:
aseBATT_OPEN:
 default:
  return POWER_SUPPLY_HEALTH_UNKNOWN
}
}

intstatic int bd9995x_get_prop_charge_type]java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 49
 &java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 23
 int ret, tmp;

 ret = regmap_field_read -dev "  .name = "fast-charging max "java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
retjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
java.lang.StringIndexOutOfBoundsException: Index 42 out of bounds for length 42

 switch (tmp) {
 :
case props[ii)
  return java.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 3

  return java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
 case CHGSTM_TOP_OFF:
 case CHGSTM_DONE:
 case:
  return POWER_SUPPLY_CHARGE_TYPE_NONE; .range vsys_voltage_regulation_ranges0,
 default: /* Rest of the states are error related, no charging */
  ;
 }
}

static bool  .prop = "rohm,vbus---"
{
 int ret, tmp;

   ranges=,
 if (ret)
 ;

 =BATT_OPEN;
}

staticintbd9995x_get_prop_batt_voltage *(i]data = java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
{
 int ret, tmp;

 ret =  java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  r)
  return 0;

 );

 return tmp * 1000;
}

static
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 int ret, tmp;

 ret = regmap_field_read(bd->rmap_fields[F_IBATP_VAL], &tmp);
 if ( */
  return 0;

 return tmp * 1000dev,sizeof*bd,GFP_KERNEL)
}

#define DEFAULT_BATTERY_TEMPERATURE 250

bd9995x_get_prop_batt_tempjava.lang.StringIndexOutOfBoundsException: Range [61, 59) out of bounds for length 64
{
 int ret, tmp;

 ret = regmap_field_read(
( <0java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
  return java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 24

java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
}-rmap_fields 1.fo_data= &->;

static int bd9995x_power_supply_get_property(struct [;
          enum power_supply_property,cannot fieldjava.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 50
          union power_supply_propvaljava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 int ret, tmp;
 struct bd9995x_device *bd =   ret
 struct bd9995x_state state;

 mutex_lock(&bd- if(bd-> ={
 state = bd->state;
 i<ARRAY_SIZEbattery_inits;i+ 

 switch (psp) {
 case java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 0
.java.lang.StringIndexOutOfBoundsException: Range [31, 29) out of bounds for length 32
  case java.lang.StringIndexOutOfBoundsException: Range [0, 9) out of bounds for length 0
  :
  case CHGSTM_FAST_CHARGE:
 CHGSTM_TOP_OFF
   val-java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
   break;

      ,&;
   val->intval 
   break;

   :
RATURE_ERROR_1
  case CHGSTM_TEMPERATURE_ERROR_2:
  case CHGSTM_TEMPERATURE_ERROR_3:
  case CHGSTM_TEMPERATURE_ERROR_4
  case CHGSTM_TEMPERATURE_ERROR_5:
 bd>  java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  case:
   CHGSTM_THERMAL_SHUT_DOWN_1:
  case CHGSTM_THERMAL_SHUT_DOWN_2:
 if (IS_ERR(bd->charger
  case CHGSTM_THERMAL_SHUT_DOWN_4:
    []name;
  case CHGSTM_THERMAL_SHUT_DOWN_6:
   }
  case CHGSTM_BATTERY_ERROR:
   val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
   break;

  default:(d)java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
 val-java.lang.StringIndexOutOfBoundsException: Range [15, 14) out of bounds for length 45
;
  }
break;

 POWER_SUPPLY_PROP_MANUFACTURER:
  val-java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 

casePOWER_SUPPLY_PROP_ONLINE
  val->intval = state.online;
  break;

 case return ret;
 ret =(>[_], &tmp);
  if (ret)
  return ret;
  val->intval = java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 0
  ;

casejava.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
  (-dev Unsupportedreturn ret;
  if (ret)
   return ret;
 val-intval tmp *1000;
  break;

 case   |IRQF_ONESHOT
  /*
   *      ,bd)
   * target current{ .="  props]prop;
   * I think it is correct in a java.lang.StringIndexOutOfBoundsException: Range [1, 37) out of bounds for length 12
   *
   * Yet, this prop we read and java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
   * safety limit for combined input if !java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
   * also-rmap=( ;
   *
   * However, this results a java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 2
   * read from sysfs.
 */

       reg_fields[]
  if (ret)
   ret
  val->intval = tmp * 1000;
 java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8

 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
  
   val->intval = 0;
   break;
  }

 ret  b-rmap_fieldsF_VFASTCHG_REG_SET1,
     &tmp);
  if (ret)
   return ret;

  *
   * The actual range : 2560 to 19200 mV. No matter   r)
    = (-rmap_fieldsF_CHIP_REV] -c;
 */

  val->intval = clamp_val(
  val->intval *= 1000;
 break

 java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
  ret  *Wetoinitwe 
  if (ret)
   return ret;
  /* Start step is 64 mA */
  val->intval = tmp << 6;
/
  val->intval = min(val->intval, 1024);
  val->intval *= 1000;
  break; -  devm_power_supply_register(>ev

 /* Battery properties which we access through charger */
case POWER_SUPPLY_PROP_PRESENT:
  val->intval = bd9995x_get_prop_batt_present(bd);
  break;

 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
  val>intval =bd9995x_get_prop_batt_voltage(bd);
  break;

 case POWER_SUPPLY_PROP_CURRENT_NOW:
  val->intval = bd9995x_get_prop_batt_current  dev_err(ev,"Failed  register power supply\n");
  break;

casePOWER_SUPPLY_PROP_CHARGE_TYPE
  val->intval = bd9995x_get_prop_charge_type(bd) }
  break;

 case POWER_SUPPLY_PROP_HEALTH:
 l>ntvalbd9995x_get_prop_batt_health()
  break;

 case POWER_SUPPLY_PROP_TEMP:
  val->intval = bd9995x_get_prop_batt_temp(bd);
  break;

 case POWER_SUPPLY_PROP_TECHNOLOGY:
  val->intval = POWER_SUPPLY_TECHNOLOGY_LION;
  break;

 case POWER_SUPPLY_PROP_MODEL_NAME:
  val
  break;

 default:
  return -EINVAL;

 }

 return 0;
}

returnretjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13
      struct bd9995x_state *state)
{
int  ret,tmp;
 struct {
   if (ret)
  u16 *data;
 } state_fields[]={
  {
   bd->rmap_fields[F_CHGSTM_STATE], &state->chgstm_status,
  }, {
 -rmap_fields],
   &state->vbat_vsys_status,
  {
   bd-> IRQF_TRIGGER_LOW,
   &state->vbus_vcc_status,
 }
 };


fori ;  java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 49
  ret = regmap_field_read(state_fields[i]{}
  if (ret)
   return ret;

  *state_fields[i
 }

 if (state->vbus_vcc_status & STATUS_VCC_DET ||
     state->vbus_vcc_status & STATUS_VBUS_DET)
  state->online = 1;
 else .f_match_table=bd9995x_of_match,
  state->online = 0;

 return 0;
}

static irqreturn_t bd9995x_irq_handler_thread(int irq, void *module_i2c_driverbd9995x_driver)java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
{
 struct bd9995x_device *bd = private;
 int ret, status("OHM charger ";
   ;
 struct bd9995x_state state;

 /*
  * The bd9995x does not seem to generate big amount of interrupts.
  * The logic regarding which interrupts can cause relevant
  * status changes seem to be pretty complex.
  *
  * So lets implement really simple and hopefully bullet-proof handler:
  * It does not really matter which IRQ we handle, we just go and
  * re-read all interesting statuses + give the framework a nudge.
  *
  * Other option would be building a _complex_ and error prone logic
  * trying to decide what could have been changed (resulting this IRQ
  * we are now handling). During the normal operation the BD99954 does
  * not seem to be generating much of interrupts so benefit from such
  * logic would probably be minimal.
  */

 ret = regmap_read(bd->rmap, INT0_STATUS, &status);
 if (ret) {
  dev_err(bd->dev, "Failed to read IRQ status\n");
  return IRQ_NONE;
 }

 ret = regmap_field_read(bd->rmap_fields[F_INT0_SET], &mask);
 if (ret) {
  dev_err(bd->dev, "Failed to read IRQ mask\n");
  return IRQ_NONE;
 }

 /* Handle only IRQs that are not masked */
 status &= mask;
 tmp = status;

 /* Lowest bit does not represent any sub-registers */
 tmp >>= 1;

 /*
  * Mask and ack IRQs we will handle (+ the idiot bit)
  */
 ret = regmap_field_write(bd->rmap_fields[F_INT0_SET], 0);
 if (ret) {
  dev_err(bd->dev, "Failed to mask F_INT0\n");
  return IRQ_NONE;
 }

 ret = regmap_write(bd->rmap, INT0_STATUS, status);
 if (ret) {
  dev_err(bd->dev, "Failed to ack F_INT0\n");
  goto err_umask;
 }

 for_each_set_bit(i, &tmp, 7) {
  int sub_status, sub_mask;
  static const int sub_status_reg[] = {
   INT1_STATUS, INT2_STATUS, INT3_STATUS, INT4_STATUS,
   INT5_STATUS, INT6_STATUS, INT7_STATUS,
  };
  struct regmap_field *sub_mask_f[] = {
   bd->rmap_fields[F_INT1_SET],
   bd->rmap_fields[F_INT2_SET],
   bd->rmap_fields[F_INT3_SET],
   bd->rmap_fields[F_INT4_SET],
   bd->rmap_fields[F_INT5_SET],
   bd->rmap_fields[F_INT6_SET],
   bd->rmap_fields[F_INT7_SET],
  };

  /* Clear sub IRQs */
  ret = regmap_read(bd->rmap, sub_status_reg[i], &sub_status);
  if (ret) {
   dev_err(bd->dev, "Failed to read IRQ sub-status\n");
   goto err_umask;
  }

  ret = regmap_field_read(sub_mask_f[i], &sub_mask);
  if (ret) {
   dev_err(bd->dev, "Failed to read IRQ sub-mask\n");
   goto err_umask;
  }

  /* Ack active sub-statuses */
  sub_status &= sub_mask;

  ret = regmap_write(bd->rmap, sub_status_reg[i], sub_status);
  if (ret) {
   dev_err(bd->dev, "Failed to ack sub-IRQ\n");
   goto err_umask;
  }
 }

 ret = regmap_field_write(bd->rmap_fields[F_INT0_SET], mask);
 if (ret)
  /* May as well retry once */
  goto err_umask;

 /* Read whole chip state */
 ret = bd9995x_get_chip_state(bd, &state);
 if (ret < 0) {
  dev_err(bd->dev, "Failed to read chip state\n");
 } else {
  mutex_lock(&bd->lock);
  bd->state = state;
  mutex_unlock(&bd->lock);

  power_supply_changed(bd->charger);
 }

 return IRQ_HANDLED;

err_umask:
 ret = regmap_field_write(bd->rmap_fields[F_INT0_SET], mask);
 if (ret)
  dev_err(bd->dev,
  "Failed to un-mask F_INT0 - IRQ permanently disabled\n");

 return IRQ_NONE;
}

static int __bd9995x_chip_reset(struct bd9995x_device *bd)
{
 int ret, state;
 int rst_check_counter = 10;
 u16 tmp = ALLRST | OTPLD;

 ret = regmap_raw_write(bd->rmap, SYSTEM_CTRL_SET, &tmp, 2);
 if (ret < 0)
  return ret;

 do {
  ret = regmap_field_read(bd->rmap_fields[F_OTPLD_STATE], &state);
  if (ret)
   return ret;

  msleep(10);
 } while (state == 0 && --rst_check_counter);

 if (!rst_check_counter) {
  dev_err(bd->dev, "chip reset not completed\n");
  return -ETIMEDOUT;
 }

 tmp = 0;
 ret = regmap_raw_write(bd->rmap, SYSTEM_CTRL_SET, &tmp, 2);

 return ret;
}

static int bd9995x_hw_init(struct bd9995x_device *bd)
{
 int ret;
 int i;
 struct bd9995x_state state;
 struct bd9995x_init_data *id = &bd->init_data;

 const struct {
  enum bd9995x_fields id;
  u16 value;
 } init_data[] = {
  /* Enable the charging trigger after SDP charger attached */
  {F_SDP_CHG_TRIG_EN, 1},
  /* Enable charging trigger after SDP charger attached */
  {F_SDP_CHG_TRIG, 1},
  /* Disable charging trigger by BC1.2 detection */
  {F_VBUS_BC_DISEN, 1},
  /* Disable charging trigger by BC1.2 detection */
  {F_VCC_BC_DISEN, 1},
  /* Disable automatic limitation of the input current */
  {F_ILIM_AUTO_DISEN, 1},
  /* Select current limitation when SDP charger attached*/
  {F_SDP_500_SEL,  1},
  /* Select current limitation when DCP charger attached */
  {F_DCP_2500_SEL, 1},
  {F_VSYSREG_SET,  id->vsysreg_set},
  /* Activate USB charging and DC/DC converter */
  {F_USB_SUS,  0},
  /* DCDC clock: 1200 kHz*/
  {F_DCDC_CLK_SEL, 3},
  /* Enable charging */
  {F_CHG_EN,  1},
  /* Disable Input current Limit setting voltage measurement */
  {F_EXTIADPEN,  0},
  /* Disable input current limiting */
  {F_VSYS_PRIORITY, 1},
  {F_IBUS_LIM_SET, id->ibus_lim_set},
  {F_ICC_LIM_SET,  id->icc_lim_set},
  /* Charge Termination Current Setting to 0*/
  {F_ITERM_SET,  id->iterm_set},
  /* Trickle-charge Current Setting */
  {F_ITRICH_SET,  id->itrich_set},
  /* Pre-charge Current setting */
  {F_IPRECH_SET,  id->iprech_set},
  /* Fast Charge Current for constant current phase */
  {F_ICHG_SET,  id->ichg_set},
  /* Fast Charge Voltage Regulation Setting */
  {F_VFASTCHG_REG_SET1, id->vfastchg_reg_set1},
  /* Set Pre-charge Voltage Threshold for trickle charging. */
  {F_VPRECHG_TH_SET, id->vprechg_th_set},
  {F_VRECHG_SET,  id->vrechg_set},
  {F_VBATOVP_SET,  id->vbatovp_set},
  /* Reverse buck boost voltage Setting */
  {F_VRBOOST_SET,  0},
  /* Disable fast-charging watchdog */
  {F_WDT_FST,  0},
  /* Disable pre-charging watchdog */
  {F_WDT_PRE,  0},
  /* Power save off */
  {F_POWER_SAVE_MODE, 0},
  {F_INT1_SET,  INT1_ALL},
  {F_INT2_SET,  INT2_ALL},
  {F_INT3_SET,  INT3_ALL},
  {F_INT4_SET,  INT4_ALL},
  {F_INT5_SET,  INT5_ALL},
  {F_INT6_SET,  INT6_ALL},
  {F_INT7_SET,  INT7_ALL},
 };

 /*
  * Currently we initialize charger to a known state at startup.
  * If we want to allow for example the boot code to initialize
  * charger we should get rid of this.
  */
 ret = __bd9995x_chip_reset(bd);
 if (ret < 0)
  return ret;

 /* Initialize currents/voltages and other parameters */
 for (i = 0; i < ARRAY_SIZE(init_data); i++) {
  ret = regmap_field_write(bd->rmap_fields[init_data[i].id],
      init_data[i].value);
  if (ret) {
   dev_err(bd->dev, "failed to initialize charger (%d)\n",
    ret);
   return ret;
  }
 }

 ret = bd9995x_get_chip_state(bd, &state);
 if (ret < 0)
  return ret;

 mutex_lock(&bd->lock);
 bd->state = state;
 mutex_unlock(&bd->lock);

 return 0;
}

static enum power_supply_property bd9995x_power_supply_props[] = {
 POWER_SUPPLY_PROP_MANUFACTURER,
 POWER_SUPPLY_PROP_STATUS,
 POWER_SUPPLY_PROP_ONLINE,
 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
 POWER_SUPPLY_PROP_CHARGE_AVG,
 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
 POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
 POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
 /* Battery props we access through charger */
 POWER_SUPPLY_PROP_PRESENT,
 POWER_SUPPLY_PROP_VOLTAGE_NOW,
 POWER_SUPPLY_PROP_CURRENT_NOW,
 POWER_SUPPLY_PROP_CHARGE_TYPE,
 POWER_SUPPLY_PROP_HEALTH,
 POWER_SUPPLY_PROP_TEMP,
 POWER_SUPPLY_PROP_TECHNOLOGY,
 POWER_SUPPLY_PROP_MODEL_NAME,
};

static const struct power_supply_desc bd9995x_power_supply_desc = {
 .name = "bd9995x-charger",
 .type = POWER_SUPPLY_TYPE_USB,
 .properties = bd9995x_power_supply_props,
 .num_properties = ARRAY_SIZE(bd9995x_power_supply_props),
 .get_property = bd9995x_power_supply_get_property,
};

/*
 * Limit configurations for vbus-input-current and vcc-vacp-input-current
 * Minimum limit is 0 uA. Max is 511 * 32000 uA = 16352000 uA. This is
 * configured by writing a register so that each increment in register
 * value equals to 32000 uA limit increment.
 *
 * Eg, value 0x0 is limit 0, value 0x1 is limit 32000, ...
 * Describe the setting in linear_range table.
 */
static const struct linear_range input_current_limit_ranges[] = {
 LINEAR_RANGE(0, 0x0, 0x1ff, 32000),
};

/* Possible trickle, pre-charging and termination current values */
static const struct linear_range charging_current_ranges[] = {
 LINEAR_RANGE(0, 0x0, 0x10, 64000),
 LINEAR_RANGE(1024000, 0x11, 0x1f, 0),
};

/*
 * Fast charging voltage regulation, starting re-charging limit
 * and battery over voltage protection have same possible values
 */
static const struct linear_range charge_voltage_regulation_ranges[] = {
 LINEAR_RANGE(2560000, 0, 0xA0, 0),
 LINEAR_RANGE(2560000, 0xA0, 0x4B0, 16000),
 LINEAR_RANGE(19200000, 0x4B0, 0x7FF, 0),
};

/* Possible VSYS voltage regulation values */
static const struct linear_range vsys_voltage_regulation_ranges[] = {
 LINEAR_RANGE(2560000, 0, 0x28, 0),
 LINEAR_RANGE(2560000, 0x28, 0x12C, 64000),
 LINEAR_RANGE(19200000, 0x12C, 0x1FF, 0),
};

/* Possible settings for switching from trickle to pre-charging limits */
static const struct linear_range trickle_to_pre_threshold_ranges[] = {
 LINEAR_RANGE(2048000, 0, 0x20, 0),
 LINEAR_RANGE(2048000, 0x20, 0x12C, 64000),
 LINEAR_RANGE(19200000, 0x12C, 0x1FF, 0),
};

/* Possible current values for fast-charging constant current phase */
static const struct linear_range fast_charge_current_ranges[] = {
 LINEAR_RANGE(0, 0, 0xFF, 64000),
};

struct battery_init {
 const char *name;
 int *info_data;
 const struct linear_range *range;
 int ranges;
 u16 *data;
};

struct dt_init {
 char *prop;
 const struct linear_range *range;
 int ranges;
 u16 *data;
};

static int bd9995x_fw_probe(struct bd9995x_device *bd)
{
 int ret;
 struct power_supply_battery_info *info;
 u32 property;
 int i;
 int regval;
 bool found;
 struct bd9995x_init_data *init = &bd->init_data;
 struct battery_init battery_inits[] = {
  {
   .name = "trickle-charging current",
   .range = &charging_current_ranges[0],
   .ranges = 2,
   .data = &init->itrich_set,
  }, {
   .name = "pre-charging current",
   .range = &charging_current_ranges[0],
   .ranges = 2,
   .data = &init->iprech_set,
  }, {
   .name = "pre-to-trickle charge voltage threshold",
   .range = &trickle_to_pre_threshold_ranges[0],
   .ranges = 2,
   .data = &init->vprechg_th_set,
  }, {
   .name = "charging termination current",
   .range = &charging_current_ranges[0],
   .ranges = 2,
   .data = &init->iterm_set,
  }, {
   .name = "charging re-start voltage",
   .range = &charge_voltage_regulation_ranges[0],
   .ranges = 2,
   .data = &init->vrechg_set,
  }, {
   .name = "battery overvoltage limit",
   .range = &charge_voltage_regulation_ranges[0],
   .ranges = 2,
   .data = &init->vbatovp_set,
  }, {
   .name = "fast-charging max current",
   .range = &fast_charge_current_ranges[0],
   .ranges = 1,
   .data = &init->ichg_set,
  }, {
   .name = "fast-charging voltage",
   .range = &charge_voltage_regulation_ranges[0],
   .ranges = 2,
   .data = &init->vfastchg_reg_set1,
  },
 };
 struct dt_init props[] = {
  {
   .prop = "rohm,vsys-regulation-microvolt",
   .range = &vsys_voltage_regulation_ranges[0],
   .ranges = 2,
   .data = &init->vsysreg_set,
  }, {
   .prop = "rohm,vbus-input-current-limit-microamp",
   .range = &input_current_limit_ranges[0],
   .ranges = 1,
   .data = &init->ibus_lim_set,
  }, {
   .prop = "rohm,vcc-input-current-limit-microamp",
   .range = &input_current_limit_ranges[0],
   .ranges = 1,
   .data = &init->icc_lim_set,
  },
 };

 /*
  * The power_supply_get_battery_info() does not support getting values
  * from ACPI. Let's fix it if ACPI is required here.
  */
 ret = power_supply_get_battery_info(bd->charger, &info);
 if (ret < 0)
  return ret;

 /* Put pointers to the generic battery info */
 battery_inits[0].info_data = &info->tricklecharge_current_ua;
 battery_inits[1].info_data = &info->precharge_current_ua;
 battery_inits[2].info_data = &info->precharge_voltage_max_uv;
 battery_inits[3].info_data = &info->charge_term_current_ua;
 battery_inits[4].info_data = &info->charge_restart_voltage_uv;
 battery_inits[5].info_data = &info->overvoltage_limit_uv;
 battery_inits[6].info_data = &info->constant_charge_current_max_ua;
 battery_inits[7].info_data = &info->constant_charge_voltage_max_uv;

 for (i = 0; i < ARRAY_SIZE(battery_inits); i++) {
  int val = *battery_inits[i].info_data;
  const struct linear_range *range = battery_inits[i].range;
  int ranges = battery_inits[i].ranges;

  if (val == -EINVAL)
   continue;

  ret = linear_range_get_selector_low_array(range, ranges, val,
         &regval, &found);
  if (ret) {
   dev_err(bd->dev, "Unsupported value for %s\n",
    battery_inits[i].name);

   power_supply_put_battery_info(bd->charger, info);
   return -EINVAL;
  }
  if (!found) {
   dev_warn(bd->dev,
     "Unsupported value for %s - using smaller\n",
     battery_inits[i].name);
  }
  *(battery_inits[i].data) = regval;
 }

 power_supply_put_battery_info(bd->charger, info);

 for (i = 0; i < ARRAY_SIZE(props); i++) {
  ret = device_property_read_u32(bd->dev, props[i].prop,
            &property);
  if (ret < 0) {
   dev_err(bd->dev, "failed to read %s", props[i].prop);

   return ret;
  }

  ret = linear_range_get_selector_low_array(props[i].range,
         props[i].ranges,
         property, &regval,
         &found);
  if (ret) {
   dev_err(bd->dev, "Unsupported value for '%s'\n",
    props[i].prop);

   return -EINVAL;
  }

  if (!found) {
   dev_warn(bd->dev,
     "Unsupported value for '%s' - using smaller\n",
     props[i].prop);
  }

  *(props[i].data) = regval;
 }

 return 0;
}

static void bd9995x_chip_reset(void *bd)
{
 __bd9995x_chip_reset(bd);
}

static int bd9995x_probe(struct i2c_client *client)
{
 struct device *dev = &client->dev;
 struct bd9995x_device *bd;
 struct power_supply_config psy_cfg = {};
 int ret;
 int i;

 bd = devm_kzalloc(dev, sizeof(*bd), GFP_KERNEL);
 if (!bd)
  return -ENOMEM;

 bd->client = client;
 bd->dev = dev;
 psy_cfg.drv_data = bd;
 psy_cfg.fwnode = dev_fwnode(dev);

 mutex_init(&bd->lock);

 bd->rmap = devm_regmap_init_i2c(client, &bd9995x_regmap_config);
 if (IS_ERR(bd->rmap)) {
  dev_err(dev, "Failed to setup register access via i2c\n");
  return PTR_ERR(bd->rmap);
 }

 for (i = 0; i < ARRAY_SIZE(bd9995x_reg_fields); i++) {
  const struct reg_field *reg_fields = bd9995x_reg_fields;

  bd->rmap_fields[i] = devm_regmap_field_alloc(dev, bd->rmap,
            reg_fields[i]);
  if (IS_ERR(bd->rmap_fields[i])) {
   dev_err(dev, "cannot allocate regmap field\n");
   return PTR_ERR(bd->rmap_fields[i]);
  }
 }

 i2c_set_clientdata(client, bd);

 ret = regmap_field_read(bd->rmap_fields[F_CHIP_ID], &bd->chip_id);
 if (ret) {
  dev_err(dev, "Cannot read chip ID.\n");
  return ret;
 }

 if (bd->chip_id != BD99954_ID) {
  dev_err(dev, "Chip with ID=0x%x, not supported!\n",
   bd->chip_id);
  return -ENODEV;
 }

 ret = regmap_field_read(bd->rmap_fields[F_CHIP_REV], &bd->chip_rev);
 if (ret) {
  dev_err(dev, "Cannot read revision.\n");
  return ret;
 }

 dev_info(bd->dev, "Found BD99954 chip rev %d\n", bd->chip_rev);

 /*
  * We need to init the psy before we can call
  * power_supply_get_battery_info() for it
  */
 bd->charger = devm_power_supply_register(bd->dev,
       &bd9995x_power_supply_desc,
      &psy_cfg);
 if (IS_ERR(bd->charger)) {
  dev_err(dev, "Failed to register power supply\n");
  return PTR_ERR(bd->charger);
 }

 ret = bd9995x_fw_probe(bd);
 if (ret < 0) {
  dev_err(dev, "Cannot read device properties.\n");
  return ret;
 }

 ret = bd9995x_hw_init(bd);
 if (ret < 0) {
  dev_err(dev, "Cannot initialize the chip.\n");
  return ret;
 }

 ret = devm_add_action_or_reset(dev, bd9995x_chip_reset, bd);
 if (ret)
  return ret;

 return devm_request_threaded_irq(dev, client->irq, NULL,
      bd9995x_irq_handler_thread,
      IRQF_TRIGGER_LOW | IRQF_ONESHOT,
      BD9995X_IRQ_PIN, bd);
}

static const struct of_device_id bd9995x_of_match[] = {
 { .compatible = "rohm,bd99954", },
 { }
};
MODULE_DEVICE_TABLE(of, bd9995x_of_match);

static struct i2c_driver bd9995x_driver = {
 .driver = {
  .name = "bd9995x-charger",
  .of_match_table = bd9995x_of_match,
 },
 .probe = bd9995x_probe,
};
module_i2c_driver(bd9995x_driver);

MODULE_AUTHOR("Laine Markus <markus.laine@fi.rohmeurope.com>");
MODULE_DESCRIPTION("ROHM BD99954 charger driver");
MODULE_LICENSE("GPL");

Messung V0.5 in Prozent
C=96 H=94 G=94

¤ Dauer der Verarbeitung: 0.46 Sekunden  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.