2 * Core driver for WM8400.
4 * Copyright 2008 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
15 #include <linux/init.h>
16 #include <linux/bug.h>
17 #include <linux/err.h>
18 #include <linux/i2c.h>
19 #include <linux/kernel.h>
20 #include <linux/mfd/core.h>
21 #include <linux/mfd/wm8400-private.h>
22 #include <linux/mfd/wm8400-audio.h>
23 #include <linux/regmap.h>
24 #include <linux/slab.h>
26 static bool wm8400_volatile(struct device
*dev
, unsigned int reg
)
29 case WM8400_INTERRUPT_STATUS_1
:
30 case WM8400_INTERRUPT_LEVELS
:
31 case WM8400_SHUTDOWN_REASON
:
38 static int wm8400_register_codec(struct wm8400
*wm8400
)
40 const struct mfd_cell cell
= {
41 .name
= "wm8400-codec",
42 .platform_data
= wm8400
,
43 .pdata_size
= sizeof(*wm8400
),
46 return devm_mfd_add_devices(wm8400
->dev
, -1, &cell
, 1, NULL
, 0, NULL
);
50 * wm8400_init - Generic initialisation
52 * The WM8400 can be configured as either an I2C or SPI device. Probe
53 * functions for each bus set up the accessors then call into this to
54 * set up the device itself.
56 static int wm8400_init(struct wm8400
*wm8400
,
57 struct wm8400_platform_data
*pdata
)
62 dev_set_drvdata(wm8400
->dev
, wm8400
);
64 /* Check that this is actually a WM8400 */
65 ret
= regmap_read(wm8400
->regmap
, WM8400_RESET_ID
, ®
);
67 dev_err(wm8400
->dev
, "Chip ID register read failed\n");
71 dev_err(wm8400
->dev
, "Device is not a WM8400, ID is %x\n",
76 ret
= regmap_read(wm8400
->regmap
, WM8400_ID
, ®
);
78 dev_err(wm8400
->dev
, "ID register read failed: %d\n", ret
);
81 reg
= (reg
& WM8400_CHIP_REV_MASK
) >> WM8400_CHIP_REV_SHIFT
;
82 dev_info(wm8400
->dev
, "WM8400 revision %x\n", reg
);
84 ret
= wm8400_register_codec(wm8400
);
86 dev_err(wm8400
->dev
, "Failed to register codec\n");
90 if (pdata
&& pdata
->platform_init
) {
91 ret
= pdata
->platform_init(wm8400
->dev
);
93 dev_err(wm8400
->dev
, "Platform init failed: %d\n",
98 dev_warn(wm8400
->dev
, "No platform initialisation supplied\n");
103 static const struct regmap_config wm8400_regmap_config
= {
106 .max_register
= WM8400_REGISTER_COUNT
- 1,
108 .volatile_reg
= wm8400_volatile
,
110 .cache_type
= REGCACHE_RBTREE
,
114 * wm8400_reset_codec_reg_cache - Reset cached codec registers to
115 * their default values.
117 void wm8400_reset_codec_reg_cache(struct wm8400
*wm8400
)
119 regmap_reinit_cache(wm8400
->regmap
, &wm8400_regmap_config
);
121 EXPORT_SYMBOL_GPL(wm8400_reset_codec_reg_cache
);
123 #if IS_ENABLED(CONFIG_I2C)
124 static int wm8400_i2c_probe(struct i2c_client
*i2c
,
125 const struct i2c_device_id
*id
)
127 struct wm8400
*wm8400
;
129 wm8400
= devm_kzalloc(&i2c
->dev
, sizeof(struct wm8400
), GFP_KERNEL
);
133 wm8400
->regmap
= devm_regmap_init_i2c(i2c
, &wm8400_regmap_config
);
134 if (IS_ERR(wm8400
->regmap
))
135 return PTR_ERR(wm8400
->regmap
);
137 wm8400
->dev
= &i2c
->dev
;
138 i2c_set_clientdata(i2c
, wm8400
);
140 return wm8400_init(wm8400
, dev_get_platdata(&i2c
->dev
));
143 static const struct i2c_device_id wm8400_i2c_id
[] = {
148 static struct i2c_driver wm8400_i2c_driver
= {
152 .probe
= wm8400_i2c_probe
,
153 .id_table
= wm8400_i2c_id
,
157 static int __init
wm8400_driver_init(void)
161 #if IS_ENABLED(CONFIG_I2C)
162 ret
= i2c_add_driver(&wm8400_i2c_driver
);
164 pr_err("Failed to register I2C driver: %d\n", ret
);
169 subsys_initcall(wm8400_driver_init
);