@@ -1635,7 +1635,6 @@ config MFD_WM97xx
select AC97_BUS_COMPAT
depends on AC97_BUS_NEW
help
-
The WM9705, WM9712 and WM9713 is a highly integrated hi-fi CODEC
designed for smartphone applications. As well as audio functionality
it has on board GPIO and a touchscreen functionality which is
@@ -1,7 +1,7 @@
/*
* Wolfson WM97xx -- Core device
*
- * Copyright (C) 2016 Robert Jarzmik
+ * Copyright (C) 2017 Robert Jarzmik
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -14,14 +14,13 @@
* - a GPIO block
*/
-#include <linux/module.h>
-
#include <linux/device.h>
#include <linux/mfd/core.h>
#include <linux/mfd/wm97xx.h>
-#include <linux/wm97xx.h>
+#include <linux/module.h>
#include <linux/regmap.h>
#include <linux/slab.h>
+#include <linux/wm97xx.h>
#include <sound/ac97/codec.h>
#include <sound/ac97/compat.h>
@@ -34,6 +33,7 @@ struct wm97xx_priv {
struct regmap *regmap;
struct snd_ac97 *ac97;
struct device *dev;
+ struct wm97xx_platform_data codec_pdata;
};
static bool wm97xx_readable_reg(struct device *dev, unsigned int reg)
@@ -108,33 +108,14 @@ static const struct regmap_config wm9705_regmap_config = {
.writeable_reg = wm97xx_writeable_reg,
};
-static int wm9705_register(struct wm97xx_priv *wm97xx,
- struct wm97xx_pdata *pdata)
-{
- static struct wm97xx_platform_data codec_pdata;
- static const struct mfd_cell cells[] = {
- {
- .name = "wm9705-codec",
- .platform_data = &codec_pdata,
- .pdata_size = sizeof(codec_pdata),
- },
- {
- .name = "wm97xx-ts",
- .platform_data = &codec_pdata,
- .pdata_size = sizeof(codec_pdata),
- },
- };
-
- codec_pdata.ac97 = wm97xx->ac97;
- codec_pdata.regmap = devm_regmap_init_ac97(wm97xx->ac97,
- &wm9705_regmap_config);
- codec_pdata.batt_pdata = pdata->batt_pdata;
- if (IS_ERR(codec_pdata.regmap))
- return PTR_ERR(codec_pdata.regmap);
-
- return devm_mfd_add_devices(wm97xx->dev, PLATFORM_DEVID_NONE, cells,
- ARRAY_SIZE(cells), NULL, 0, NULL);
-}
+static struct mfd_cell wm9705_cells[] = {
+ {
+ .name = "wm9705-codec",
+ },
+ {
+ .name = "wm97xx-ts",
+ },
+};
static bool wm9712_volatile_reg(struct device *dev, unsigned int reg)
{
@@ -199,33 +180,14 @@ static const struct regmap_config wm9712_regmap_config = {
.writeable_reg = wm97xx_writeable_reg,
};
-static int wm9712_register(struct wm97xx_priv *wm97xx,
- struct wm97xx_pdata *pdata)
-{
- static struct wm97xx_platform_data codec_pdata;
- static const struct mfd_cell cells[] = {
- {
- .name = "wm9712-codec",
- .platform_data = &codec_pdata,
- .pdata_size = sizeof(codec_pdata),
- },
- {
- .name = "wm97xx-ts",
- .platform_data = &codec_pdata,
- .pdata_size = sizeof(codec_pdata),
- },
- };
-
- codec_pdata.ac97 = wm97xx->ac97;
- codec_pdata.regmap = devm_regmap_init_ac97(wm97xx->ac97,
- &wm9712_regmap_config);
- codec_pdata.batt_pdata = pdata->batt_pdata;
- if (IS_ERR(codec_pdata.regmap))
- return PTR_ERR(codec_pdata.regmap);
-
- return devm_mfd_add_devices(wm97xx->dev, PLATFORM_DEVID_NONE, cells,
- ARRAY_SIZE(cells), NULL, 0, NULL);
-}
+static struct mfd_cell wm9712_cells[] = {
+ {
+ .name = "wm9712-codec",
+ },
+ {
+ .name = "wm97xx-ts",
+ },
+};
static const struct reg_default wm9713_reg_defaults[] = {
{ 0x02, 0x8080 }, /* Speaker Output Volume */
@@ -293,39 +255,23 @@ static const struct regmap_config wm9713_regmap_config = {
.writeable_reg = wm97xx_writeable_reg,
};
-static int wm9713_register(struct wm97xx_priv *wm97xx,
- struct wm97xx_pdata *pdata)
-{
- static struct wm97xx_platform_data codec_pdata;
- static const struct mfd_cell cells[] = {
- {
- .name = "wm9713-codec",
- .platform_data = &codec_pdata,
- .pdata_size = sizeof(codec_pdata),
- },
- {
- .name = "wm97xx-ts",
- .platform_data = &codec_pdata,
- .pdata_size = sizeof(codec_pdata),
- },
- };
-
- codec_pdata.ac97 = wm97xx->ac97;
- codec_pdata.regmap = devm_regmap_init_ac97(wm97xx->ac97,
- &wm9713_regmap_config);
- codec_pdata.batt_pdata = pdata->batt_pdata;
- if (IS_ERR(codec_pdata.regmap))
- return PTR_ERR(codec_pdata.regmap);
-
- return devm_mfd_add_devices(wm97xx->dev, PLATFORM_DEVID_NONE, cells,
- ARRAY_SIZE(cells), NULL, 0, NULL);
-}
+static struct mfd_cell wm9713_cells[] = {
+ {
+ .name = "wm9713-codec",
+ },
+ {
+ .name = "wm97xx-ts",
+ },
+};
static int wm97xx_ac97_probe(struct ac97_codec_device *adev)
{
struct wm97xx_priv *wm97xx;
- int ret;
- void *pdata = snd_ac97_codec_get_platdata(adev);
+ const struct regmap_config *config;
+ struct wm97xx_platform_data *codec_pdata;
+ struct mfd_cell *cells;
+ int ret = 0, nb_cells, i;
+ struct wm97xx_pdata *pdata = snd_ac97_codec_get_platdata(adev);
wm97xx = devm_kzalloc(ac97_codec_dev2dev(adev),
sizeof(*wm97xx), GFP_KERNEL);
@@ -342,20 +288,48 @@ static int wm97xx_ac97_probe(struct ac97_codec_device *adev)
dev_info(wm97xx->dev, "wm97xx core found, id=0x%x\n",
adev->vendor_id);
+ codec_pdata = &wm97xx->codec_pdata;
+ codec_pdata->ac97 = wm97xx->ac97;
+ codec_pdata->batt_pdata = pdata->batt_pdata;
+
switch (adev->vendor_id) {
case WM9705_VENDOR_ID:
- ret = wm9705_register(wm97xx, pdata);
+ config = &wm9705_regmap_config;
+ cells = wm9705_cells;
+ nb_cells = ARRAY_SIZE(wm9705_cells);
break;
case WM9712_VENDOR_ID:
- ret = wm9712_register(wm97xx, pdata);
+ config = &wm9712_regmap_config;
+ cells = wm9712_cells;
+ nb_cells = ARRAY_SIZE(wm9712_cells);
break;
case WM9713_VENDOR_ID:
- ret = wm9713_register(wm97xx, pdata);
+ config = &wm9713_regmap_config;
+ cells = wm9713_cells;
+ nb_cells = ARRAY_SIZE(wm9713_cells);
break;
default:
+ config = NULL;
+ }
+
+ for (i = 0; i < nb_cells; i++) {
+ cells[i].platform_data = codec_pdata;
+ cells[i].pdata_size = sizeof(*codec_pdata);
+ }
+
+ if (config) {
+ codec_pdata->regmap =
+ devm_regmap_init_ac97(wm97xx->ac97, config);
+ if (IS_ERR(codec_pdata->regmap))
+ ret = PTR_ERR(codec_pdata->regmap);
+ } else {
ret = -ENODEV;
}
+ if (!ret)
+ ret = devm_mfd_add_devices(wm97xx->dev, PLATFORM_DEVID_NONE,
+ cells, nb_cells, NULL, 0, NULL);
+
if (ret)
snd_ac97_compat_release(wm97xx->ac97);
@@ -1,17 +1,12 @@
/*
* wm97xx client interface
*
- * Copyright (C) 2016 Robert Jarzmik
+ * Copyright (C) 2017 Robert Jarzmik
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
*/
#ifndef __LINUX_MFD_WM97XX_H
@@ -27,5 +22,4 @@ struct wm97xx_platform_data {
struct wm97xx_batt_pdata *batt_pdata;
};
-
#endif