mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 07:45:16 +08:00
drivers/power/mcp73871.c: Fix MCP73871 driver to return a battery_charger_dev_s
drivers/power/bq2425x.c: The Battery Charger expects a battery_charger_dev_s not battery_charger_operations_s drivers/power/bq2429x.c: The Battery Charger expects a battery_charger_dev_s not battery_charger_operations_s
This commit is contained in:
committed by
Gregory Nutt
parent
3de2533599
commit
11881f8fc6
+49
-33
@@ -99,7 +99,7 @@ struct bq2425x_dev_s
|
|||||||
{
|
{
|
||||||
/* The common part of the battery driver visible to the upper-half driver */
|
/* The common part of the battery driver visible to the upper-half driver */
|
||||||
|
|
||||||
FAR const struct battery_charger_operations_s *ops; /* Battery operations */
|
FAR const struct battery_charger_dev_s *dev; /* Battery device */
|
||||||
sem_t batsem; /* Enforce mutually exclusive access */
|
sem_t batsem; /* Enforce mutually exclusive access */
|
||||||
|
|
||||||
/* Data fields specific to the lower half BQ2425x driver follow */
|
/* Data fields specific to the lower half BQ2425x driver follow */
|
||||||
@@ -781,48 +781,64 @@ FAR struct battery_charger_dev_s *
|
|||||||
FAR struct bq2425x_dev_s *priv;
|
FAR struct bq2425x_dev_s *priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Initialize the BQ2425x device structure */
|
/* Allocate the BQ2425x device structure */
|
||||||
|
|
||||||
priv = (FAR struct bq2425x_dev_s *)kmm_zalloc(sizeof(struct bq2425x_dev_s));
|
priv = (FAR struct bq2425x_dev_s *)kmm_zalloc(sizeof(struct bq2425x_dev_s));
|
||||||
if (priv)
|
if (priv == NULL)
|
||||||
{
|
{
|
||||||
/* Initialize the BQ2425x device structure */
|
baterr("ERROR: Failed to allocate memory for bq2425x_dev_s!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
nxsem_init(&priv->batsem, 0, 1);
|
priv->dev = (FAR struct battery_charger_dev_s *)
|
||||||
priv->ops = &g_bq2425xops;
|
kmm_zalloc(sizeof(struct battery_charger_dev_s));
|
||||||
priv->i2c = i2c;
|
|
||||||
priv->addr = addr;
|
|
||||||
priv->frequency = frequency;
|
|
||||||
|
|
||||||
/* Reset the BQ2425x */
|
if (priv->dev == NULL)
|
||||||
|
{
|
||||||
|
baterr("ERROR: Failed to allocate memory for battery_charger_dev_s!\n");
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ret = bq2425x_reset(priv);
|
/* Initialize the BQ2425x device structure */
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
baterr("ERROR: Failed to reset the BQ2425x: %d\n", ret);
|
|
||||||
kmm_free(priv);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable watchdog otherwise BQ2425x returns to StandAlone mode */
|
nxsem_init(&priv->batsem, 0, 1);
|
||||||
|
priv->dev->ops = &g_bq2425xops;
|
||||||
|
priv->i2c = i2c;
|
||||||
|
priv->addr = addr;
|
||||||
|
priv->frequency = frequency;
|
||||||
|
|
||||||
ret = bq2425x_watchdog(priv, false);
|
/* Reset the BQ2425x */
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
baterr("ERROR: Failed to disable BQ2425x watchdog: %d\n", ret);
|
|
||||||
kmm_free(priv);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Define the current that our power supply can offer to the charger. */
|
ret = bq2425x_reset(priv);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
baterr("ERROR: Failed to reset the BQ2425x: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
ret = bq2425x_powersupply(priv, current);
|
/* Disable watchdog otherwise BQ2425x returns to StandAlone mode */
|
||||||
if (ret < 0)
|
|
||||||
{
|
ret = bq2425x_watchdog(priv, false);
|
||||||
baterr("ERROR: Failed to set BQ2425x power supply input limit: %d\n", ret);
|
if (ret < 0)
|
||||||
kmm_free(priv);
|
{
|
||||||
return NULL;
|
baterr("ERROR: Failed to disable BQ2425x watchdog: %d\n", ret);
|
||||||
}
|
kmm_free(priv->dev);
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Define the current that our power supply can offer to the charger. */
|
||||||
|
|
||||||
|
ret = bq2425x_powersupply(priv, current);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
baterr("ERROR: Failed to set BQ2425x power supply input limit: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (FAR struct battery_charger_dev_s *)priv;
|
return (FAR struct battery_charger_dev_s *)priv;
|
||||||
|
|||||||
+57
-41
@@ -122,7 +122,7 @@ struct bq2429x_dev_s
|
|||||||
{
|
{
|
||||||
/* The common part of the battery driver visible to the upper-half driver */
|
/* The common part of the battery driver visible to the upper-half driver */
|
||||||
|
|
||||||
FAR const struct battery_charger_operations_s *ops; /* Battery operations */
|
FAR const struct battery_charger_dev_s *dev; /* Battery device */
|
||||||
sem_t batsem; /* Enforce mutually exclusive access */
|
sem_t batsem; /* Enforce mutually exclusive access */
|
||||||
|
|
||||||
/* Data fields specific to the lower half BQ2429X driver follow */
|
/* Data fields specific to the lower half BQ2429X driver follow */
|
||||||
@@ -1251,58 +1251,74 @@ FAR struct battery_charger_dev_s *
|
|||||||
FAR struct bq2429x_dev_s *priv;
|
FAR struct bq2429x_dev_s *priv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Initialize the BQ2429x device structure */
|
/* Allocate the BQ2429x device structure */
|
||||||
|
|
||||||
priv = (FAR struct bq2429x_dev_s *)kmm_zalloc(sizeof(struct bq2429x_dev_s));
|
priv = (FAR struct bq2429x_dev_s *)kmm_zalloc(sizeof(struct bq2429x_dev_s));
|
||||||
if (priv)
|
if (priv == NULL)
|
||||||
{
|
{
|
||||||
/* Initialize the BQ2429x device structure */
|
baterr("ERROR: Failed to allocate memory for bq2429x_dev_s!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
nxsem_init(&priv->batsem, 0, 1);
|
priv->dev = (FAR struct battery_charger_dev_s *)
|
||||||
priv->ops = &g_bq2429xops;
|
kmm_zalloc(sizeof(struct battery_charger_dev_s));
|
||||||
priv->i2c = i2c;
|
if (priv->dev == NULL)
|
||||||
priv->addr = addr;
|
{
|
||||||
priv->frequency = frequency;
|
baterr("ERROR: Failed to allocate memory for battery_charger_dev_s!\n");
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Reset the BQ2429x */
|
/* Initialize the BQ2429x device structure */
|
||||||
|
|
||||||
ret = bq2429x_reset(priv);
|
nxsem_init(&priv->batsem, 0, 1);
|
||||||
if (ret < 0)
|
priv->dev->ops = &g_bq2429xops;
|
||||||
{
|
priv->i2c = i2c;
|
||||||
baterr("ERROR: Failed to reset the BQ2429x: %d\n", ret);
|
priv->addr = addr;
|
||||||
kmm_free(priv);
|
priv->frequency = frequency;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Disable watchdog otherwise BQ2429x returns to StandAlone mode */
|
/* Reset the BQ2429x */
|
||||||
|
|
||||||
ret = bq2429x_watchdog(priv, false);
|
ret = bq2429x_reset(priv);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to disable BQ2429x watchdog: %d\n", ret);
|
baterr("ERROR: Failed to reset the BQ2429x: %d\n", ret);
|
||||||
kmm_free(priv);
|
kmm_free(priv->dev);
|
||||||
return NULL;
|
kmm_free(priv);
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Define the current that our power supply can offer to the charger. */
|
/* Disable watchdog otherwise BQ2429x returns to StandAlone mode */
|
||||||
|
|
||||||
ret = bq2429x_powersupply(priv, current);
|
ret = bq2429x_watchdog(priv, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to set BQ2429x power supply input limit: %d\n", ret);
|
baterr("ERROR: Failed to disable BQ2429x watchdog: %d\n", ret);
|
||||||
kmm_free(priv);
|
kmm_free(priv->dev);
|
||||||
return NULL;
|
kmm_free(priv);
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Disable all interrupts. */
|
/* Define the current that our power supply can offer to the charger. */
|
||||||
|
|
||||||
ret = bq2429x_en_stat(priv, false);
|
ret = bq2429x_powersupply(priv, current);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to disable BQ2429x interrupts: %d\n", ret);
|
baterr("ERROR: Failed to set BQ2429x power supply input limit: %d\n", ret);
|
||||||
kmm_free(priv);
|
kmm_free(priv->dev);
|
||||||
return NULL;
|
kmm_free(priv);
|
||||||
}
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Disable all interrupts. */
|
||||||
|
|
||||||
|
ret = bq2429x_en_stat(priv, false);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
baterr("ERROR: Failed to disable BQ2429x interrupts: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (FAR struct battery_charger_dev_s *)priv;
|
return (FAR struct battery_charger_dev_s *)priv;
|
||||||
|
|||||||
+29
-17
@@ -93,13 +93,14 @@
|
|||||||
|
|
||||||
struct mcp73871_dev_s
|
struct mcp73871_dev_s
|
||||||
{
|
{
|
||||||
|
/* The common part of the battery driver visible to the upper-half driver */
|
||||||
|
|
||||||
|
FAR struct battery_charger_dev_s *dev;
|
||||||
|
|
||||||
/* MCP73871 configuration helpers */
|
/* MCP73871 configuration helpers */
|
||||||
|
|
||||||
FAR struct mcp73871_config_s *config;
|
FAR struct mcp73871_config_s *config;
|
||||||
|
|
||||||
/* The common part of the battery driver visible to the upper-half driver */
|
|
||||||
|
|
||||||
FAR const struct battery_charger_operations_s *ops; /* Battery operations */
|
|
||||||
sem_t batsem; /* Enforce mutually exclusive access */
|
sem_t batsem; /* Enforce mutually exclusive access */
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -399,24 +400,35 @@ FAR struct battery_charger_dev_s *
|
|||||||
{
|
{
|
||||||
FAR struct mcp73871_dev_s *priv;
|
FAR struct mcp73871_dev_s *priv;
|
||||||
|
|
||||||
/* Initialize the BQ2425x device structure */
|
/* Allocate the MCP73871 device structure */
|
||||||
|
|
||||||
priv = (FAR struct mcp73871_dev_s *)
|
priv = (FAR struct mcp73871_dev_s *)kmm_zalloc(sizeof(struct mcp73871_dev_s));
|
||||||
kmm_zalloc(sizeof(struct mcp73871_dev_s));
|
if (priv == NULL)
|
||||||
|
|
||||||
if (priv)
|
|
||||||
{
|
{
|
||||||
/* Initialize the BQ2425x device structure */
|
baterr("Error: Failed to allocate memory for mcp73871_dev_s!\n");
|
||||||
|
return NULL;
|
||||||
nxsem_init(&priv->batsem, 0, 1);
|
|
||||||
priv->ops = &g_mcp73871ops;
|
|
||||||
priv->config = config;
|
|
||||||
|
|
||||||
/* Enable the battery charge */
|
|
||||||
|
|
||||||
priv->config->set_chg_ce(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
priv->dev = (FAR struct battery_charger_dev_s *)
|
||||||
|
kmm_zalloc(sizeof(struct battery_charger_dev_s));
|
||||||
|
|
||||||
|
if (priv->dev == NULL)
|
||||||
|
{
|
||||||
|
batterr("Error: Failed to allocate memory for battery_charger_dev_s!\n");
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize the MCP73871 device structure */
|
||||||
|
|
||||||
|
nxsem_init(&priv->batsem, 0, 1);
|
||||||
|
priv->config = config;
|
||||||
|
priv->dev->ops = &g_mcp73871ops;
|
||||||
|
|
||||||
|
/* Enable the battery charge */
|
||||||
|
|
||||||
|
priv->config->set_chg_ce(true);
|
||||||
|
|
||||||
return (FAR struct battery_charger_dev_s *)priv;
|
return (FAR struct battery_charger_dev_s *)priv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user