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