Op 08-10-2024 om 22:59 schreef Kees Bakker:
Op 01-10-2024 om 11:16 schreef Jack Yu:
This is the first version of common functions for Realtek soundwire codec driver.
Signed-off-by: Jack Yu jack.yu@realtek.com
sound/soc/codecs/Kconfig | 5 + sound/soc/codecs/Makefile | 2 + sound/soc/codecs/rt-sdw-common.c | 238 +++++++++++++++++++++++++++++++ sound/soc/codecs/rt-sdw-common.h | 66 +++++++++ 4 files changed, 311 insertions(+) create mode 100644 sound/soc/codecs/rt-sdw-common.c create mode 100644 sound/soc/codecs/rt-sdw-common.h
[...] +/**
- rt_sdca_headset_detect - Headset jack type detection.
- @map: map for setting.
- @entity_id: SDCA entity ID.
- A headset jack type will be returned, a negative errno will
- be returned in error cases.
- */
+int rt_sdca_headset_detect(struct regmap *map, unsigned int entity_id) +{ + unsigned int det_mode, jack_type; + int ret;
+ /* get detected_mode */ + ret = regmap_read(map, SDW_SDCA_CTL(SDCA_NUM_JACK_CODEC, entity_id, + RT_SDCA_CTL_DETECTED_MODE, 0), &det_mode);
+ if (ret < 0) + goto io_error;
+ switch (det_mode) { + case 0x00: + jack_type = 0; + break; + case 0x03: + jack_type = SND_JACK_HEADPHONE; + break; + case 0x05: + jack_type = SND_JACK_HEADSET; + break;
There is no default case. So, variable jack_type can remain uninitialized and then used for the return value. Perhaps you can combine "case 0x00" with "default".
+ }
+ /* write selected_mode */ + if (det_mode) { + ret = regmap_write(map, SDW_SDCA_CTL(SDCA_NUM_JACK_CODEC, entity_id, + RT_SDCA_CTL_SELECTED_MODE, 0), det_mode); + if (ret < 0) + goto io_error; + }
+ return jack_type;
Please have a look at my comment again. If regmap_read returns a `det_mode` not 0, 3 or 5 then the function will return jack_type with an uninitialzed value.