blob: c56abce4d4c13fafcbc3088adeb59c27b9d7459f [file] [log] [blame]
Mario Six86da8c12018-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
10#include <common.h>
11#include <dm.h>
12#include <regmap.h>
13#include <misc.h>
14
15struct gdsys_rxaui_ctrl_regs {
16 u16 gen_cnt;
17 u16 err_cnt;
18 u16 succ_cnt;
19 u16 status;
20 u16 ctrl_0;
21 u16 ctrl_1;
22};
23
24#define rxaui_ctrl_set(map, member, val) \
25 regmap_set(map, struct gdsys_rxaui_ctrl_regs, member, val)
26
27#define rxaui_ctrl_get(map, member, valp) \
28 regmap_get(map, struct gdsys_rxaui_ctrl_regs, member, valp)
29
30struct gdsys_rxaui_ctrl_priv {
31 struct regmap *map;
Mario Sixca0eab22019-01-28 09:47:41 +010032 bool state;
Mario Six86da8c12018-04-27 14:53:33 +020033};
34
35int gdsys_rxaui_set_polarity_inversion(struct udevice *dev, bool val)
36{
37 struct gdsys_rxaui_ctrl_priv *priv = dev_get_priv(dev);
38 u16 state;
39
Mario Sixca0eab22019-01-28 09:47:41 +010040 priv->state = !priv->state;
41
Mario Six86da8c12018-04-27 14:53:33 +020042 rxaui_ctrl_get(priv->map, ctrl_1, &state);
43
44 if (val)
45 state |= ~0x7800;
46 else
47 state &= ~0x7800;
48
49 rxaui_ctrl_set(priv->map, ctrl_1, state);
50
Mario Sixca0eab22019-01-28 09:47:41 +010051 return !priv->state;
Mario Six86da8c12018-04-27 14:53:33 +020052}
53
54static const struct misc_ops gdsys_rxaui_ctrl_ops = {
55 .set_enabled = gdsys_rxaui_set_polarity_inversion,
56};
57
58int gdsys_rxaui_ctrl_probe(struct udevice *dev)
59{
60 struct gdsys_rxaui_ctrl_priv *priv = dev_get_priv(dev);
61
Mario Six935a8922019-01-28 09:47:42 +010062 regmap_init_mem(dev_ofnode(dev), &priv->map);
Mario Six86da8c12018-04-27 14:53:33 +020063
Mario Sixca0eab22019-01-28 09:47:41 +010064 priv->state = false;
65
Mario Six86da8c12018-04-27 14:53:33 +020066 return 0;
67}
68
69static const struct udevice_id gdsys_rxaui_ctrl_ids[] = {
70 { .compatible = "gdsys,rxaui_ctrl" },
71 { }
72};
73
74U_BOOT_DRIVER(gdsys_rxaui_ctrl) = {
75 .name = "gdsys_rxaui_ctrl",
76 .id = UCLASS_MISC,
77 .ops = &gdsys_rxaui_ctrl_ops,
78 .of_match = gdsys_rxaui_ctrl_ids,
79 .probe = gdsys_rxaui_ctrl_probe,
80 .priv_auto_alloc_size = sizeof(struct gdsys_rxaui_ctrl_priv),
81};