drivers/macintosh/windfarm_smu_sat.c

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

File Facts

System
Linux kernel
Corpus path
drivers/macintosh/windfarm_smu_sat.c
Extension
.c
Size
8335 bytes
Lines
362
Domain
Driver Families
Bucket
drivers/macintosh
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 wf_sat {
	struct kref		ref;
	int			nr;
	struct mutex		mutex;
	unsigned long		last_read; /* jiffies when cache last updated */
	u8			cache[16];
	struct list_head	sensors;
	struct i2c_client	*i2c;
	struct device_node	*node;
};

static struct wf_sat *sats[2];

struct wf_sat_sensor {
	struct list_head	link;
	int			index;
	int			index2;		/* used for power sensors */
	int			shift;
	struct wf_sat		*sat;
	struct wf_sensor 	sens;
};

#define wf_to_sat(c)	container_of(c, struct wf_sat_sensor, sens)

struct smu_sdbp_header *smu_sat_get_sdb_partition(unsigned int sat_id, int id,
						  unsigned int *size)
{
	struct wf_sat *sat;
	int err;
	unsigned int i, len;
	u8 *buf;
	u8 data[4];

	/* TODO: Add the resulting partition to the device-tree */

	if (sat_id > 1 || (sat = sats[sat_id]) == NULL)
		return NULL;

	err = i2c_smbus_write_word_data(sat->i2c, 8, id << 8);
	if (err) {
		printk(KERN_ERR "smu_sat_get_sdb_part wr error %d\n", err);
		return NULL;
	}

	err = i2c_smbus_read_word_data(sat->i2c, 9);
	if (err < 0) {
		printk(KERN_ERR "smu_sat_get_sdb_part rd len error\n");
		return NULL;
	}
	len = err;
	if (len == 0) {
		printk(KERN_ERR "smu_sat_get_sdb_part no partition %x\n", id);
		return NULL;
	}

	len = le16_to_cpu(len);
	len = (len + 3) & ~3;
	buf = kmalloc(len, GFP_KERNEL);
	if (buf == NULL)
		return NULL;

	for (i = 0; i < len; i += 4) {
		err = i2c_smbus_read_i2c_block_data(sat->i2c, 0xa, 4, data);
		if (err < 0) {
			printk(KERN_ERR "smu_sat_get_sdb_part rd err %d\n",
			       err);
			goto fail;
		}
		buf[i] = data[1];
		buf[i+1] = data[0];
		buf[i+2] = data[3];
		buf[i+3] = data[2];
	}

	printk(KERN_DEBUG "sat %d partition %x:", sat_id, id);
	print_hex_dump(KERN_DEBUG, "  ", DUMP_PREFIX_OFFSET,
		       16, 1, buf, len, false);
	if (size)
		*size = len;
	return (struct smu_sdbp_header *) buf;

 fail:
	kfree(buf);
	return NULL;
}
EXPORT_SYMBOL_GPL(smu_sat_get_sdb_partition);

/* refresh the cache */
static int wf_sat_read_cache(struct wf_sat *sat)
{

Annotation

Implementation Notes