Mario Six | 7f504a0 | 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 | |
Mario Six | 7f504a0 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 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; |
Mario Six | 8f4a346 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 31 | bool state; |
Mario Six | 7f504a0 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 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 | |
Mario Six | 8f4a346 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 39 | priv->state = !priv->state; |
| 40 | |
Mario Six | 7f504a0 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 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 | |
Mario Six | 8f4a346 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 50 | return !priv->state; |
Mario Six | 7f504a0 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 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 | |
Mario Six | 941f7ea | 2019-01-28 09:47:42 +0100 | [diff] [blame] | 61 | regmap_init_mem(dev_ofnode(dev), &priv->map); |
Mario Six | 7f504a0 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 62 | |
Mario Six | 8f4a346 | 2019-01-28 09:47:41 +0100 | [diff] [blame] | 63 | priv->state = false; |
| 64 | |
Mario Six | 7f504a0 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 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, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 79 | .priv_auto = sizeof(struct gdsys_rxaui_ctrl_priv), |
Mario Six | 7f504a0 | 2018-04-27 14:53:33 +0200 | [diff] [blame] | 80 | }; |