19dc15f81SMark Brown // SPDX-License-Identifier: GPL-2.0-only
29dc15f81SMark Brown /*
39dc15f81SMark Brown * wm8731-i2c.c -- WM8731 ALSA SoC Audio driver I2C code
49dc15f81SMark Brown *
59dc15f81SMark Brown * Copyright 2005 Openedhand Ltd.
69dc15f81SMark Brown * Copyright 2006-12 Wolfson Microelectronics, plc
79dc15f81SMark Brown *
89dc15f81SMark Brown * Author: Richard Purdie <richard@openedhand.com>
99dc15f81SMark Brown *
109dc15f81SMark Brown * Based on wm8753.c by Liam Girdwood
119dc15f81SMark Brown */
129dc15f81SMark Brown
139dc15f81SMark Brown #include <linux/i2c.h>
14340d79a1SRob Herring #include <linux/mod_devicetable.h>
159dc15f81SMark Brown #include <linux/module.h>
169dc15f81SMark Brown
179dc15f81SMark Brown #include "wm8731.h"
189dc15f81SMark Brown
199dc15f81SMark Brown
209dc15f81SMark Brown static const struct of_device_id wm8731_of_match[] = {
219dc15f81SMark Brown { .compatible = "wlf,wm8731", },
229dc15f81SMark Brown { }
239dc15f81SMark Brown };
249dc15f81SMark Brown MODULE_DEVICE_TABLE(of, wm8731_of_match);
259dc15f81SMark Brown
wm8731_i2c_probe(struct i2c_client * i2c)2640658542SStephen Kitt static int wm8731_i2c_probe(struct i2c_client *i2c)
279dc15f81SMark Brown {
289dc15f81SMark Brown struct wm8731_priv *wm8731;
299dc15f81SMark Brown int ret;
309dc15f81SMark Brown
319dc15f81SMark Brown wm8731 = devm_kzalloc(&i2c->dev, sizeof(struct wm8731_priv),
329dc15f81SMark Brown GFP_KERNEL);
339dc15f81SMark Brown if (wm8731 == NULL)
349dc15f81SMark Brown return -ENOMEM;
359dc15f81SMark Brown
369dc15f81SMark Brown i2c_set_clientdata(i2c, wm8731);
379dc15f81SMark Brown
389dc15f81SMark Brown wm8731->regmap = devm_regmap_init_i2c(i2c, &wm8731_regmap);
399dc15f81SMark Brown if (IS_ERR(wm8731->regmap)) {
409dc15f81SMark Brown ret = PTR_ERR(wm8731->regmap);
419dc15f81SMark Brown dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
429dc15f81SMark Brown ret);
439dc15f81SMark Brown return ret;
449dc15f81SMark Brown }
459dc15f81SMark Brown
469dc15f81SMark Brown return wm8731_init(&i2c->dev, wm8731);
479dc15f81SMark Brown }
489dc15f81SMark Brown
499dc15f81SMark Brown static const struct i2c_device_id wm8731_i2c_id[] = {
50*ba2a2c37SUwe Kleine-König { "wm8731" },
519dc15f81SMark Brown { }
529dc15f81SMark Brown };
539dc15f81SMark Brown MODULE_DEVICE_TABLE(i2c, wm8731_i2c_id);
549dc15f81SMark Brown
559dc15f81SMark Brown static struct i2c_driver wm8731_i2c_driver = {
569dc15f81SMark Brown .driver = {
579dc15f81SMark Brown .name = "wm8731",
589dc15f81SMark Brown .of_match_table = wm8731_of_match,
599dc15f81SMark Brown },
609abcd240SUwe Kleine-König .probe = wm8731_i2c_probe,
619dc15f81SMark Brown .id_table = wm8731_i2c_id,
629dc15f81SMark Brown };
639dc15f81SMark Brown
649dc15f81SMark Brown module_i2c_driver(wm8731_i2c_driver);
659dc15f81SMark Brown
669dc15f81SMark Brown MODULE_DESCRIPTION("ASoC WM8731 driver - I2C");
679dc15f81SMark Brown MODULE_AUTHOR("Richard Purdie");
689dc15f81SMark Brown MODULE_LICENSE("GPL");
69