^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * wm8350-i2c.c -- Generic I2C driver for Wolfson WM8350 PMIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2007, 2008 Wolfson Microelectronics PLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Liam Girdwood
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * linux@wolfsonmicro.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/mfd/wm8350/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static int wm8350_i2c_probe(struct i2c_client *i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct wm8350 *wm8350;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct wm8350_platform_data *pdata = dev_get_platdata(&i2c->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) wm8350 = devm_kzalloc(&i2c->dev, sizeof(struct wm8350), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) if (wm8350 == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) wm8350->regmap = devm_regmap_init_i2c(i2c, &wm8350_regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) if (IS_ERR(wm8350->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) ret = PTR_ERR(wm8350->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) i2c_set_clientdata(i2c, wm8350);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) wm8350->dev = &i2c->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) return wm8350_device_init(wm8350, i2c->irq, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static const struct i2c_device_id wm8350_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) { "wm8350", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) { "wm8351", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) { "wm8352", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) static struct i2c_driver wm8350_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) .name = "wm8350",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) .suppress_bind_attrs = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) .probe = wm8350_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) .id_table = wm8350_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static int __init wm8350_i2c_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return i2c_add_driver(&wm8350_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* init early so consumer devices can complete system boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) subsys_initcall(wm8350_i2c_init);