Angel Pons | 32859fc | 2020-04-02 23:48:27 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Kyösti Mälkki | 3855c01 | 2019-03-03 08:45:19 +0200 | [diff] [blame] | 2 | |
| 3 | #ifndef __DEVICE_PNP_OPS_H__ |
| 4 | #define __DEVICE_PNP_OPS_H__ |
| 5 | |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 6 | #include <stdint.h> |
Angel Pons | 4c466c9 | 2020-06-05 19:00:41 +0200 | [diff] [blame] | 7 | #include <device/pnp.h> |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 8 | |
Kyösti Mälkki | 0f63975 | 2019-09-27 12:01:15 +0300 | [diff] [blame] | 9 | #if ENV_PNP_SIMPLE_DEVICE |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 10 | |
| 11 | static __always_inline void pnp_write_config( |
| 12 | pnp_devfn_t dev, uint8_t reg, uint8_t value) |
| 13 | { |
Angel Pons | 4c466c9 | 2020-06-05 19:00:41 +0200 | [diff] [blame] | 14 | pnp_write_index(dev >> 8, reg, value); |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 15 | } |
| 16 | |
| 17 | static __always_inline uint8_t pnp_read_config( |
| 18 | pnp_devfn_t dev, uint8_t reg) |
| 19 | { |
Angel Pons | 4c466c9 | 2020-06-05 19:00:41 +0200 | [diff] [blame] | 20 | return pnp_read_index(dev >> 8, reg); |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 21 | } |
| 22 | |
Angel Pons | 64a6b6c | 2020-06-05 19:10:03 +0200 | [diff] [blame] | 23 | static __always_inline void pnp_unset_and_set_config( |
| 24 | pnp_devfn_t dev, uint8_t reg, uint8_t unset, uint8_t set) |
| 25 | { |
| 26 | pnp_unset_and_set_index(dev >> 8, reg, unset, set); |
| 27 | } |
| 28 | |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 29 | static __always_inline |
| 30 | void pnp_set_logical_device(pnp_devfn_t dev) |
| 31 | { |
| 32 | unsigned int device = dev & 0xff; |
| 33 | pnp_write_config(dev, 0x07, device); |
| 34 | } |
| 35 | |
| 36 | static __always_inline |
| 37 | void pnp_set_enable(pnp_devfn_t dev, int enable) |
| 38 | { |
Elyes HAOUAS | 79a3de1 | 2020-08-26 19:52:40 +0200 | [diff] [blame] | 39 | pnp_write_config(dev, PNP_IDX_EN, enable?0x1:0x0); |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | static __always_inline |
| 43 | int pnp_read_enable(pnp_devfn_t dev) |
| 44 | { |
Elyes HAOUAS | 79a3de1 | 2020-08-26 19:52:40 +0200 | [diff] [blame] | 45 | return !!pnp_read_config(dev, PNP_IDX_EN); |
Kyösti Mälkki | 3ee8b75 | 2019-03-03 00:35:15 +0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static __always_inline |
| 49 | void pnp_set_iobase(pnp_devfn_t dev, unsigned int index, unsigned int iobase) |
| 50 | { |
| 51 | pnp_write_config(dev, index + 0, (iobase >> 8) & 0xff); |
| 52 | pnp_write_config(dev, index + 1, iobase & 0xff); |
| 53 | } |
| 54 | |
| 55 | static __always_inline |
| 56 | uint16_t pnp_read_iobase(pnp_devfn_t dev, unsigned int index) |
| 57 | { |
| 58 | return ((uint16_t)(pnp_read_config(dev, index)) << 8) |
| 59 | | pnp_read_config(dev, index + 1); |
| 60 | } |
| 61 | |
| 62 | static __always_inline |
| 63 | void pnp_set_irq(pnp_devfn_t dev, unsigned int index, unsigned int irq) |
| 64 | { |
| 65 | pnp_write_config(dev, index, irq); |
| 66 | } |
| 67 | |
| 68 | static __always_inline |
| 69 | void pnp_set_drq(pnp_devfn_t dev, unsigned int index, unsigned int drq) |
| 70 | { |
| 71 | pnp_write_config(dev, index, drq & 0xff); |
| 72 | } |
| 73 | |
Kyösti Mälkki | 0f63975 | 2019-09-27 12:01:15 +0300 | [diff] [blame] | 74 | #endif |
Kyösti Mälkki | 3855c01 | 2019-03-03 08:45:19 +0200 | [diff] [blame] | 75 | |
| 76 | #endif |