blob: d4cd63ca9f89fc8a35bc43d7e91b95f2e312deb3 [file] [log] [blame]
Mario Six7f504a02018-04-27 14:53:33 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * (C) Copyright 2015
4 * Dirk Eibach, Guntermann & Drunck GmbH, eibach@gdsys.de
5 *
6 * (C) Copyright 2017
7 * Mario Six, Guntermann & Drunck GmbH, mario.six@gdsys.cc
8 */
9
Mario Six7f504a02018-04-27 14:53:33 +020010#include <dm.h>
11#include <regmap.h>
12#include <misc.h>
13
14struct 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
29struct gdsys_rxaui_ctrl_priv {
30 struct regmap *map;
Mario Six8f4a3462019-01-28 09:47:41 +010031 bool state;
Mario Six7f504a02018-04-27 14:53:33 +020032};
33
34int 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
Mario Six8f4a3462019-01-28 09:47:41 +010039 priv->state = !priv->state;
40
Mario Six7f504a02018-04-27 14:53:33 +020041 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
Mario Six8f4a3462019-01-28 09:47:41 +010050 return !priv->state;
Mario Six7f504a02018-04-27 14:53:33 +020051}
52
53static const struct misc_ops gdsys_rxaui_ctrl_ops = {
54 .set_enabled = gdsys_rxaui_set_polarity_inversion,
55};
56
57int gdsys_rxaui_ctrl_probe(struct udevice *dev)
58{
59 struct gdsys_rxaui_ctrl_priv *priv = dev_get_priv(dev);
60
Mario Six941f7ea2019-01-28 09:47:42 +010061 regmap_init_mem(dev_ofnode(dev), &priv->map);
Mario Six7f504a02018-04-27 14:53:33 +020062
Mario Six8f4a3462019-01-28 09:47:41 +010063 priv->state = false;
64
Mario Six7f504a02018-04-27 14:53:33 +020065 return 0;
66}
67
68static const struct udevice_id gdsys_rxaui_ctrl_ids[] = {
69 { .compatible = "gdsys,rxaui_ctrl" },
70 { }
71};
72
73U_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,
Simon Glass8a2b47f2020-12-03 16:55:17 -070079 .priv_auto = sizeof(struct gdsys_rxaui_ctrl_priv),
Mario Six7f504a02018-04-27 14:53:33 +020080};