1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright 2026, Beijing ESWIN Computing Technology Co., Ltd..
4 * All rights reserved.
5 *
6 * ESWIN EIC7700 HSP Reset Driver
7 *
8 * Authors: Xuyang Dong <dongxuyang@eswincomputing.com>
9 */
10
11 #include <linux/auxiliary_bus.h>
12 #include <linux/device.h>
13 #include <linux/module.h>
14 #include <linux/regmap.h>
15 #include <linux/reset-controller.h>
16
17 #include <dt-bindings/reset/eswin,eic7700-hspcrg.h>
18
19 /**
20 * struct eic7700_hsp_reset_data - reset controller information structure
21 * @rcdev: reset controller entity
22 * @regmap: regmap handle containing the memory-mapped reset registers
23 */
24 struct eic7700_hsp_reset_data {
25 struct reset_controller_dev rcdev;
26 struct regmap *regmap;
27 };
28
29 struct eic7700_hsp_reg {
30 u32 reg;
31 u32 bit;
32 bool active_low;
33 };
34
35 static inline struct eic7700_hsp_reset_data *
to_eic7700_hsp_reset(struct reset_controller_dev * rcdev)36 to_eic7700_hsp_reset(struct reset_controller_dev *rcdev)
37 {
38 return container_of(rcdev, struct eic7700_hsp_reset_data, rcdev);
39 }
40
41 static const struct eic7700_hsp_reg eic7700_hsp_reset[] = {
42 [EIC7700_HSP_RST_SATA_P0] = {0x340, BIT(0), false},
43 [EIC7700_HSP_RST_SATA_PHY] = {0x340, BIT(1), false},
44 [EIC7700_HSP_RST_USB0] = {0x800, BIT(24), true},
45 [EIC7700_HSP_RST_USB1] = {0x900, BIT(24), true},
46 [EIC7700_HSP_RST_USB0_PHY] = {0x800, BIT(25), false},
47 [EIC7700_HSP_RST_USB1_PHY] = {0x900, BIT(25), false},
48 };
49
eic7700_hsp_reset_assert(struct reset_controller_dev * rcdev,unsigned long id)50 static int eic7700_hsp_reset_assert(struct reset_controller_dev *rcdev,
51 unsigned long id)
52 {
53 struct eic7700_hsp_reset_data *data = to_eic7700_hsp_reset(rcdev);
54
55 return regmap_assign_bits(data->regmap, eic7700_hsp_reset[id].reg,
56 eic7700_hsp_reset[id].bit,
57 !eic7700_hsp_reset[id].active_low);
58 }
59
eic7700_hsp_reset_deassert(struct reset_controller_dev * rcdev,unsigned long id)60 static int eic7700_hsp_reset_deassert(struct reset_controller_dev *rcdev,
61 unsigned long id)
62 {
63 struct eic7700_hsp_reset_data *data = to_eic7700_hsp_reset(rcdev);
64
65 return regmap_assign_bits(data->regmap, eic7700_hsp_reset[id].reg,
66 eic7700_hsp_reset[id].bit,
67 eic7700_hsp_reset[id].active_low);
68 }
69
70 static const struct reset_control_ops eic7700_hsp_reset_ops = {
71 .assert = eic7700_hsp_reset_assert,
72 .deassert = eic7700_hsp_reset_deassert,
73 };
74
eic7700_hsp_reset_probe(struct auxiliary_device * adev,const struct auxiliary_device_id * id)75 static int eic7700_hsp_reset_probe(struct auxiliary_device *adev,
76 const struct auxiliary_device_id *id)
77 {
78 struct eic7700_hsp_reset_data *data;
79 struct device *dev = &adev->dev;
80
81 data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
82 if (!data)
83 return -ENOMEM;
84
85 data->regmap = dev_get_regmap(dev->parent, NULL);
86 if (!data->regmap)
87 return dev_err_probe(dev, -ENODEV, "failed to get regmap!\n");
88
89 data->rcdev.owner = THIS_MODULE;
90 data->rcdev.ops = &eic7700_hsp_reset_ops;
91 data->rcdev.of_node = dev->parent->of_node;
92 data->rcdev.dev = dev;
93 data->rcdev.nr_resets = ARRAY_SIZE(eic7700_hsp_reset);
94
95 return devm_reset_controller_register(dev, &data->rcdev);
96 }
97
98 static const struct auxiliary_device_id eic7700_hsp_reset_ids[] = {
99 { .name = "clk_eic7700_hsp.hsp-reset", },
100 { /* sentinel */ }
101 };
102 MODULE_DEVICE_TABLE(auxiliary, eic7700_hsp_reset_ids);
103
104 static struct auxiliary_driver eic7700_hsp_reset_driver = {
105 .probe = eic7700_hsp_reset_probe,
106 .id_table = eic7700_hsp_reset_ids,
107 };
108
109 module_auxiliary_driver(eic7700_hsp_reset_driver);
110
111 MODULE_LICENSE("GPL");
112 MODULE_AUTHOR("Xuyang Dong <dongxuyang@eswincomputing.com>");
113 MODULE_DESCRIPTION("ESWIN EIC7700 HSP Reset Controller Driver");
114