⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 via-pmu.c

📁 linux和2410结合开发 用他可以生成2410所需的zImage文件
💻 C
📖 第 1 页 / 共 5 页
字号:
	return PBOOK_SLEEP_OK;}#endif /* CONFIG_PM */intpmu_register_sleep_notifier(struct pmu_sleep_notifier *n){	struct list_head *list;	struct pmu_sleep_notifier *notifier;	for (list = sleep_notifiers.next; list != &sleep_notifiers;	     list = list->next) {		notifier = list_entry(list, struct pmu_sleep_notifier, list);		if (n->priority > notifier->priority)			break;	}	__list_add(&n->list, list->prev, list);	return 0;}intpmu_unregister_sleep_notifier(struct pmu_sleep_notifier* n){	if (n->list.next == 0)		return -ENOENT;	list_del(&n->list);	n->list.next = 0;	return 0;}/* Sleep is broadcast last-to-first */static intbroadcast_sleep(int when, int fallback){	int ret = PBOOK_SLEEP_OK;	struct list_head *list;	struct pmu_sleep_notifier *notifier;	for (list = sleep_notifiers.prev; list != &sleep_notifiers;	     list = list->prev) {		notifier = list_entry(list, struct pmu_sleep_notifier, list);		ret = notifier->notifier_call(notifier, when);		if (ret != PBOOK_SLEEP_OK) {			printk(KERN_DEBUG "sleep %d rejected by %p (%p)\n",			       when, notifier, notifier->notifier_call);			for (; list != &sleep_notifiers; list = list->next) {				notifier = list_entry(list, struct pmu_sleep_notifier, list);				notifier->notifier_call(notifier, fallback);			}			return ret;		}	}	return ret;}/* Wake is broadcast first-to-last */static intbroadcast_wake(void){	int ret = PBOOK_SLEEP_OK;	struct list_head *list;	struct pmu_sleep_notifier *notifier;	for (list = sleep_notifiers.next; list != &sleep_notifiers;	     list = list->next) {		notifier = list_entry(list, struct pmu_sleep_notifier, list);		notifier->notifier_call(notifier, PBOOK_WAKE);	}	return ret;}/* * This struct is used to store config register values for * PCI devices which may get powered off when we sleep. */static struct pci_save {#ifndef HACKED_PCI_SAVE	u16	command;	u16	cache_lat;	u16	intr;	u32	rom_address;#else	u32	config[16];#endif	} *pbook_pci_saves;static int n_pbook_pci_saves;static void __openfirmwarepbook_pci_save(void){	int npci;	struct pci_dev *pd;	struct pci_save *ps;	npci = 0;	pci_for_each_dev(pd) {		++npci;	}	n_pbook_pci_saves = npci;	if (npci == 0)		return;	ps = (struct pci_save *) kmalloc(npci * sizeof(*ps), GFP_KERNEL);	pbook_pci_saves = ps;	if (ps == NULL)		return;	pci_for_each_dev(pd) {#ifndef HACKED_PCI_SAVE		pci_read_config_word(pd, PCI_COMMAND, &ps->command);		pci_read_config_word(pd, PCI_CACHE_LINE_SIZE, &ps->cache_lat);		pci_read_config_word(pd, PCI_INTERRUPT_LINE, &ps->intr);		pci_read_config_dword(pd, PCI_ROM_ADDRESS, &ps->rom_address);#else		int i;		for (i=1;i<16;i++)			pci_read_config_dword(pd, i<<4, &ps->config[i]);#endif		++ps;	}}/* For this to work, we must take care of a few things: If gmac was enabled * during boot, it will be in the pci dev list. If it's disabled at this point * (and it will probably be), then you can't access it's config space. */static void __openfirmwarepbook_pci_restore(void){	u16 cmd;	struct pci_save *ps = pbook_pci_saves - 1;	struct pci_dev *pd;	int j;	pci_for_each_dev(pd) {#ifdef HACKED_PCI_SAVE		int i;		ps++;		for (i=2;i<16;i++)			pci_write_config_dword(pd, i<<4, ps->config[i]);		pci_write_config_dword(pd, 4, ps->config[1]);#else		if (ps->command == 0)			continue;		pci_read_config_word(pd, PCI_COMMAND, &cmd);		if ((ps->command & ~cmd) == 0)			continue;		switch (pd->hdr_type) {		case PCI_HEADER_TYPE_NORMAL:			for (j = 0; j < 6; ++j)				pci_write_config_dword(pd,					PCI_BASE_ADDRESS_0 + j*4,					pd->resource[j].start);			pci_write_config_dword(pd, PCI_ROM_ADDRESS,				ps->rom_address);			pci_write_config_word(pd, PCI_CACHE_LINE_SIZE,				ps->cache_lat);			pci_write_config_word(pd, PCI_INTERRUPT_LINE,				ps->intr);			pci_write_config_word(pd, PCI_COMMAND, ps->command);			break;		}#endif		}}#ifdef DEBUG_SLEEP/* N.B. This doesn't work on the 3400 */voidpmu_blink(int n){	struct adb_request req;	memset(&req, 0, sizeof(req));	for (; n > 0; --n) {		req.nbytes = 4;		req.done = NULL;		req.data[0] = 0xee;		req.data[1] = 4;		req.data[2] = 0;		req.data[3] = 1;		req.reply[0] = ADB_RET_OK;		req.reply_len = 1;		req.reply_expected = 0;		pmu_polled_request(&req);		mdelay(50);		req.nbytes = 4;		req.done = NULL;		req.data[0] = 0xee;		req.data[1] = 4;		req.data[2] = 0;		req.data[3] = 0;		req.reply[0] = ADB_RET_OK;		req.reply_len = 1;		req.reply_expected = 0;		pmu_polled_request(&req);		mdelay(50);	}	mdelay(50);}#endif/* * Put the powerbook to sleep. */ static u32 save_via[8];static void save_via_state(void){	save_via[0] = in_8(&via[ANH]);	save_via[1] = in_8(&via[DIRA]);	save_via[2] = in_8(&via[B]);	save_via[3] = in_8(&via[DIRB]);	save_via[4] = in_8(&via[PCR]);	save_via[5] = in_8(&via[ACR]);	save_via[6] = in_8(&via[T1CL]);	save_via[7] = in_8(&via[T1CH]);}static void restore_via_state(void){	out_8(&via[ANH], save_via[0]);	out_8(&via[DIRA], save_via[1]);	out_8(&via[B], save_via[2]);	out_8(&via[DIRB], save_via[3]);	out_8(&via[PCR], save_via[4]);	out_8(&via[ACR], save_via[5]);	out_8(&via[T1CL], save_via[6]);	out_8(&via[T1CH], save_via[7]);	out_8(&via[IER], IER_CLR | 0x7f);	/* disable all intrs */	out_8(&via[IFR], 0x7f);				/* clear IFR */	out_8(&via[IER], IER_SET | SR_INT | CB1_INT);}static inline void wakeup_decrementer(void){	set_dec(tb_ticks_per_jiffy);	/* No currently-supported powerbook has a 601,	 * so use get_tbl, not native	 */	last_jiffy_stamp(0) = tb_last_stamp = get_tbl();}#define	GRACKLE_PM	(1<<7)#define GRACKLE_DOZE	(1<<5)#define	GRACKLE_NAP	(1<<4)#define	GRACKLE_SLEEP	(1<<3)int __openfirmware powerbook_sleep_G3(void){	unsigned long save_l2cr;	unsigned long wait;	unsigned short pmcr1;	struct adb_request req;	int ret, timeout;	struct pci_dev *grackle;	grackle = pci_find_slot(0, 0);	if (!grackle)		return -ENODEV;	/* Notify device drivers */	ret = broadcast_sleep(PBOOK_SLEEP_REQUEST, PBOOK_SLEEP_REJECT);	if (ret != PBOOK_SLEEP_OK) {		printk("pmu: sleep rejected\n");		return -EBUSY;	}	/* Sync the disks. */	/* XXX It would be nice to have some way to ensure that	 * nobody is dirtying any new buffers while we wait.	 * BenH: Moved to _after_ sleep request and changed video	 * drivers to vmalloc() during sleep request. This way, all	 * vmalloc's are done before actual sleep of block drivers */	fsync_dev(0);	/* Give the disks a little time to actually finish writing */	for (wait = jiffies + (HZ/2); time_before(jiffies, wait); )		mb();	/* Sleep can fail now. May not be very robust but useful for debugging */	ret = broadcast_sleep(PBOOK_SLEEP_NOW, PBOOK_WAKE);	if (ret != PBOOK_SLEEP_OK) {		printk("pmu: sleep failed\n");		return -EBUSY;	}	/* Wait for completion of async backlight requests */	while (!bright_req_1.complete || !bright_req_2.complete ||		!bright_req_3.complete || !batt_req.complete)		pmu_poll();		/* Turn off various things. Darwin does some retry tests here... */	pmu_request(&req, NULL, 2, PMU_POWER_CTRL0, PMU_POW0_OFF|PMU_POW0_HARD_DRIVE);	while (!req.complete)		pmu_poll();	pmu_request(&req, NULL, 2, PMU_POWER_CTRL,		PMU_POW_OFF|PMU_POW_BACKLIGHT|PMU_POW_IRLED|PMU_POW_MEDIABAY);	while (!req.complete)		pmu_poll();	/* Disable all interrupts */	pmac_sleep_save_intrs(-1);	/* Make sure the PMU is idle */	while (pmu_state != idle)		pmu_poll();	/* Make sure the decrementer won't interrupt us */	asm volatile("mtdec %0" : : "r" (0x7fffffff));	/* Make sure any pending DEC interrupt occuring while we did	 * the above didn't re-enable the DEC */	mb();	asm volatile("mtdec %0" : : "r" (0x7fffffff));		/* Giveup the FPU */	if (current->thread.regs && (current->thread.regs->msr & MSR_FP) != 0)		giveup_fpu(current);	/* We can now disable MSR_EE */	cli();	/* For 750, save backside cache setting and disable it */	save_l2cr = _get_L2CR();	/* (returns 0 if not 750) */	if (save_l2cr)		_set_L2CR(0);	/* Ask the PMU to put us to sleep */	pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');	while (!req.complete)		pmu_poll();	/* The VIA is supposed not to be restored correctly*/	save_via_state();	/* We shut down some HW */	pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,1);	pci_read_config_word(grackle, 0x70, &pmcr1);	/* Apparently, MacOS uses NAP mode for Grackle ??? */	pmcr1 &= ~(GRACKLE_DOZE|GRACKLE_SLEEP); 	pmcr1 |= GRACKLE_PM|GRACKLE_NAP;	pci_write_config_word(grackle, 0x70, pmcr1);	/* Call low-level ASM sleep handler */	low_sleep_handler();	/* We're awake again, stop grackle PM */	pci_read_config_word(grackle, 0x70, &pmcr1);	pmcr1 &= ~(GRACKLE_PM|GRACKLE_DOZE|GRACKLE_SLEEP|GRACKLE_NAP); 	pci_write_config_word(grackle, 0x70, pmcr1);	/* Make sure the PMU is idle */	pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,0);	restore_via_state();		/* Restore L2 cache */	if (save_l2cr) 		_set_L2CR(save_l2cr);		/* Restore userland MMU context */	set_context(current->active_mm->context, current->active_mm->pgd);	/* Power things up */	pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, 0xfc);	while (!req.complete)		pmu_poll();	pmu_request(&req, NULL, 2, PMU_POWER_CTRL0,			PMU_POW0_ON|PMU_POW0_HARD_DRIVE);	while (!req.complete)		pmu_poll();	pmu_request(&req, NULL, 2, PMU_POWER_CTRL,			PMU_POW_ON|PMU_POW_BACKLIGHT|PMU_POW_CHARGER|PMU_POW_IRLED|PMU_POW_MEDIABAY);	while (!req.complete)		pmu_poll();	/* ack all pending interrupts */	timeout = 100000;	interrupt_data[0] = 1;	while (interrupt_data[0] || pmu_state != idle) {		if (--timeout < 0)			break;		if (pmu_state == idle)			adb_int_pending = 1;		via_pmu_interrupt(0, 0, 0);		udelay(10);	}	/* reenable interrupt controller */	pmac_sleep_restore_intrs();	/* Leave some time for HW to settle down */	mdelay(100);	/* Restart jiffies & scheduling */	wakeup_decrementer();	sti();	/* Notify drivers */	broadcast_wake();	return 0;}int __openfirmware powerbook_sleep_Core99(void){	unsigned long save_l2cr;	unsigned long wait;	struct adb_request req;	int ret, timeout;		if (!can_sleep) {		printk(KERN_ERR "Sleep mode not supported on this machine\n");		return -ENOSYS;	}		/* Notify device drivers */	ret = broadcast_sleep(PBOOK_SLEEP_REQUEST, PBOOK_SLEEP_REJECT);	if (ret != PBOOK_SLEEP_OK) {		printk("pmu: sleep rejected\n");		return -EBUSY;	}	/* Sync the disks. */	/* XXX It would be nice to have some way to ensure that	 * nobody is dirtying any new buffers while we wait.	 * BenH: Moved to _after_ sleep request and changed video	 * drivers to vmalloc() during sleep request. This way, all	 * vmalloc's are done before actual sleep of block drivers */	fsync_dev(0);	/* Give the disks a little time to actually finish writing */	for (wait = jiffies + HZ; time_before(jiffies, wait); )		mb();	/* Sleep can fail now. May not be very robust but useful for debugging */	ret = broadcast_sleep(PBOOK_SLEEP_NOW, PBOOK_WAKE);	if (ret != PBOOK_SLEEP_OK) {		printk("pmu: sleep failed\n");		return -EBUSY;	}	/* Wait for completion of async backlight requests */	while (!bright_req_1.complete || !bright_req_2.complete ||		!bright_req_3.complete || !batt_req.complete)		pmu_poll();	/* Tell PMU what events will wake us up */	pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_CLR_WAKEUP_EVENTS,		0xff, 0xff);	while (!req.complete)		pmu_poll();	pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_SET_WAKEUP_EVENTS,		0, PMU_PWR_WAKEUP_KEY |		(option_lid_wakeup ? PMU_PWR_WAKEUP_LID_OPEN : 0));	while (!req.complete)		pmu_poll();			/* Save & disable all interrupts */	openpic_sleep_save_intrs();	/* Make sure the PMU is idle */	while (pmu_state != idle)		pmu_poll();	/* Make sure the decrementer won't interrupt us */	asm volatile("mtdec %0" : : "r" (0x7fffffff));	/* Make sure any pending DEC interrupt occuring while we did	 * the above didn't re-enable the DEC */	mb();	asm volatile("mtdec %0" : : "r" (0x7fffffff));	/* Giveup the FPU & vec */	enable_kernel_fp();#ifdef CONFIG_ALTIVEC	if (cur_cpu_spec[0]->cpu_features & CPU_FTR_ALTIVEC)		enable_kernel_altivec();#endif /* CONFIG_ALTIVEC */	/* We can now disable MSR_EE */	cli();	/* For 750, save backside cache setting and disable it */	save_l2cr = _get_L2CR();	/* (returns 0 if not 750) */	if (save_l2cr)		_set_L2CR(save_l2cr & 0x7fffffff);	/* Save the state of PCI config space for some slots */	//pbook_pci_save();	if (!__fake_sleep) {		/* Ask the PMU to put us to sleep */		pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');		while (!req.complete && pmu_state != idle)			pmu_poll();	}	out_8(&via[B], in_8(&via[B]) | TREQ);	wait_for_ack();	/* The VIA is supposed not to be restored correctly*/	save_via_state();	/* Shut down various ASICs. There's a chance that we can no longer	 * talk to the PMU after this, so I moved it to _after_ sending the	 * sleep command to it. Still need to be checked.	 */	pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -