drivers/ata/pata_parport/friq.c

Source file repositories/reference/linux-study-clean/drivers/ata/pata_parport/friq.c

File Facts

System
Linux kernel
Corpus path
drivers/ata/pata_parport/friq.c
Extension
.c
Size
5637 bytes
Lines
265
Domain
Driver Families
Bucket
drivers/ata
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * (c) 1998    Grant R. Guenther <grant@torque.net>
 *
 * friq.c is a low-level protocol driver for the Freecom "IQ"
 * parallel port IDE adapter.   Early versions of this adapter
 * use the 'frpw' protocol.
 *
 * Freecom uses this adapter in a battery powered external
 * CD-ROM drive.  It is also used in LS-120 drives by
 * Maxell and Panasonic, and other devices.
 *
 * The battery powered drive requires software support to
 * control the power to the drive.  This module enables the
 * drive power when the high level driver (pcd) is loaded
 * and disables it when the module is unloaded.  Note, if
 * the friq module is built in to the kernel, the power
 * will never be switched off, so other means should be
 * used to conserve battery power.
 */

#include <linux/module.h>
#include <linux/init.h>
#include <linux/delay.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/wait.h>
#include <asm/io.h>
#include "pata_parport.h"

#define CMD(x)							\
	do {							\
		w2(4); w0(0xff); w0(0xff); w0(0x73); w0(0x73);	\
		w0(0xc9); w0(0xc9); w0(0x26);			\
		w0(0x26); w0(x); w0(x);				\
	} while (0)

#define j44(l, h)	(((l >> 4) & 0x0f) | (h & 0xf0))

/*
 * cont = 0 - access the IDE register file
 * cont = 1 - access the IDE command set
 */
static int cont_map[2] = { 0x08, 0x10 };

static int friq_read_regr(struct pi_adapter *pi, int cont, int regr)
{
	int h, l, r;

	r = regr + cont_map[cont];

	CMD(r);
	w2(6); l = r1();
	w2(4); h = r1();
	w2(4);

	return j44(l, h);
}

static void friq_write_regr(struct pi_adapter *pi, int cont, int regr, int val)
{
	int r = regr + cont_map[cont];

	CMD(r);
	w0(val);
	w2(5); w2(7); w2(5); w2(4);
}

static void friq_read_block_int(struct pi_adapter *pi, char *buf, int count, int regr)
{
	int h, l, k, ph;

	switch (pi->mode) {
	case 0:
		CMD(regr);
		for (k = 0; k < count; k++) {
			w2(6); l = r1();
			w2(4); h = r1();
			buf[k] = j44(l, h);
		}
		w2(4);
		break;
	case 1:
		ph = 2;
		CMD(regr + 0xc0);
		w0(0xff);
		for (k = 0; k < count; k++) {
			w2(0xa4 + ph);
			buf[k] = r0();
			ph = 2 - ph;

Annotation

Implementation Notes