| 1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 |
/* |
| 3 |
* HD audio Component Binding Interface |
| 4 |
* |
| 5 |
* Copyright (C) 2021 Cirrus Logic, Inc. and |
| 6 |
* Cirrus Logic International Semiconductor Ltd. |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __HDA_COMPONENT_H__ |
| 10 |
#define __HDA_COMPONENT_H__ |
| 11 |
|
| 12 |
#include <linux/acpi.h> |
| 13 |
#include <linux/component.h> |
| 14 |
#include <linux/mutex.h> |
| 15 |
#include <sound/hda_codec.h> |
| 16 |
|
| 17 |
#define HDA_MAX_COMPONENTS 4 |
| 18 |
#define HDA_MAX_NAME_SIZE 50 |
| 19 |
|
| 20 |
struct hda_component { |
| 21 |
struct device *dev; |
| 22 |
char name[HDA_MAX_NAME_SIZE]; |
| 23 |
struct acpi_device *adev; |
| 24 |
bool acpi_notifications_supported; |
| 25 |
void (*acpi_notify)(acpi_handle handle, u32 event, struct device *dev); |
| 26 |
void (*pre_playback_hook)(struct device *dev, int action); |
| 27 |
void (*playback_hook)(struct device *dev, int action); |
| 28 |
void (*post_playback_hook)(struct device *dev, int action); |
| 29 |
}; |
| 30 |
|
| 31 |
struct hda_component_parent { |
| 32 |
struct mutex mutex; |
| 33 |
struct hda_codec *codec; |
| 34 |
struct hda_component comps[HDA_MAX_COMPONENTS]; |
| 35 |
}; |
| 36 |
|
| 37 |
#ifdef CONFIG_ACPI |
| 38 |
void hda_component_acpi_device_notify(struct hda_component_parent *parent, |
| 39 |
acpi_handle handle, u32 event, void *data); |
| 40 |
int hda_component_manager_bind_acpi_notifications(struct hda_codec *cdc, |
| 41 |
struct hda_component_parent *parent, |
| 42 |
acpi_notify_handler handler, void *data); |
| 43 |
void hda_component_manager_unbind_acpi_notifications(struct hda_codec *cdc, |
| 44 |
struct hda_component_parent *parent, |
| 45 |
acpi_notify_handler handler); |
| 46 |
#else |
| 47 |
static inline void hda_component_acpi_device_notify(struct hda_component_parent *parent, |
| 48 |
acpi_handle handle, |
| 49 |
u32 event, |
| 50 |
void *data) |
| 51 |
{ |
| 52 |
} |
| 53 |
|
| 54 |
static inline int hda_component_manager_bind_acpi_notifications(struct hda_codec *cdc, |
| 55 |
struct hda_component_parent *parent, |
| 56 |
acpi_notify_handler handler, |
| 57 |
void *data) |
| 58 |
|
| 59 |
{ |
| 60 |
return 0; |
| 61 |
} |
| 62 |
|
| 63 |
static inline void hda_component_manager_unbind_acpi_notifications(struct hda_codec *cdc, |
| 64 |
struct hda_component_parent *parent, |
| 65 |
acpi_notify_handler handler) |
| 66 |
{ |
| 67 |
} |
| 68 |
#endif /* ifdef CONFIG_ACPI */ |
| 69 |
|
| 70 |
void hda_component_manager_playback_hook(struct hda_component_parent *parent, int action); |
| 71 |
|
| 72 |
int hda_component_manager_init(struct hda_codec *cdc, |
| 73 |
struct hda_component_parent *parent, int count, |
| 74 |
const char *bus, const char *hid, |
| 75 |
const char *match_str, |
| 76 |
const struct component_master_ops *ops); |
| 77 |
|
| 78 |
void hda_component_manager_free(struct hda_component_parent *parent, |
| 79 |
const struct component_master_ops *ops); |
| 80 |
|
| 81 |
int hda_component_manager_bind(struct hda_codec *cdc, struct hda_component_parent *parent); |
| 82 |
|
| 83 |
static inline struct hda_component *hda_component_from_index(struct hda_component_parent *parent, |
| 84 |
int index) |
| 85 |
{ |
| 86 |
if (!parent) |
| 87 |
return NULL; |
| 88 |
|
| 89 |
if (index < 0 || index >= ARRAY_SIZE(parent->comps)) |
| 90 |
return NULL; |
| 91 |
|
| 92 |
return &parent->comps[index]; |
| 93 |
} |
| 94 |
|
| 95 |
static inline void hda_component_manager_unbind(struct hda_codec *cdc, |
| 96 |
struct hda_component_parent *parent) |
| 97 |
{ |
| 98 |
guard(mutex)(&parent->mutex); |
| 99 |
component_unbind_all(hda_codec_dev(cdc), parent); |
| 100 |
} |
| 101 |
|
| 102 |
#endif /* ifndef __HDA_COMPONENT_H__ */ |