drivers/macintosh/macio-adb.c

Source file repositories/reference/linux-study-clean/drivers/macintosh/macio-adb.c

File Facts

System
Linux kernel
Corpus path
drivers/macintosh/macio-adb.c
Extension
.c
Size
6741 bytes
Lines
289
Domain
Driver Families
Bucket
drivers/macintosh
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

struct preg {
	unsigned char r;
	char pad[15];
};

struct adb_regs {
	struct preg intr;
	struct preg data[9];
	struct preg intr_enb;
	struct preg dcount;
	struct preg error;
	struct preg ctrl;
	struct preg autopoll;
	struct preg active_hi;
	struct preg active_lo;
	struct preg test;
};

/* Bits in intr and intr_enb registers */
#define DFB	1		/* data from bus */
#define TAG	2		/* transfer access grant */

/* Bits in dcount register */
#define HMB	0x0f		/* how many bytes */
#define APD	0x10		/* auto-poll data */

/* Bits in error register */
#define NRE	1		/* no response error */
#define DLE	2		/* data lost error */

/* Bits in ctrl register */
#define TAR	1		/* transfer access request */
#define DTB	2		/* data to bus */
#define CRE	4		/* command response expected */
#define ADB_RST	8		/* ADB reset */

/* Bits in autopoll register */
#define APE	1		/* autopoll enable */

static volatile struct adb_regs __iomem *adb;
static struct adb_request *current_req, *last_req;
static DEFINE_SPINLOCK(macio_lock);

static int macio_probe(void);
static int macio_init(void);
static irqreturn_t macio_adb_interrupt(int irq, void *arg);
static int macio_send_request(struct adb_request *req, int sync);
static int macio_adb_autopoll(int devs);
static void macio_adb_poll(void);
static int macio_adb_reset_bus(void);

struct adb_driver macio_adb_driver = {
	.name         = "MACIO",
	.probe        = macio_probe,
	.init         = macio_init,
	.send_request = macio_send_request,
	.autopoll     = macio_adb_autopoll,
	.poll         = macio_adb_poll,
	.reset_bus    = macio_adb_reset_bus,
};

int macio_probe(void)
{
	struct device_node *np __free(device_node) =
		of_find_compatible_node(NULL, "adb", "chrp,adb0");

	if (np)
		return 0;

	return -ENODEV;
}

int macio_init(void)
{
	struct device_node *adbs __free(device_node) =
		of_find_compatible_node(NULL, "adb", "chrp,adb0");
	struct resource r;
	unsigned int irq;

	if (!adbs)
		return -ENXIO;

	if (of_address_to_resource(adbs, 0, &r))
		return -ENXIO;

	adb = ioremap(r.start, sizeof(struct adb_regs));
	if (!adb)
		return -ENOMEM;

Annotation

Implementation Notes