1 | // SPDX-License-Identifier: GPL-2.0 |
2 | // |
3 | // cs35l45-spi.c -- CS35L45 SPI driver |
4 | // |
5 | // Copyright 2019-2022 Cirrus Logic, Inc. |
6 | // |
7 | // Author: James Schulman <james.schulman@cirrus.com> |
8 | |
9 | #include <linux/device.h> |
10 | #include <linux/module.h> |
11 | #include <linux/regmap.h> |
12 | #include <linux/spi/spi.h> |
13 | |
14 | #include "cs35l45.h" |
15 | |
16 | static int cs35l45_spi_probe(struct spi_device *spi) |
17 | { |
18 | struct cs35l45_private *cs35l45; |
19 | struct device *dev = &spi->dev; |
20 | int ret; |
21 | |
22 | cs35l45 = devm_kzalloc(dev, size: sizeof(struct cs35l45_private), GFP_KERNEL); |
23 | if (cs35l45 == NULL) |
24 | return -ENOMEM; |
25 | |
26 | spi->max_speed_hz = CS35L45_SPI_MAX_FREQ; |
27 | spi_setup(spi); |
28 | |
29 | spi_set_drvdata(spi, data: cs35l45); |
30 | cs35l45->regmap = devm_regmap_init_spi(spi, &cs35l45_spi_regmap); |
31 | if (IS_ERR(ptr: cs35l45->regmap)) { |
32 | ret = PTR_ERR(ptr: cs35l45->regmap); |
33 | dev_err(dev, "Failed to allocate register map: %d\n" , ret); |
34 | return ret; |
35 | } |
36 | |
37 | cs35l45->dev = dev; |
38 | cs35l45->irq = spi->irq; |
39 | cs35l45->bus_type = CONTROL_BUS_SPI; |
40 | |
41 | return cs35l45_probe(cs35l45); |
42 | } |
43 | |
44 | static void cs35l45_spi_remove(struct spi_device *spi) |
45 | { |
46 | struct cs35l45_private *cs35l45 = spi_get_drvdata(spi); |
47 | |
48 | cs35l45_remove(cs35l45); |
49 | } |
50 | |
51 | static const struct of_device_id cs35l45_of_match[] = { |
52 | { .compatible = "cirrus,cs35l45" }, |
53 | {}, |
54 | }; |
55 | MODULE_DEVICE_TABLE(of, cs35l45_of_match); |
56 | |
57 | static const struct spi_device_id cs35l45_id_spi[] = { |
58 | { "cs35l45" , 0 }, |
59 | {} |
60 | }; |
61 | MODULE_DEVICE_TABLE(spi, cs35l45_id_spi); |
62 | |
63 | static struct spi_driver cs35l45_spi_driver = { |
64 | .driver = { |
65 | .name = "cs35l45" , |
66 | .of_match_table = cs35l45_of_match, |
67 | .pm = pm_ptr(&cs35l45_pm_ops), |
68 | }, |
69 | .id_table = cs35l45_id_spi, |
70 | .probe = cs35l45_spi_probe, |
71 | .remove = cs35l45_spi_remove, |
72 | }; |
73 | module_spi_driver(cs35l45_spi_driver); |
74 | |
75 | MODULE_DESCRIPTION("SPI CS35L45 driver" ); |
76 | MODULE_AUTHOR("James Schulman, Cirrus Logic Inc, <james.schulman@cirrus.com>" ); |
77 | MODULE_LICENSE("GPL" ); |
78 | MODULE_IMPORT_NS(SND_SOC_CS35L45); |
79 | |