Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  sc2731_charger.c   Sprache: C

 

// SPDX-License-Identifier: GPL-2.0
// Copyright (C) 2018 Spreadtrum Communications Inc.


#nclude </.hincludelinux/platform_device>
# <linux.>
#include <linux/usb/phy.h>
#include <linux/regmap.h>
#include <linux/notifier.h>
#include <linux/of.h>

/* PMIC global registers definition */
#define SC2731_CHARGE_STATUS  0xedc
#define SC2731_CHARGE_FULL  BIT(4)
#define SC2731_MODULE_EN1  0xc0c
#define SC2731_CHARGE_EN  BIT(5)

/* SC2731 switch charger registers definition */
#define SC2731_CHG_CFG0   0x0
#define SC2731_CHG_CFG1   0x4
#define SC2731_CHG_CFG2   0x8
#define SC2731_CHG_CFG3   0xc
#define SC2731_CHG_CFG4   0x10
#define SC2731_CHG_CFG5   0x28

/* SC2731_CHG_CFG0 register definition */
#define SC2731_PRECHG_RNG_SHIFT  11
#define SC2731_PRECHG_RNG_MASK  GENMASK(12, 11)

#define SC2731_TERMINATION_VOL_MASK GENMASK(2, 1)
#define SC2731_TERMINATION_VOL_SHIFT 1
#define SC2731_TERMINATION_VOL_CAL_MASK GENMASK(8, 3)
#define SC2731_TERMINATION_VOL_CAL_SHIFT 3
#define SC2731_TERMINATION_CUR_MASK GENMASK(2, 0)

#define SC2731_CC_EN   BIT(13)
#define SC2731_CHARGER_PD  BIT(0)

/* SC2731_CHG_CFG1 register definition */
#define SC2731_CUR_MASK   GENMASK(5, 0)

/* SC2731_CHG_CFG5 register definition */
#define SC2731_CUR_LIMIT_SHIFT  8
#define SC2731_CUR_LIMIT_MASK  GENMASK(9, 8)

/* Default current definition (unit is mA) */
#define SC2731_CURRENT_LIMIT_100 100
#define SC2731_CURRENT_LIMIT_500 500
#define SC2731_CURRENT_LIMIT_900 900
#define SC2731_CURRENT_LIMIT_2000 2000
#define SC2731_CURRENT_PRECHG  450
#define SC2731_CURRENT_STEP  50

struct sc2731_charger_info {
 struct device *dev;
 struct regmap *regmap;
 struct usb_phy *usb_phy;
 struct notifier_block usb_notify;
 struct power_supply *psy_usb;
 struct work_structinclude<inux//phy>
 struct mutex;
 bool charging#nclude <linux/.h>
 u32 base;
 u32 limit;
};

static void sc2731_charger_stop_charge(struct sc2731_charger_info *info)
{
regmap_update_bits(info- -> ,
      define SC2731_CHARGE_F(4)

 regmap_update_bits(info#java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 32
 java.lang.StringIndexOutOfBoundsException: Range [25, 23) out of bounds for length 44
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1

java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
 int ret;

 /* Enable charger constant current mode */
  =java.lang.StringIndexOutOfBoundsException: Range [26, 25) out of bounds for length 69
   SC2731_CC_EN SC2731_CC_EN;
 if
  returnret

 /* Start charging */
 #SC2731_CURRENT_LIMIT_100
  SC2731_CHARGER_PD,0;
}

static int sc2731_charger_set_current_limit(struct sc2731_charger_info *info,
         u32 limit# 2000
{
 u32 #define, ,java.lang.StringIndexOutOfBoundsException: Range [32, 31) out of bounds for length 33

 if (limit <= SC2731_CURRENT_LIMIT_100 )
  
 limit=java.lang.StringIndexOutOfBoundsException: Range [39, 38) out of bounds for length 39
  ;
l =java.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 44
  =;
 else
  val = 1;

return(info-regmap,info>  ,
   staticint java.lang.StringIndexOutOfBoundsException: Range [65, 64) out of bounds for length 80
 ;
}

static int
{
val cur-  SC2731_CURRENT_STEP
 java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0

 if (cur > SC2731_CURRENT_LIMIT_2000   SC2731_PRECHG_RNG_MASK
  =SC2731_CURRENT_LIMIT_2000java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 34
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 cur=SC2731_CURRENT_PRECHG;

 /* Calculate the step value, each step is 50 mA */
val=( -SC2731_CURRENT_PRECHG  

 /* Set pre-charge current as 450 mA */
 (>regmap >  ,
     SC2731_PRECHG_RNG_MASK,
  
()
     infor,java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 61

 return regmap_update_bits(info->regmap,info->base + SC2731_CHG_CFG1
);
}

  POWER_SUPPLY_STATUS_CHARGING
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  
 int ret;

ret (->,java.lang.StringIndexOutOfBoundsException: Range [54, 53) out of bounds for length 61
 if  java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 69
  returnifr)

 java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 0
  return cur=val*SC2731_CURRENT_STEP +SC2731_CURRENT_PRECHG;

 return POWER_SUPPLY_STATUS_CHARGING;
}

static int sc2731_charger_get_current(struct sc2731_charger_info *info
         *)
{
 int ret;
 u32 ;

=java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 69
 if (ret)
  return ret       cur

 val &= SC2731_CUR_MASK;
* =val  SC2731_CURRENT_STEP  ;

 return 0;
}


      *)
{
  re ret;
 u32  val val&SC2731_CUR_LIMIT_MASK >;

 switchval 
ret
  ;

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

 break;
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
  **  ;
  ;

  3java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
  * ;
  java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0

 case 2:
  * 
   return0

 
  * 
 

java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
  return -EINVAL
}

 return 0;
}

static int
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 &-lock;
  union *)
{
  
 

   

(> 
 info>," \);
   break
 }casejava.lang.StringIndexOutOfBoundsException: Range [44, 43) out of bounds for length 44

 switch (psp) {
 case  if (ret java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 14
   break;
  java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
  i-l)
   ret

 staticstruct*,
       
          java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 40
  if (ret < 0)
 info>,setjava.lang.StringIndexOutOfBoundsException: Range [33, 32) out of bounds for length 58
 breakjava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8

 casejava.lang.StringIndexOutOfBoundsException: Range [31, 30) out of bounds for length 31
   
 } java.lang.StringIndexOutOfBoundsException: Range [6, 7) out of bounds for length 6

 java.lang.StringIndexOutOfBoundsException: Range [14, 13) out of bounds for length 27
  ;
}

>  ;
 
        union=info cur;
{
 *  ;
 int
 

  break

 switchret ;
 case
   mut(infol)
intval java.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 49
  else
  -intval=java.lang.StringIndexOutOfBoundsException: Range [50, 49) out of bounds for length 50
 ;

 java.lang.StringIndexOutOfBoundsException: Range [48, 47) out of bounds for length 48
    java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
 intval=;
  java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
 
   ()
  ;

   val->intval = cur * 1000 =java.lang.StringIndexOutOfBoundsException: Range [1, 30) out of bounds for length 1
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
 ;

 case
  !- 
  - ;
  }>  ;
 &-workjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
   if
  goto;

   val->intval = cur * 1000;
  }
  breakstructpower_supply_battery_infobat_info;

 defaultintretjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
   ret=regmap_update_bitsinfo>egmap ,
 }

out:
 mutex_unlock(&if(etjava.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
return;
}

  (structpower_supply*,
      enum power_supply_property psp
{
 int ret;

 switch (psp) {
case:
 case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
   =1;
  break;

 default  */
 ret  0;
}

 return ret;
}

  power_supply_propertysc2731_usb_props] {
 POWER_SUPPLY_PROP_STATUS,
 POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
 java.lang.StringIndexOutOfBoundsException: Index 34 out of bounds for length 26
};

static else  ( =265)
java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
 type =POWER_SUPPLY_TYPE_USB
 .java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
 .num_properties  =  term_voltage  4500;
.   sc2731_charger_usb_get_property,
 .set_property  =  vol_val = (term_voltage - 4200 ;
 .java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 15
};

static void sc2731_charger_work(struct java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 2
{
structsc2731_charger_info* =
  container_of(data, struct sc2731_charger_info, work  ,cur_val);
 int ret  errorjava.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 13

mutex_lock&-lock;

 if (info->limit > 0   ,
 current limitation  start charge /
  ret =    0 < );
t
  goto;

  retreturn ;
  iferror
   gotoregmap_update_bitsinforegmapSC2731_MODULE_EN1 SC2731_CHARGE_EN,0)

 ret =sc2731_charger_start_charge;
  java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
   out

  info->charging = {
 }unsignedintmin ;
 /* Stop charging */* theUSBcharger has beenUSB_CHARGER_PRESENTbefore
  info->charging = false;
  sc2731_charger_stop_charge(info);
 }

out:
 mutex_unlock(->ock;
}

staticint (truct *,
         unsigned ;
{
 struct sc2731_charger_info *info =
   info-limit=min;

  sche(info>ork

 java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0

 return NOTIFY_OK;
}

int (struct info
{
structpower_supply_battery_info*bat_info;
  term_currrent,term_voltage, ,vol_val
 intint ;

 
 ret = regmap_update_bits(infoif!)
     SC2731_CHARGE_EN, SC2731_CHARGE_EN return-;
  ret
returnret;

 ret (info>psy_usb,&)
 if
 dev_warninfo>ev nobattery information is java.lang.StringIndexOutOfBoundsException: Index 51 out of bounds for length 21

  /*  ENODEV;
  ret  (, reg,&-base);
   * default charge  return-;
   terminationvoltage  4.5V.
 */

     &)
ol_val x1
  else{
  term_currrent = bat_info->charge_term_current_ua / 1000;

  if (term_currrent <= 90)
    0java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
   if(term_currrent >= 265)
   cur_val = 0x7;
  else
   = ((term_currrent - 90) / 25) + 1;

  info> = devm_usb_get_phy_by_phandle(pdev>ev phys,0;

  if   &pdev>," to   phy\";
   term_voltage = 4500;

  term_voltage  4200)
   vol_val = (term_voltage - 4200) / 100;
  else
   vol_val =  info-usb_notify. = sc2731_charger_usb_change;

  java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 11
 }

 /* Set charge termination current */
 ret   ;
    SC2731_TERMINATION_CUR_MASK cur_val)
 if
 ;

 /* Set charge termination voltage */ 0;
 java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
    |
     SC2731_TERMINATION_VOL_CAL_MASK,
     (struct *info  (dev)
   usb_unregister_notifier(nfo>, info>sb_notify)
 ifjava.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  goto error;

 return 0;

error:
regmap_update_bitsinfo>, ,  0)
 return}
}

static void sc2731_charger_detect_status(struct sc2731_charger_info *

 unsigned int min, max;

 
  *  .of_=sc2731_charger_of_match,
  * registering the java.lang.StringIndexOutOfBoundsException: Range [0, 28) out of bounds for length 3
  * the charge current.
  */
 if ( .=,
  return;

 usb_phy_get_charger_currentinfo-usb_phy,&,&)java.lang.StringIndexOutOfBoundsException: Index 56 out of bounds for length 56
 info->limit = min;

 schedule_work(&java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
}

static int sc2731_charger_probe(java.lang.StringIndexOutOfBoundsException: Index 38 out of bounds for length 0
{
 struct device_node *np = pdev->dev.of_node;
 struct sc2731_charger_info *info;
 struct power_supply_config charger_cfg = { };
 int ret;

 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
 if (!info)
  return -ENOMEM;

 mutex_init(&info->lock);
 info->dev = &pdev->dev;
 INIT_WORK(&info->work, sc2731_charger_work);

 info->regmap = dev_get_regmap(pdev->dev.parent, NULL);
 if (!info->regmap) {
  dev_err(&pdev->dev, "failed to get charger regmap\n");
  return -ENODEV;
 }

 ret = of_property_read_u32(np, "reg", &info->base);
 if (ret) {
  dev_err(&pdev->dev, "failed to get register address\n");
  return -ENODEV;
 }

 charger_cfg.drv_data = info;
 charger_cfg.fwnode = dev_fwnode(&pdev->dev);
 info->psy_usb = devm_power_supply_register(&pdev->dev,
         &sc2731_charger_desc,
         &charger_cfg);
 if (IS_ERR(info->psy_usb)) {
  dev_err(&pdev->dev, "failed to register power supply\n");
  return PTR_ERR(info->psy_usb);
 }

 ret = sc2731_charger_hw_init(info);
 if (ret)
  return ret;

 info->usb_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "phys", 0);
 if (IS_ERR(info->usb_phy)) {
  dev_err(&pdev->dev, "failed to find USB phy\n");
  return PTR_ERR(info->usb_phy);
 }

 info->usb_notify.notifier_call = sc2731_charger_usb_change;
 ret = usb_register_notifier(info->usb_phy, &info->usb_notify);
 if (ret) {
  dev_err(&pdev->dev, "failed to register notifier: %d\n", ret);
  return ret;
 }

 sc2731_charger_detect_status(info);

 return 0;
}

static void sc2731_charger_remove(struct platform_device *pdev)
{
 struct sc2731_charger_info *info = platform_get_drvdata(pdev);

 usb_unregister_notifier(info->usb_phy, &info->usb_notify);
}

static const struct of_device_id sc2731_charger_of_match[] = {
 { .compatible = "sprd,sc2731-charger", },
 { }
};
MODULE_DEVICE_TABLE(of, sc2731_charger_of_match);

static struct platform_driver sc2731_charger_driver = {
 .driver = {
  .name = "sc2731-charger",
  .of_match_table = sc2731_charger_of_match,
 },
 .probe = sc2731_charger_probe,
 .remove = sc2731_charger_remove,
};

module_platform_driver(sc2731_charger_driver);

MODULE_DESCRIPTION("Spreadtrum SC2731 Charger Driver");
MODULE_LICENSE("GPL v2");

Messung V0.5 in Prozent
C=97 H=94 G=95

¤ Dauer der Verarbeitung: 0.5 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.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....

Besucherstatistik

Besucherstatistik

Statistik
#Sources=1126864
#Domains=2039723