]> Git Repo - u-boot.git/blob - drivers/misc/gdsys_rxaui_ctrl.c
Restore patch series "arm: dts: am62-beagleplay: Fix Beagleplay Ethernet"
[u-boot.git] / drivers / misc / gdsys_rxaui_ctrl.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2015
4  * Dirk Eibach,  Guntermann & Drunck GmbH, [email protected]
5  *
6  * (C) Copyright 2017
7  * Mario Six,  Guntermann & Drunck GmbH, [email protected]
8  */
9
10 #include <dm.h>
11 #include <regmap.h>
12 #include <misc.h>
13
14 struct gdsys_rxaui_ctrl_regs {
15         u16 gen_cnt;
16         u16 err_cnt;
17         u16 succ_cnt;
18         u16 status;
19         u16 ctrl_0;
20         u16 ctrl_1;
21 };
22
23 #define rxaui_ctrl_set(map, member, val) \
24         regmap_set(map, struct gdsys_rxaui_ctrl_regs, member, val)
25
26 #define rxaui_ctrl_get(map, member, valp) \
27         regmap_get(map, struct gdsys_rxaui_ctrl_regs, member, valp)
28
29 struct gdsys_rxaui_ctrl_priv {
30         struct regmap *map;
31         bool state;
32 };
33
34 int gdsys_rxaui_set_polarity_inversion(struct udevice *dev, bool val)
35 {
36         struct gdsys_rxaui_ctrl_priv *priv = dev_get_priv(dev);
37         u16 state;
38
39         priv->state = !priv->state;
40
41         rxaui_ctrl_get(priv->map, ctrl_1, &state);
42
43         if (val)
44                 state |= ~0x7800;
45         else
46                 state &= ~0x7800;
47
48         rxaui_ctrl_set(priv->map, ctrl_1, state);
49
50         return !priv->state;
51 }
52
53 static const struct misc_ops gdsys_rxaui_ctrl_ops = {
54         .set_enabled = gdsys_rxaui_set_polarity_inversion,
55 };
56
57 int gdsys_rxaui_ctrl_probe(struct udevice *dev)
58 {
59         struct gdsys_rxaui_ctrl_priv *priv = dev_get_priv(dev);
60
61         regmap_init_mem(dev_ofnode(dev), &priv->map);
62
63         priv->state = false;
64
65         return 0;
66 }
67
68 static const struct udevice_id gdsys_rxaui_ctrl_ids[] = {
69         { .compatible = "gdsys,rxaui_ctrl" },
70         { }
71 };
72
73 U_BOOT_DRIVER(gdsys_rxaui_ctrl) = {
74         .name           = "gdsys_rxaui_ctrl",
75         .id             = UCLASS_MISC,
76         .ops            = &gdsys_rxaui_ctrl_ops,
77         .of_match       = gdsys_rxaui_ctrl_ids,
78         .probe          = gdsys_rxaui_ctrl_probe,
79         .priv_auto      = sizeof(struct gdsys_rxaui_ctrl_priv),
80 };
This page took 0.030335 seconds and 4 git commands to generate.