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 | |
| 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; |
| 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 | rxaui_ctrl_get(priv->map, ctrl_1, &state); |
| 40 | |
| 41 | if (val) |
| 42 | state |= ~0x7800; |
| 43 | else |
| 44 | state &= ~0x7800; |
| 45 | |
| 46 | rxaui_ctrl_set(priv->map, ctrl_1, state); |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static const struct misc_ops gdsys_rxaui_ctrl_ops = { |
| 52 | .set_enabled = gdsys_rxaui_set_polarity_inversion, |
| 53 | }; |
| 54 | |
| 55 | int gdsys_rxaui_ctrl_probe(struct udevice *dev) |
| 56 | { |
| 57 | struct gdsys_rxaui_ctrl_priv *priv = dev_get_priv(dev); |
| 58 | |
| 59 | regmap_init_mem(dev, &priv->map); |
| 60 | |
| 61 | return 0; |
| 62 | } |
| 63 | |
| 64 | static const struct udevice_id gdsys_rxaui_ctrl_ids[] = { |
| 65 | { .compatible = "gdsys,rxaui_ctrl" }, |
| 66 | { } |
| 67 | }; |
| 68 | |
| 69 | U_BOOT_DRIVER(gdsys_rxaui_ctrl) = { |
| 70 | .name = "gdsys_rxaui_ctrl", |
| 71 | .id = UCLASS_MISC, |
| 72 | .ops = &gdsys_rxaui_ctrl_ops, |
| 73 | .of_match = gdsys_rxaui_ctrl_ids, |
| 74 | .probe = gdsys_rxaui_ctrl_probe, |
| 75 | .priv_auto_alloc_size = sizeof(struct gdsys_rxaui_ctrl_priv), |
| 76 | }; |