mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +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
+21
-5
@@ -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,15 +781,29 @@ 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)
|
||||||
{
|
{
|
||||||
|
baterr("ERROR: Failed to allocate memory for bq2425x_dev_s!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->dev = (FAR struct battery_charger_dev_s *)
|
||||||
|
kmm_zalloc(sizeof(struct battery_charger_dev_s));
|
||||||
|
|
||||||
|
if (priv->dev == NULL)
|
||||||
|
{
|
||||||
|
baterr("ERROR: Failed to allocate memory for battery_charger_dev_s!\n");
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the BQ2425x device structure */
|
/* Initialize the BQ2425x device structure */
|
||||||
|
|
||||||
nxsem_init(&priv->batsem, 0, 1);
|
nxsem_init(&priv->batsem, 0, 1);
|
||||||
priv->ops = &g_bq2425xops;
|
priv->dev->ops = &g_bq2425xops;
|
||||||
priv->i2c = i2c;
|
priv->i2c = i2c;
|
||||||
priv->addr = addr;
|
priv->addr = addr;
|
||||||
priv->frequency = frequency;
|
priv->frequency = frequency;
|
||||||
@@ -800,6 +814,7 @@ FAR struct battery_charger_dev_s *
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to reset the BQ2425x: %d\n", ret);
|
baterr("ERROR: Failed to reset the BQ2425x: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -810,6 +825,7 @@ FAR struct battery_charger_dev_s *
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to disable BQ2425x watchdog: %d\n", ret);
|
baterr("ERROR: Failed to disable BQ2425x watchdog: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -820,10 +836,10 @@ FAR struct battery_charger_dev_s *
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to set BQ2425x power supply input limit: %d\n", ret);
|
baterr("ERROR: Failed to set BQ2425x power supply input limit: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (FAR struct battery_charger_dev_s *)priv;
|
return (FAR struct battery_charger_dev_s *)priv;
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-5
@@ -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,15 +1251,28 @@ 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)
|
||||||
{
|
{
|
||||||
|
baterr("ERROR: Failed to allocate memory for bq2429x_dev_s!\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->dev = (FAR struct battery_charger_dev_s *)
|
||||||
|
kmm_zalloc(sizeof(struct battery_charger_dev_s));
|
||||||
|
if (priv->dev == NULL)
|
||||||
|
{
|
||||||
|
baterr("ERROR: Failed to allocate memory for battery_charger_dev_s!\n");
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the BQ2429x device structure */
|
/* Initialize the BQ2429x device structure */
|
||||||
|
|
||||||
nxsem_init(&priv->batsem, 0, 1);
|
nxsem_init(&priv->batsem, 0, 1);
|
||||||
priv->ops = &g_bq2429xops;
|
priv->dev->ops = &g_bq2429xops;
|
||||||
priv->i2c = i2c;
|
priv->i2c = i2c;
|
||||||
priv->addr = addr;
|
priv->addr = addr;
|
||||||
priv->frequency = frequency;
|
priv->frequency = frequency;
|
||||||
@@ -1270,6 +1283,7 @@ FAR struct battery_charger_dev_s *
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to reset the BQ2429x: %d\n", ret);
|
baterr("ERROR: Failed to reset the BQ2429x: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1280,6 +1294,7 @@ FAR struct battery_charger_dev_s *
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to disable BQ2429x watchdog: %d\n", ret);
|
baterr("ERROR: Failed to disable BQ2429x watchdog: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1290,6 +1305,7 @@ FAR struct battery_charger_dev_s *
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to set BQ2429x power supply input limit: %d\n", ret);
|
baterr("ERROR: Failed to set BQ2429x power supply input limit: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -1300,10 +1316,10 @@ FAR struct battery_charger_dev_s *
|
|||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
baterr("ERROR: Failed to disable BQ2429x interrupts: %d\n", ret);
|
baterr("ERROR: Failed to disable BQ2429x interrupts: %d\n", ret);
|
||||||
|
kmm_free(priv->dev);
|
||||||
kmm_free(priv);
|
kmm_free(priv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return (FAR struct battery_charger_dev_s *)priv;
|
return (FAR struct battery_charger_dev_s *)priv;
|
||||||
}
|
}
|
||||||
|
|||||||
+23
-11
@@ -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,23 +400,34 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
nxsem_init(&priv->batsem, 0, 1);
|
||||||
priv->ops = &g_mcp73871ops;
|
|
||||||
priv->config = config;
|
priv->config = config;
|
||||||
|
priv->dev->ops = &g_mcp73871ops;
|
||||||
|
|
||||||
/* Enable the battery charge */
|
/* Enable the battery charge */
|
||||||
|
|
||||||
priv->config->set_chg_ce(true);
|
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