diff options
| author | Javier <dev.git@javispedro.com> | 2026-10-26 00:50:06 +0100 |
|---|---|---|
| committer | Javier <dev.git@javispedro.com> | 2026-10-26 00:50:06 +0100 |
| commit | 6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a (patch) | |
| tree | e274d41a8dd5e912e20617a937a1fda5af91f8de /linux/ch375lnx.h | |
| parent | 9b1cf601360fb194047e6dcc2af75c2f38c611ec (diff) | |
| download | chu-6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a.tar.gz chu-6b8a368c51082fdd010ef5e1b0be4eb9b5059d1a.zip | |
refactor common parts into inc/ch375.h and add win9x, linux drivers
Diffstat (limited to 'linux/ch375lnx.h')
| -rw-r--r-- | linux/ch375lnx.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/linux/ch375lnx.h b/linux/ch375lnx.h new file mode 100644 index 0000000..e9309a2 --- /dev/null +++ b/linux/ch375lnx.h @@ -0,0 +1,76 @@ +/* + * CHU - IO routines to CH375 from a Linux kernel module + * Copyright (C) 2026 Javier S. Pedro + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <https://www.gnu.org/licenses/>. + */ + +#ifndef CH375LNX_H +#define CH375LNX_H + +#include <linux/types.h> +#include <linux/ioport.h> +#include <asm/io.h> +#define _Packed __attribute__ ((packed)) +typedef enum { + false = 0, + true = 1 +} bool; + +#include <ch375.h> + +struct ch375 { + uint16_t io_base; + uint16_t sec_size; +}; + +static inline uint8_t ch375_read_data(struct ch375 *dev) +{ + return inb(dev->io_base + CH375_PORT_DATA); +} + +static inline void ch375_write_data(struct ch375 *dev, uint8_t data) +{ + outb(data, dev->io_base + CH375_PORT_DATA); +} + +static inline void ch375_send_command(struct ch375 *dev, enum ch375_command cmd) +{ + outb(cmd, dev->io_base + CH375_PORT_CMD); +} + +/// True if interrupt line is currently active (i.e. low) +static inline bool ch375_poll_interrupt(struct ch375 *dev) +{ + return !(inb(dev->io_base + CH375_PORT_CMD) & 0x80); +} + +/** Reads one transfer block (64 bytes max). */ +static uint8_t ch375_read_data_block(struct ch375 *dev, uint8_t *buffer) +{ + uint8_t n = ch375_read_data(dev); + + insb(dev->io_base + CH375_PORT_DATA, buffer, n); + + return n; +} + +static void ch375_write_data_block(struct ch375 *dev, uint8_t * buffer, uint8_t n) +{ + ch375_write_data(dev, n); + + outsb(dev->io_base + CH375_PORT_DATA, buffer, n); +} + +#endif // CH375LNX_H |
