Skip to content

Commit

Permalink
ASoC: SDCA: Add support for PDE Entity properties
Browse files Browse the repository at this point in the history
Add support for parsing the Power Domain Entity properties from
DisCo/ACPI.

Signed-off-by: Charles Keepax <[email protected]>
  • Loading branch information
charleskeepax committed Jan 20, 2025
1 parent 3f11e30 commit ad1cf56
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
30 changes: 30 additions & 0 deletions include/sound/sdca_function.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,34 @@ struct sdca_entity_cs {
unsigned int max_delay;
};

/**
* struct sdca_pde_delay - describes the delay changing between 2 power states
* @from_ps: The power state being exited.
* @to_ps: The power state being entered.
* @us: The delay in microseconds switching between the two states.
*/
struct sdca_pde_delay {
int from_ps;
int to_ps;
int us;
};

/**
* struct sdca_entity_pde - information specific to Power Domain Entities
* @managed: Dynamically allocated array pointing to each Entity
* controlled by this PDE.
* @max_delay: Dynamically allocated array of delays for switching
* between power states.
* @num_managed: Number of Entities controlled by this PDE.
* @num_max_delay: Number of delays specified for state changes.
*/
struct sdca_entity_pde {
struct sdca_entity **managed;
struct sdca_pde_delay *max_delay;
int num_managed;
int num_max_delay;
};

/**
* enum sdca_entity_type - SDCA Entity Type codes
* @SDCA_ENTITY_TYPE_ENTITY_0: Entity 0, not actually from the
Expand Down Expand Up @@ -838,6 +866,7 @@ enum sdca_entity_type {
* @num_controls: Number of Controls for the Entity.
* @iot: Input/Output Terminal specific Entity properties.
* @cs: Clock Source specific Entity properties.
* @pde: Power Domain Entity specific Entity properties.
*/
struct sdca_entity {
const char *label;
Expand All @@ -851,6 +880,7 @@ struct sdca_entity {
union {
struct sdca_entity_iot iot;
struct sdca_entity_cs cs;
struct sdca_entity_pde pde;
};
};

Expand Down
141 changes: 141 additions & 0 deletions sound/soc/sdca/sdca_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@
*/
#define SDCA_MAX_CHANNEL_COUNT 32

/*
* Sanity check on number of PDE delays, can be expanded if needed.
*/
#define SDCA_MAX_DELAY_COUNT 256

static int patch_sdca_function_type(u32 interface_revision, u32 *function_type)
{
/*
Expand Down Expand Up @@ -903,6 +908,64 @@ static int find_sdca_entity_cs(struct device *dev,
return 0;
}

static int find_sdca_entity_pde(struct device *dev,
struct fwnode_handle *entity_node,
struct sdca_entity *entity)
{
static int const mult_delay = 3;
struct sdca_entity_pde *power = &entity->pde;
struct sdca_pde_delay *delays;
int num_delays;
u32 *delay_list;
int i;

num_delays = fwnode_property_count_u32(entity_node,
"mipi-sdca-powerdomain-transition-max-delay");
if (num_delays <= 0) {
dev_err(dev, "%s: max delay list missing: %d\n",
entity->label, num_delays);
return -EINVAL;
} else if (num_delays % mult_delay != 0) {
dev_err(dev, "%s: delays not multiple of %d\n",
entity->label, mult_delay);
return -EINVAL;
} else if (num_delays > SDCA_MAX_DELAY_COUNT) {
dev_err(dev, "%s: maximum number of transition delays exceeded\n",
entity->label);
return -EINVAL;
}

/* There are 3 values per delay */
delays = devm_kcalloc(dev, num_delays / mult_delay,
sizeof(*delays), GFP_KERNEL);
if (!delays)
return -ENOMEM;

delay_list = kcalloc(num_delays, sizeof(*delay_list), GFP_KERNEL);
if (!delay_list)
return -ENOMEM;

fwnode_property_read_u32_array(entity_node,
"mipi-sdca-powerdomain-transition-max-delay",
delay_list, num_delays);

for (i = 0; i < num_delays;) {
delays->from_ps = delay_list[i++];
delays->to_ps = delay_list[i++];
delays->us = delay_list[i++];

dev_info(dev, "%s: from %#x to %#x delay %dus\n", entity->label,
delays->from_ps, delays->to_ps, delays->us);
}

kfree(delay_list);

power->num_max_delay = num_delays / mult_delay;
power->max_delay = delays;

return 0;
}

static int find_sdca_entity(struct device *dev,
struct fwnode_handle *function_node,
struct fwnode_handle *entity_node,
Expand Down Expand Up @@ -938,6 +1001,9 @@ static int find_sdca_entity(struct device *dev,
case SDCA_ENTITY_TYPE_CS:
ret = find_sdca_entity_cs(dev, entity_node, entity);
break;
case SDCA_ENTITY_TYPE_PDE:
ret = find_sdca_entity_pde(dev, entity_node, entity);
break;
default:
break;
}
Expand Down Expand Up @@ -1042,6 +1108,21 @@ static struct sdca_entity *find_sdca_entity_by_label(struct sdca_function_data *
return NULL;
}

static struct sdca_entity *find_sdca_entity_by_id(struct sdca_function_data *function,
const int id)
{
int i;

for (i = 0; i < function->num_entities; i++) {
struct sdca_entity *entity = &function->entities[i];

if (entity->id == id)
return entity;
}

return NULL;
}

static int find_sdca_entity_connection_iot(struct device *dev,
struct sdca_function_data *function,
struct fwnode_handle *entity_node,
Expand Down Expand Up @@ -1082,6 +1163,62 @@ static int find_sdca_entity_connection_iot(struct device *dev,
return 0;
}

static int find_sdca_entity_connection_pde(struct device *dev,
struct sdca_function_data *function,
struct fwnode_handle *entity_node,
struct sdca_entity *entity)
{
struct sdca_entity_pde *power = &entity->pde;
struct sdca_entity **managed;
u32 *managed_list;
int num_managed;
int i;

num_managed = fwnode_property_count_u32(entity_node,
"mipi-sdca-powerdomain-managed-list");
if (!num_managed) {
return 0;
} else if (num_managed < 0) {
dev_err(dev, "%s: managed list missing: %d\n", entity->label, num_managed);
return num_managed;
} else if (num_managed > SDCA_MAX_ENTITY_COUNT) {
dev_err(dev, "%s: maximum number of managed entities exceeded\n",
entity->label);
return -EINVAL;
}

managed = devm_kcalloc(dev, num_managed, sizeof(*managed), GFP_KERNEL);
if (!managed)
return -ENOMEM;

managed_list = kcalloc(num_managed, sizeof(*managed_list), GFP_KERNEL);
if (!managed_list)
return -ENOMEM;

fwnode_property_read_u32_array(entity_node,
"mipi-sdca-powerdomain-managed-list",
managed_list, num_managed);

for (i = 0; i < num_managed; i++) {
managed[i] = find_sdca_entity_by_id(function, managed_list[i]);
if (!managed[i]) {
dev_err(dev, "%s: failed to find entity with id %#x\n",
entity->label, managed_list[i]);
kfree(managed_list);
return -EINVAL;
}

dev_info(dev, "%s -> %s\n", managed[i]->label, entity->label);
}

kfree(managed_list);

power->num_managed = num_managed;
power->managed = managed;

return 0;
}

static int find_sdca_entity_connection(struct device *dev,
struct sdca_function_data *function,
struct fwnode_handle *entity_node,
Expand All @@ -1098,6 +1235,10 @@ static int find_sdca_entity_connection(struct device *dev,
ret = find_sdca_entity_connection_iot(dev, function,
entity_node, entity);
break;
case SDCA_ENTITY_TYPE_PDE:
ret = find_sdca_entity_connection_pde(dev, function,
entity_node, entity);
break;
default:
ret = 0;
break;
Expand Down

0 comments on commit ad1cf56

Please sign in to comment.