Lines Matching refs:wm8400

117 static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest)  in wm8400_read()  argument
121 BUG_ON(reg + num_regs > ARRAY_SIZE(wm8400->reg_cache)); in wm8400_read()
126 ret = wm8400->read_dev(wm8400->io_data, reg, in wm8400_read()
137 memcpy(dest, &wm8400->reg_cache[reg], num_regs * sizeof(u16)); in wm8400_read()
142 static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs, in wm8400_write() argument
147 BUG_ON(reg + num_regs > ARRAY_SIZE(wm8400->reg_cache)); in wm8400_write()
151 wm8400->reg_cache[reg + i] = src[i]; in wm8400_write()
156 ret = wm8400->write_dev(wm8400->io_data, reg, num_regs, src); in wm8400_write()
171 u16 wm8400_reg_read(struct wm8400 *wm8400, u8 reg) in wm8400_reg_read() argument
175 mutex_lock(&wm8400->io_lock); in wm8400_reg_read()
177 wm8400_read(wm8400, reg, 1, &val); in wm8400_reg_read()
179 mutex_unlock(&wm8400->io_lock); in wm8400_reg_read()
185 int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data) in wm8400_block_read() argument
189 mutex_lock(&wm8400->io_lock); in wm8400_block_read()
191 ret = wm8400_read(wm8400, reg, count, data); in wm8400_block_read()
193 mutex_unlock(&wm8400->io_lock); in wm8400_block_read()
207 int wm8400_set_bits(struct wm8400 *wm8400, u8 reg, u16 mask, u16 val) in wm8400_set_bits() argument
212 mutex_lock(&wm8400->io_lock); in wm8400_set_bits()
214 ret = wm8400_read(wm8400, reg, 1, &tmp); in wm8400_set_bits()
217 ret = wm8400_write(wm8400, reg, 1, &tmp); in wm8400_set_bits()
219 mutex_unlock(&wm8400->io_lock); in wm8400_set_bits()
229 void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400) in wm8400_reset_codec_reg_cache() argument
233 mutex_lock(&wm8400->io_lock); in wm8400_reset_codec_reg_cache()
236 for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++) in wm8400_reset_codec_reg_cache()
238 wm8400->reg_cache[i] = reg_data[i].default_val; in wm8400_reset_codec_reg_cache()
240 mutex_unlock(&wm8400->io_lock); in wm8400_reset_codec_reg_cache()
244 static int wm8400_register_codec(struct wm8400 *wm8400) in wm8400_register_codec() argument
248 .mfd_data = wm8400, in wm8400_register_codec()
251 return mfd_add_devices(wm8400->dev, -1, &cell, 1, NULL, 0); in wm8400_register_codec()
261 static int wm8400_init(struct wm8400 *wm8400, in wm8400_init() argument
267 mutex_init(&wm8400->io_lock); in wm8400_init()
269 dev_set_drvdata(wm8400->dev, wm8400); in wm8400_init()
272 ret = wm8400->read_dev(wm8400->io_data, WM8400_RESET_ID, 1, &reg); in wm8400_init()
274 dev_err(wm8400->dev, "Chip ID register read failed\n"); in wm8400_init()
278 dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n", in wm8400_init()
287 ret = wm8400->read_dev(wm8400->io_data, 0, in wm8400_init()
288 ARRAY_SIZE(wm8400->reg_cache), in wm8400_init()
289 wm8400->reg_cache); in wm8400_init()
291 dev_err(wm8400->dev, "Register cache read failed\n"); in wm8400_init()
294 for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++) in wm8400_init()
295 wm8400->reg_cache[i] = be16_to_cpu(wm8400->reg_cache[i]); in wm8400_init()
298 if (!(wm8400->reg_cache[WM8400_POWER_MANAGEMENT_1] & WM8400_CODEC_ENA)) in wm8400_init()
299 for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++) in wm8400_init()
301 wm8400->reg_cache[i] = reg_data[i].default_val; in wm8400_init()
303 ret = wm8400_read(wm8400, WM8400_ID, 1, &reg); in wm8400_init()
305 dev_err(wm8400->dev, "ID register read failed: %d\n", ret); in wm8400_init()
309 dev_info(wm8400->dev, "WM8400 revision %x\n", reg); in wm8400_init()
311 ret = wm8400_register_codec(wm8400); in wm8400_init()
313 dev_err(wm8400->dev, "Failed to register codec\n"); in wm8400_init()
318 ret = pdata->platform_init(wm8400->dev); in wm8400_init()
320 dev_err(wm8400->dev, "Platform init failed: %d\n", in wm8400_init()
325 dev_warn(wm8400->dev, "No platform initialisation supplied\n"); in wm8400_init()
330 mfd_remove_devices(wm8400->dev); in wm8400_init()
334 static void wm8400_release(struct wm8400 *wm8400) in wm8400_release() argument
336 mfd_remove_devices(wm8400->dev); in wm8400_release()
396 struct wm8400 *wm8400; in wm8400_i2c_probe() local
399 wm8400 = kzalloc(sizeof(struct wm8400), GFP_KERNEL); in wm8400_i2c_probe()
400 if (wm8400 == NULL) { in wm8400_i2c_probe()
405 wm8400->io_data = i2c; in wm8400_i2c_probe()
406 wm8400->read_dev = wm8400_i2c_read; in wm8400_i2c_probe()
407 wm8400->write_dev = wm8400_i2c_write; in wm8400_i2c_probe()
408 wm8400->dev = &i2c->dev; in wm8400_i2c_probe()
409 i2c_set_clientdata(i2c, wm8400); in wm8400_i2c_probe()
411 ret = wm8400_init(wm8400, i2c->dev.platform_data); in wm8400_i2c_probe()
418 kfree(wm8400); in wm8400_i2c_probe()
425 struct wm8400 *wm8400 = i2c_get_clientdata(i2c); in wm8400_i2c_remove() local
427 wm8400_release(wm8400); in wm8400_i2c_remove()
428 kfree(wm8400); in wm8400_i2c_remove()