Mauro Carvalho Chehab | 4b5e9b3 | 2020-08-17 09:10:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mauro Carvalho Chehab | fb7ba18 | 2021-01-29 20:51:55 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Device driver for regulators in HISI PMIC IC |
| 4 | * |
| 5 | * Copyright (c) 2013 Linaro Ltd. |
| 6 | * Copyright (c) 2011 Hisilicon. |
Mauro Carvalho Chehab | 49bd509 | 2021-07-17 11:58:14 +0200 | [diff] [blame] | 7 | * Copyright (c) 2020-2021 Huawei Technologies Co., Ltd. |
Mauro Carvalho Chehab | fb7ba18 | 2021-01-29 20:51:55 +0100 | [diff] [blame] | 8 | */ |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 9 | |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 10 | #include <linux/mfd/core.h> |
Mauro Carvalho Chehab | 6b94669 | 2020-08-17 09:10:41 +0200 | [diff] [blame] | 11 | #include <linux/module.h> |
Mauro Carvalho Chehab | 6b94669 | 2020-08-17 09:10:41 +0200 | [diff] [blame] | 12 | #include <linux/platform_device.h> |
Mauro Carvalho Chehab | bb3b655 | 2021-07-17 11:58:15 +0200 | [diff] [blame] | 13 | #include <linux/regmap.h> |
Mauro Carvalho Chehab | 6b94669 | 2020-08-17 09:10:41 +0200 | [diff] [blame] | 14 | #include <linux/slab.h> |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 15 | #include <linux/spmi.h> |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 16 | |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 17 | static const struct mfd_cell hi6421v600_devs[] = { |
Mauro Carvalho Chehab | bb3b655 | 2021-07-17 11:58:15 +0200 | [diff] [blame] | 18 | { .name = "hi6421v600-irq", }, |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 19 | { .name = "hi6421v600-regulator", }, |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 20 | }; |
| 21 | |
Mauro Carvalho Chehab | a2e904f | 2021-01-29 20:51:50 +0100 | [diff] [blame] | 22 | static const struct regmap_config regmap_config = { |
Mauro Carvalho Chehab | 5ff96c9 | 2021-06-25 09:46:00 +0200 | [diff] [blame] | 23 | .reg_bits = 16, |
| 24 | .val_bits = BITS_PER_BYTE, |
| 25 | .max_register = 0xffff, |
| 26 | .fast_io = true |
Mauro Carvalho Chehab | fb02e3e | 2021-01-29 20:51:47 +0100 | [diff] [blame] | 27 | }; |
| 28 | |
Mauro Carvalho Chehab | b82d45a | 2021-07-17 11:58:12 +0200 | [diff] [blame] | 29 | static int hi6421_spmi_pmic_probe(struct spmi_device *sdev) |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 30 | { |
Mauro Carvalho Chehab | b82d45a | 2021-07-17 11:58:12 +0200 | [diff] [blame] | 31 | struct device *dev = &sdev->dev; |
Mauro Carvalho Chehab | e68ce0f | 2021-09-02 14:47:48 +0200 | [diff] [blame] | 32 | struct regmap *regmap; |
Mauro Carvalho Chehab | bb3b655 | 2021-07-17 11:58:15 +0200 | [diff] [blame] | 33 | int ret; |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 34 | |
Mauro Carvalho Chehab | e68ce0f | 2021-09-02 14:47:48 +0200 | [diff] [blame] | 35 | regmap = devm_regmap_init_spmi_ext(sdev, ®map_config); |
| 36 | if (IS_ERR(regmap)) |
| 37 | return PTR_ERR(regmap); |
Mauro Carvalho Chehab | fb02e3e | 2021-01-29 20:51:47 +0100 | [diff] [blame] | 38 | |
Mauro Carvalho Chehab | e68ce0f | 2021-09-02 14:47:48 +0200 | [diff] [blame] | 39 | dev_set_drvdata(&sdev->dev, regmap); |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 40 | |
Mauro Carvalho Chehab | b82d45a | 2021-07-17 11:58:12 +0200 | [diff] [blame] | 41 | ret = devm_mfd_add_devices(&sdev->dev, PLATFORM_DEVID_NONE, |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 42 | hi6421v600_devs, ARRAY_SIZE(hi6421v600_devs), |
| 43 | NULL, 0, NULL); |
Mauro Carvalho Chehab | a2e904f | 2021-01-29 20:51:50 +0100 | [diff] [blame] | 44 | if (ret < 0) |
| 45 | dev_err(dev, "Failed to add child devices: %d\n", ret); |
Mauro Carvalho Chehab | 6b94669 | 2020-08-17 09:10:41 +0200 | [diff] [blame] | 46 | |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 47 | return ret; |
| 48 | } |
| 49 | |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 50 | static const struct of_device_id pmic_spmi_id_table[] = { |
Mauro Carvalho Chehab | 9f46c34 | 2020-08-18 16:58:56 +0200 | [diff] [blame] | 51 | { .compatible = "hisilicon,hi6421-spmi" }, |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 52 | { } |
| 53 | }; |
| 54 | MODULE_DEVICE_TABLE(of, pmic_spmi_id_table); |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 55 | |
Mauro Carvalho Chehab | 1eb2784 | 2020-08-17 09:10:38 +0200 | [diff] [blame] | 56 | static struct spmi_driver hi6421_spmi_pmic_driver = { |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 57 | .driver = { |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 58 | .name = "hi6421-spmi-pmic", |
| 59 | .of_match_table = pmic_spmi_id_table, |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 60 | }, |
Mauro Carvalho Chehab | 1eb2784 | 2020-08-17 09:10:38 +0200 | [diff] [blame] | 61 | .probe = hi6421_spmi_pmic_probe, |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 62 | }; |
Mauro Carvalho Chehab | 1eb2784 | 2020-08-17 09:10:38 +0200 | [diff] [blame] | 63 | module_spmi_driver(hi6421_spmi_pmic_driver); |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 64 | |
Mauro Carvalho Chehab | cf0f27b | 2020-08-17 09:10:35 +0200 | [diff] [blame] | 65 | MODULE_DESCRIPTION("HiSilicon Hi6421v600 SPMI PMIC driver"); |
Mayulong | 4524ac5 | 2020-08-17 09:10:30 +0200 | [diff] [blame] | 66 | MODULE_LICENSE("GPL v2"); |