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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * wm831x-spi.c  --  SPI access for Wolfson WM831x PMICs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2009,2010 Wolfson Microelectronics PLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/pm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/spi/spi.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/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/mfd/wm831x/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int wm831x_spi_probe(struct spi_device *spi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	struct wm831x_pdata *pdata = dev_get_platdata(&spi->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	const struct spi_device_id *id = spi_get_device_id(spi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	const struct of_device_id *of_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct wm831x *wm831x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	enum wm831x_parent type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	if (spi->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		of_id = of_match_device(wm831x_of_match, &spi->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		if (!of_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 			dev_err(&spi->dev, "Failed to match device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		type = (enum wm831x_parent)of_id->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		type = (enum wm831x_parent)id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	wm831x = devm_kzalloc(&spi->dev, sizeof(struct wm831x), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (wm831x == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	spi->mode = SPI_MODE_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	spi_set_drvdata(spi, wm831x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	wm831x->dev = &spi->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	wm831x->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	wm831x->regmap = devm_regmap_init_spi(spi, &wm831x_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	if (IS_ERR(wm831x->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 		ret = PTR_ERR(wm831x->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		dev_err(wm831x->dev, "Failed to allocate register map: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	if (pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		memcpy(&wm831x->pdata, pdata, sizeof(*pdata));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	return wm831x_device_init(wm831x, spi->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int wm831x_spi_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct wm831x *wm831x = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return wm831x_device_suspend(wm831x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) static int wm831x_spi_poweroff(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	struct wm831x *wm831x = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	wm831x_device_shutdown(wm831x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	return 0;
^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 const struct dev_pm_ops wm831x_spi_pm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	.freeze = wm831x_spi_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	.suspend = wm831x_spi_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	.poweroff = wm831x_spi_poweroff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) static const struct spi_device_id wm831x_spi_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	{ "wm8310", WM8310 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	{ "wm8311", WM8311 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	{ "wm8312", WM8312 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	{ "wm8320", WM8320 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	{ "wm8321", WM8321 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	{ "wm8325", WM8325 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	{ "wm8326", WM8326 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static struct spi_driver wm831x_spi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		.name	= "wm831x",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		.pm	= &wm831x_spi_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		.of_match_table = of_match_ptr(wm831x_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		.suppress_bind_attrs = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	.id_table	= wm831x_spi_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.probe		= wm831x_spi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static int __init wm831x_spi_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	ret = spi_register_driver(&wm831x_spi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		pr_err("Failed to register WM831x SPI driver: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) subsys_initcall(wm831x_spi_init);