Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  /* I2C access for DA9055 PMICs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright(c) 2012 Dialog Semiconductor Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Author: David Dajun Chen <dchen@diasemi.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/mfd/da9055/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static int da9055_i2c_probe(struct i2c_client *i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 				      const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	struct da9055 *da9055;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	da9055 = devm_kzalloc(&i2c->dev, sizeof(struct da9055), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	if (!da9055)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	da9055->regmap = devm_regmap_init_i2c(i2c, &da9055_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	if (IS_ERR(da9055->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		ret = PTR_ERR(da9055->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		dev_err(&i2c->dev, "Failed to allocate register map: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	da9055->dev = &i2c->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	da9055->chip_irq = i2c->irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	i2c_set_clientdata(i2c, da9055);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	return da9055_device_init(da9055);
^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 int da9055_i2c_remove(struct i2c_client *i2c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	struct da9055 *da9055 = i2c_get_clientdata(i2c);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	da9055_device_exit(da9055);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  * DO NOT change the device Ids. The naming is intentionally specific as both
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55)  * the PMIC and CODEC parts of this chip are instantiated separately as I2C
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56)  * devices (both have configurable I2C addresses, and are to all intents and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57)  * purposes separate). As a result there are specific DA9055 ids for PMIC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58)  * and CODEC, which must be different to operate together.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static const struct i2c_device_id da9055_i2c_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	{"da9055-pmic", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) MODULE_DEVICE_TABLE(i2c, da9055_i2c_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static const struct of_device_id da9055_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	{ .compatible = "dlg,da9055-pmic", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	{ }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) static struct i2c_driver da9055_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.probe = da9055_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.remove = da9055_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.id_table = da9055_i2c_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.name = "da9055-pmic",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		.of_match_table = of_match_ptr(da9055_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int __init da9055_i2c_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	ret = i2c_add_driver(&da9055_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	if (ret != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 		pr_err("DA9055 I2C registration failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) subsys_initcall(da9055_i2c_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) static void __exit da9055_i2c_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	i2c_del_driver(&da9055_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) module_exit(da9055_i2c_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) MODULE_DESCRIPTION("I2C driver for Dialog DA9055 PMIC");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) MODULE_LICENSE("GPL");