diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-09-19 18:04:06 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-11-08 09:13:25 -0500 |
commit | b2d1e23373fde66d5532ffdfd0f1e650174b83f6 (patch) | |
tree | eed5421994eb7adae03c1ac959d06a004842bb96 /sound/soc/codecs/wm8996.c | |
parent | ee5f387226d13535f41bda0e8a2cf3843fc4c080 (diff) |
ASoC: Convert WM8996 gpiolib to regmap
Actually pretty straightforward.
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/codecs/wm8996.c')
-rw-r--r-- | sound/soc/codecs/wm8996.c | 56 |
1 files changed, 27 insertions, 29 deletions
diff --git a/sound/soc/codecs/wm8996.c b/sound/soc/codecs/wm8996.c index cb9709ad66fd..fd5bb1ad6912 100644 --- a/sound/soc/codecs/wm8996.c +++ b/sound/soc/codecs/wm8996.c | |||
@@ -50,6 +50,7 @@ static const char *wm8996_supply_names[WM8996_NUM_SUPPLIES] = { | |||
50 | }; | 50 | }; |
51 | 51 | ||
52 | struct wm8996_priv { | 52 | struct wm8996_priv { |
53 | struct device *dev; | ||
53 | struct regmap *regmap; | 54 | struct regmap *regmap; |
54 | struct snd_soc_codec *codec; | 55 | struct snd_soc_codec *codec; |
55 | 56 | ||
@@ -2325,48 +2326,45 @@ static inline struct wm8996_priv *gpio_to_wm8996(struct gpio_chip *chip) | |||
2325 | static void wm8996_gpio_set(struct gpio_chip *chip, unsigned offset, int value) | 2326 | static void wm8996_gpio_set(struct gpio_chip *chip, unsigned offset, int value) |
2326 | { | 2327 | { |
2327 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); | 2328 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
2328 | struct snd_soc_codec *codec = wm8996->codec; | ||
2329 | 2329 | ||
2330 | snd_soc_update_bits(codec, WM8996_GPIO_1 + offset, | 2330 | regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, |
2331 | WM8996_GP1_LVL, !!value << WM8996_GP1_LVL_SHIFT); | 2331 | WM8996_GP1_LVL, !!value << WM8996_GP1_LVL_SHIFT); |
2332 | } | 2332 | } |
2333 | 2333 | ||
2334 | static int wm8996_gpio_direction_out(struct gpio_chip *chip, | 2334 | static int wm8996_gpio_direction_out(struct gpio_chip *chip, |
2335 | unsigned offset, int value) | 2335 | unsigned offset, int value) |
2336 | { | 2336 | { |
2337 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); | 2337 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
2338 | struct snd_soc_codec *codec = wm8996->codec; | ||
2339 | int val; | 2338 | int val; |
2340 | 2339 | ||
2341 | val = (1 << WM8996_GP1_FN_SHIFT) | (!!value << WM8996_GP1_LVL_SHIFT); | 2340 | val = (1 << WM8996_GP1_FN_SHIFT) | (!!value << WM8996_GP1_LVL_SHIFT); |
2342 | 2341 | ||
2343 | return snd_soc_update_bits(codec, WM8996_GPIO_1 + offset, | 2342 | return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, |
2344 | WM8996_GP1_FN_MASK | WM8996_GP1_DIR | | 2343 | WM8996_GP1_FN_MASK | WM8996_GP1_DIR | |
2345 | WM8996_GP1_LVL, val); | 2344 | WM8996_GP1_LVL, val); |
2346 | } | 2345 | } |
2347 | 2346 | ||
2348 | static int wm8996_gpio_get(struct gpio_chip *chip, unsigned offset) | 2347 | static int wm8996_gpio_get(struct gpio_chip *chip, unsigned offset) |
2349 | { | 2348 | { |
2350 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); | 2349 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
2351 | struct snd_soc_codec *codec = wm8996->codec; | 2350 | unsigned int reg; |
2352 | int ret; | 2351 | int ret; |
2353 | 2352 | ||
2354 | ret = snd_soc_read(codec, WM8996_GPIO_1 + offset); | 2353 | ret = regmap_read(wm8996->regmap, WM8996_GPIO_1 + offset, ®); |
2355 | if (ret < 0) | 2354 | if (ret < 0) |
2356 | return ret; | 2355 | return ret; |
2357 | 2356 | ||
2358 | return (ret & WM8996_GP1_LVL) != 0; | 2357 | return (reg & WM8996_GP1_LVL) != 0; |
2359 | } | 2358 | } |
2360 | 2359 | ||
2361 | static int wm8996_gpio_direction_in(struct gpio_chip *chip, unsigned offset) | 2360 | static int wm8996_gpio_direction_in(struct gpio_chip *chip, unsigned offset) |
2362 | { | 2361 | { |
2363 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); | 2362 | struct wm8996_priv *wm8996 = gpio_to_wm8996(chip); |
2364 | struct snd_soc_codec *codec = wm8996->codec; | ||
2365 | 2363 | ||
2366 | return snd_soc_update_bits(codec, WM8996_GPIO_1 + offset, | 2364 | return regmap_update_bits(wm8996->regmap, WM8996_GPIO_1 + offset, |
2367 | WM8996_GP1_FN_MASK | WM8996_GP1_DIR, | 2365 | WM8996_GP1_FN_MASK | WM8996_GP1_DIR, |
2368 | (1 << WM8996_GP1_FN_SHIFT) | | 2366 | (1 << WM8996_GP1_FN_SHIFT) | |
2369 | (1 << WM8996_GP1_DIR_SHIFT)); | 2367 | (1 << WM8996_GP1_DIR_SHIFT)); |
2370 | } | 2368 | } |
2371 | 2369 | ||
2372 | static struct gpio_chip wm8996_template_chip = { | 2370 | static struct gpio_chip wm8996_template_chip = { |
@@ -2379,14 +2377,13 @@ static struct gpio_chip wm8996_template_chip = { | |||
2379 | .can_sleep = 1, | 2377 | .can_sleep = 1, |
2380 | }; | 2378 | }; |
2381 | 2379 | ||
2382 | static void wm8996_init_gpio(struct snd_soc_codec *codec) | 2380 | static void wm8996_init_gpio(struct wm8996_priv *wm8996) |
2383 | { | 2381 | { |
2384 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); | ||
2385 | int ret; | 2382 | int ret; |
2386 | 2383 | ||
2387 | wm8996->gpio_chip = wm8996_template_chip; | 2384 | wm8996->gpio_chip = wm8996_template_chip; |
2388 | wm8996->gpio_chip.ngpio = 5; | 2385 | wm8996->gpio_chip.ngpio = 5; |
2389 | wm8996->gpio_chip.dev = codec->dev; | 2386 | wm8996->gpio_chip.dev = wm8996->dev; |
2390 | 2387 | ||
2391 | if (wm8996->pdata.gpio_base) | 2388 | if (wm8996->pdata.gpio_base) |
2392 | wm8996->gpio_chip.base = wm8996->pdata.gpio_base; | 2389 | wm8996->gpio_chip.base = wm8996->pdata.gpio_base; |
@@ -2395,24 +2392,23 @@ static void wm8996_init_gpio(struct snd_soc_codec *codec) | |||
2395 | 2392 | ||
2396 | ret = gpiochip_add(&wm8996->gpio_chip); | 2393 | ret = gpiochip_add(&wm8996->gpio_chip); |
2397 | if (ret != 0) | 2394 | if (ret != 0) |
2398 | dev_err(codec->dev, "Failed to add GPIOs: %d\n", ret); | 2395 | dev_err(wm8996->dev, "Failed to add GPIOs: %d\n", ret); |
2399 | } | 2396 | } |
2400 | 2397 | ||
2401 | static void wm8996_free_gpio(struct snd_soc_codec *codec) | 2398 | static void wm8996_free_gpio(struct wm8996_priv *wm8996) |
2402 | { | 2399 | { |
2403 | struct wm8996_priv *wm8996 = snd_soc_codec_get_drvdata(codec); | ||
2404 | int ret; | 2400 | int ret; |
2405 | 2401 | ||
2406 | ret = gpiochip_remove(&wm8996->gpio_chip); | 2402 | ret = gpiochip_remove(&wm8996->gpio_chip); |
2407 | if (ret != 0) | 2403 | if (ret != 0) |
2408 | dev_err(codec->dev, "Failed to remove GPIOs: %d\n", ret); | 2404 | dev_err(wm8996->dev, "Failed to remove GPIOs: %d\n", ret); |
2409 | } | 2405 | } |
2410 | #else | 2406 | #else |
2411 | static void wm8996_init_gpio(struct snd_soc_codec *codec) | 2407 | static void wm8996_init_gpio(struct wm8996_priv *wm8996) |
2412 | { | 2408 | { |
2413 | } | 2409 | } |
2414 | 2410 | ||
2415 | static void wm8996_free_gpio(struct snd_soc_codec *codec) | 2411 | static void wm8996_free_gpio(struct wm8996_priv *wm8996) |
2416 | { | 2412 | { |
2417 | } | 2413 | } |
2418 | #endif | 2414 | #endif |
@@ -2974,8 +2970,6 @@ static int wm8996_probe(struct snd_soc_codec *codec) | |||
2974 | WM8996_AIF2TX_LRCLK_MODE, | 2970 | WM8996_AIF2TX_LRCLK_MODE, |
2975 | WM8996_AIF2TX_LRCLK_MODE); | 2971 | WM8996_AIF2TX_LRCLK_MODE); |
2976 | 2972 | ||
2977 | wm8996_init_gpio(codec); | ||
2978 | |||
2979 | if (i2c->irq) { | 2973 | if (i2c->irq) { |
2980 | if (wm8996->pdata.irq_flags) | 2974 | if (wm8996->pdata.irq_flags) |
2981 | irq_flags = wm8996->pdata.irq_flags; | 2975 | irq_flags = wm8996->pdata.irq_flags; |
@@ -3029,8 +3023,6 @@ static int wm8996_remove(struct snd_soc_codec *codec) | |||
3029 | if (i2c->irq) | 3023 | if (i2c->irq) |
3030 | free_irq(i2c->irq, codec); | 3024 | free_irq(i2c->irq, codec); |
3031 | 3025 | ||
3032 | wm8996_free_gpio(codec); | ||
3033 | |||
3034 | for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) | 3026 | for (i = 0; i < ARRAY_SIZE(wm8996->supplies); i++) |
3035 | regulator_unregister_notifier(wm8996->supplies[i].consumer, | 3027 | regulator_unregister_notifier(wm8996->supplies[i].consumer, |
3036 | &wm8996->disable_nb[i]); | 3028 | &wm8996->disable_nb[i]); |
@@ -3117,6 +3109,7 @@ static __devinit int wm8996_i2c_probe(struct i2c_client *i2c, | |||
3117 | return -ENOMEM; | 3109 | return -ENOMEM; |
3118 | 3110 | ||
3119 | i2c_set_clientdata(i2c, wm8996); | 3111 | i2c_set_clientdata(i2c, wm8996); |
3112 | wm8996->dev = &i2c->dev; | ||
3120 | 3113 | ||
3121 | if (dev_get_platdata(&i2c->dev)) | 3114 | if (dev_get_platdata(&i2c->dev)) |
3122 | memcpy(&wm8996->pdata, dev_get_platdata(&i2c->dev), | 3115 | memcpy(&wm8996->pdata, dev_get_platdata(&i2c->dev), |
@@ -3197,14 +3190,18 @@ static __devinit int wm8996_i2c_probe(struct i2c_client *i2c, | |||
3197 | goto err_regmap; | 3190 | goto err_regmap; |
3198 | } | 3191 | } |
3199 | 3192 | ||
3193 | wm8996_init_gpio(wm8996); | ||
3194 | |||
3200 | ret = snd_soc_register_codec(&i2c->dev, | 3195 | ret = snd_soc_register_codec(&i2c->dev, |
3201 | &soc_codec_dev_wm8996, wm8996_dai, | 3196 | &soc_codec_dev_wm8996, wm8996_dai, |
3202 | ARRAY_SIZE(wm8996_dai)); | 3197 | ARRAY_SIZE(wm8996_dai)); |
3203 | if (ret < 0) | 3198 | if (ret < 0) |
3204 | goto err_regmap; | 3199 | goto err_gpiolib; |
3205 | 3200 | ||
3206 | return ret; | 3201 | return ret; |
3207 | 3202 | ||
3203 | err_gpiolib: | ||
3204 | wm8996_free_gpio(wm8996); | ||
3208 | err_regmap: | 3205 | err_regmap: |
3209 | regmap_exit(wm8996->regmap); | 3206 | regmap_exit(wm8996->regmap); |
3210 | err_enable: | 3207 | err_enable: |
@@ -3229,6 +3226,7 @@ static __devexit int wm8996_i2c_remove(struct i2c_client *client) | |||
3229 | struct wm8996_priv *wm8996 = i2c_get_clientdata(client); | 3226 | struct wm8996_priv *wm8996 = i2c_get_clientdata(client); |
3230 | 3227 | ||
3231 | snd_soc_unregister_codec(&client->dev); | 3228 | snd_soc_unregister_codec(&client->dev); |
3229 | wm8996_free_gpio(wm8996); | ||
3232 | regulator_put(wm8996->cpvdd); | 3230 | regulator_put(wm8996->cpvdd); |
3233 | regulator_bulk_free(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); | 3231 | regulator_bulk_free(ARRAY_SIZE(wm8996->supplies), wm8996->supplies); |
3234 | regmap_exit(wm8996->regmap); | 3232 | regmap_exit(wm8996->regmap); |