Mario Six | 86da8c1 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 1 | // 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 | |
| 15 | struct 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 | |
| 30 | struct gdsys_rxaui_ctrl_priv { |
| 31 | struct regmap *map; |
Mario Six | ca0eab2 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 32 | bool state; |
Mario Six | 86da8c1 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | int 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 Six | ca0eab2 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 40 | priv->state = !priv->state; |
| 41 | |
Mario Six | 86da8c1 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 42 | 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 Six | ca0eab2 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 51 | return !priv->state; |
Mario Six | 86da8c1 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | static const struct misc_ops gdsys_rxaui_ctrl_ops = { |
| 55 | .set_enabled = gdsys_rxaui_set_polarity_inversion, |
| 56 | }; |
| 57 | |
| 58 | int gdsys_rxaui_ctrl_probe(struct udevice *dev) |
| 59 | { |
| 60 | struct gdsys_rxaui_ctrl_priv *priv = dev_get_priv(dev); |
| 61 | |
Mario Six | 935a892 | 2019-01-28 09:47:42 +0100 | [diff] [blame] | 62 | regmap_init_mem(dev_ofnode(dev), &priv->map); |
Mario Six | 86da8c1 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 63 | |
Mario Six | ca0eab2 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 64 | priv->state = false; |
| 65 | |
Mario Six | 86da8c1 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 66 | return 0; |
| 67 | } |
| 68 | |
| 69 | static const struct udevice_id gdsys_rxaui_ctrl_ids[] = { |
| 70 | { .compatible = "gdsys,rxaui_ctrl" }, |
| 71 | { } |
| 72 | }; |
| 73 | |
| 74 | U_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, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 80 | .priv_auto = sizeof(struct gdsys_rxaui_ctrl_priv), |
Mario Six | 86da8c1 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 81 | }; |