.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * wm2000.c -- WM2000 ALSA Soc Audio driver |
---|
3 | 4 | * |
---|
4 | 5 | * Copyright 2008-2011 Wolfson Microelectronics PLC. |
---|
5 | 6 | * |
---|
6 | 7 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License version 2 as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | 8 | * |
---|
12 | 9 | * The download image for the WM2000 will be requested as |
---|
13 | 10 | * 'wm2000_anc.bin' by default (overridable via platform data) at |
---|
.. | .. |
---|
88 | 85 | return regmap_write(wm2000->regmap, reg, value); |
---|
89 | 86 | } |
---|
90 | 87 | |
---|
91 | | -static unsigned int wm2000_read(struct i2c_client *i2c, unsigned int r) |
---|
92 | | -{ |
---|
93 | | - struct wm2000_priv *wm2000 = i2c_get_clientdata(i2c); |
---|
94 | | - unsigned int val; |
---|
95 | | - int ret; |
---|
96 | | - |
---|
97 | | - ret = regmap_read(wm2000->regmap, r, &val); |
---|
98 | | - if (ret < 0) |
---|
99 | | - return -1; |
---|
100 | | - |
---|
101 | | - return val; |
---|
102 | | -} |
---|
103 | | - |
---|
104 | 88 | static void wm2000_reset(struct wm2000_priv *wm2000) |
---|
105 | 89 | { |
---|
106 | 90 | struct i2c_client *i2c = wm2000->i2c; |
---|
.. | .. |
---|
115 | 99 | static int wm2000_poll_bit(struct i2c_client *i2c, |
---|
116 | 100 | unsigned int reg, u8 mask) |
---|
117 | 101 | { |
---|
| 102 | + struct wm2000_priv *wm2000 = i2c_get_clientdata(i2c); |
---|
118 | 103 | int timeout = 4000; |
---|
119 | | - int val; |
---|
| 104 | + unsigned int val; |
---|
120 | 105 | |
---|
121 | | - val = wm2000_read(i2c, reg); |
---|
| 106 | + regmap_read(wm2000->regmap, reg, &val); |
---|
122 | 107 | |
---|
123 | 108 | while (!(val & mask) && --timeout) { |
---|
124 | 109 | msleep(1); |
---|
125 | | - val = wm2000_read(i2c, reg); |
---|
| 110 | + regmap_read(wm2000->regmap, reg, &val); |
---|
126 | 111 | } |
---|
127 | 112 | |
---|
128 | 113 | if (timeout == 0) |
---|
.. | .. |
---|
135 | 120 | { |
---|
136 | 121 | struct wm2000_priv *wm2000 = dev_get_drvdata(&i2c->dev); |
---|
137 | 122 | unsigned long rate; |
---|
| 123 | + unsigned int val; |
---|
138 | 124 | int ret; |
---|
139 | 125 | |
---|
140 | 126 | if (WARN_ON(wm2000->anc_mode != ANC_OFF)) |
---|
.. | .. |
---|
213 | 199 | WM2000_MODE_THERMAL_ENABLE); |
---|
214 | 200 | } |
---|
215 | 201 | |
---|
216 | | - ret = wm2000_read(i2c, WM2000_REG_SPEECH_CLARITY); |
---|
| 202 | + ret = regmap_read(wm2000->regmap, WM2000_REG_SPEECH_CLARITY, &val); |
---|
| 203 | + if (ret != 0) { |
---|
| 204 | + dev_err(&i2c->dev, "Unable to read Speech Clarity: %d\n", ret); |
---|
| 205 | + regulator_bulk_disable(WM2000_NUM_SUPPLIES, wm2000->supplies); |
---|
| 206 | + return ret; |
---|
| 207 | + } |
---|
217 | 208 | if (wm2000->speech_clarity) |
---|
218 | | - ret |= WM2000_SPEECH_CLARITY; |
---|
| 209 | + val |= WM2000_SPEECH_CLARITY; |
---|
219 | 210 | else |
---|
220 | | - ret &= ~WM2000_SPEECH_CLARITY; |
---|
221 | | - wm2000_write(i2c, WM2000_REG_SPEECH_CLARITY, ret); |
---|
| 211 | + val &= ~WM2000_SPEECH_CLARITY; |
---|
| 212 | + wm2000_write(i2c, WM2000_REG_SPEECH_CLARITY, val); |
---|
222 | 213 | |
---|
223 | 214 | wm2000_write(i2c, WM2000_REG_SYS_START0, 0x33); |
---|
224 | 215 | wm2000_write(i2c, WM2000_REG_SYS_START1, 0x02); |
---|
.. | .. |
---|
545 | 536 | { |
---|
546 | 537 | struct i2c_client *i2c = wm2000->i2c; |
---|
547 | 538 | int i, j; |
---|
548 | | - int ret; |
---|
| 539 | + int ret = 0; |
---|
549 | 540 | |
---|
550 | 541 | if (wm2000->anc_mode == mode) |
---|
551 | 542 | return 0; |
---|
.. | .. |
---|
575 | 566 | ret = anc_transitions[i].step[j](i2c, |
---|
576 | 567 | anc_transitions[i].analogue); |
---|
577 | 568 | if (ret != 0) |
---|
578 | | - return ret; |
---|
| 569 | + break; |
---|
579 | 570 | } |
---|
580 | 571 | |
---|
581 | 572 | if (anc_transitions[i].dest == ANC_OFF) |
---|
582 | 573 | clk_disable_unprepare(wm2000->mclk); |
---|
583 | 574 | |
---|
584 | | - return 0; |
---|
| 575 | + return ret; |
---|
585 | 576 | } |
---|
586 | 577 | |
---|
587 | 578 | static int wm2000_anc_set_mode(struct wm2000_priv *wm2000) |
---|
.. | .. |
---|
824 | 815 | const char *filename; |
---|
825 | 816 | const struct firmware *fw = NULL; |
---|
826 | 817 | int ret, i; |
---|
827 | | - int reg; |
---|
| 818 | + unsigned int reg; |
---|
828 | 819 | u16 id; |
---|
829 | 820 | |
---|
830 | 821 | wm2000 = devm_kzalloc(&i2c->dev, sizeof(*wm2000), GFP_KERNEL); |
---|
.. | .. |
---|
860 | 851 | } |
---|
861 | 852 | |
---|
862 | 853 | /* Verify that this is a WM2000 */ |
---|
863 | | - reg = wm2000_read(i2c, WM2000_REG_ID1); |
---|
| 854 | + ret = regmap_read(wm2000->regmap, WM2000_REG_ID1, ®); |
---|
| 855 | + if (ret != 0) { |
---|
| 856 | + dev_err(&i2c->dev, "Unable to read ID1: %d\n", ret); |
---|
| 857 | + return ret; |
---|
| 858 | + } |
---|
864 | 859 | id = reg << 8; |
---|
865 | | - reg = wm2000_read(i2c, WM2000_REG_ID2); |
---|
| 860 | + ret = regmap_read(wm2000->regmap, WM2000_REG_ID2, ®); |
---|
| 861 | + if (ret != 0) { |
---|
| 862 | + dev_err(&i2c->dev, "Unable to read ID2: %d\n", ret); |
---|
| 863 | + return ret; |
---|
| 864 | + } |
---|
866 | 865 | id |= reg & 0xff; |
---|
867 | 866 | |
---|
868 | 867 | if (id != 0x2000) { |
---|
.. | .. |
---|
871 | 870 | goto err_supplies; |
---|
872 | 871 | } |
---|
873 | 872 | |
---|
874 | | - reg = wm2000_read(i2c, WM2000_REG_REVISON); |
---|
| 873 | + ret = regmap_read(wm2000->regmap, WM2000_REG_REVISON, ®); |
---|
| 874 | + if (ret != 0) { |
---|
| 875 | + dev_err(&i2c->dev, "Unable to read Revision: %d\n", ret); |
---|
| 876 | + return ret; |
---|
| 877 | + } |
---|
875 | 878 | dev_info(&i2c->dev, "revision %c\n", reg + 'A'); |
---|
876 | 879 | |
---|
877 | 880 | wm2000->mclk = devm_clk_get(&i2c->dev, "MCLK"); |
---|