License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 17:07:57 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
2018-07-02 11:21:19 +03:00
|
|
|
* Device driver for the PMU in Apple PowerBooks and PowerMacs.
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* The VIA (versatile interface adapter) interfaces to the PMU,
|
|
|
|
* a 6805 microprocessor core whose primary function is to control
|
|
|
|
* battery charging and system power on the PowerBook 3400 and 2400.
|
|
|
|
* The PMU also controls the ADB (Apple Desktop Bus) which connects
|
|
|
|
* to the keyboard and mouse, as well as the non-volatile RAM
|
|
|
|
* and the RTC (real time clock) chip.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1998 Paul Mackerras and Fabio Riccardi.
|
|
|
|
* Copyright (C) 2001-2002 Benjamin Herrenschmidt
|
2007-12-11 17:25:59 +03:00
|
|
|
* Copyright (C) 2006-2007 Johannes Berg
|
2005-04-17 02:20:36 +04:00
|
|
|
*
|
|
|
|
* THIS DRIVER IS BECOMING A TOTAL MESS !
|
|
|
|
* - Cleanup atomically disabling reply to PMU events after
|
|
|
|
* a sleep or a freq. switch
|
|
|
|
*
|
|
|
|
*/
|
2021-08-02 23:40:32 +03:00
|
|
|
#include <linux/stdarg.h>
|
2010-06-02 16:28:52 +04:00
|
|
|
#include <linux/mutex.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/delay.h>
|
2017-02-02 21:15:33 +03:00
|
|
|
#include <linux/sched/signal.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/blkdev.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/poll.h>
|
|
|
|
#include <linux/adb.h>
|
|
|
|
#include <linux/pmu.h>
|
|
|
|
#include <linux/cuda.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#include <linux/pm.h>
|
|
|
|
#include <linux/proc_fs.h>
|
2009-11-26 23:53:06 +03:00
|
|
|
#include <linux/seq_file.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/device.h>
|
2011-05-20 09:37:22 +04:00
|
|
|
#include <linux/syscore_ops.h>
|
2006-12-07 07:34:23 +03:00
|
|
|
#include <linux/freezer.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/syscalls.h>
|
2007-01-06 03:36:18 +03:00
|
|
|
#include <linux/suspend.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <linux/cpu.h>
|
2010-08-22 10:23:17 +04:00
|
|
|
#include <linux/compat.h>
|
2013-09-17 23:28:33 +04:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
2018-07-02 11:21:19 +03:00
|
|
|
#include <linux/uaccess.h>
|
2020-06-09 07:32:42 +03:00
|
|
|
#include <linux/pgtable.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/sections.h>
|
|
|
|
#include <asm/irq.h>
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_PPC_PMAC
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/pmac_feature.h>
|
2006-01-07 03:41:02 +03:00
|
|
|
#include <asm/pmac_pfunc.h>
|
|
|
|
#include <asm/pmac_low_i2c.h>
|
2018-07-02 11:21:19 +03:00
|
|
|
#include <asm/prom.h>
|
2005-04-17 02:20:36 +04:00
|
|
|
#include <asm/mmu_context.h>
|
|
|
|
#include <asm/cputable.h>
|
|
|
|
#include <asm/time.h>
|
|
|
|
#include <asm/backlight.h>
|
2018-07-02 11:21:19 +03:00
|
|
|
#else
|
|
|
|
#include <asm/macintosh.h>
|
|
|
|
#include <asm/macints.h>
|
|
|
|
#include <asm/mac_via.h>
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-06-26 09:49:55 +04:00
|
|
|
#include "via-pmu-event.h"
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Some compile options */
|
2007-12-11 17:25:59 +03:00
|
|
|
#undef DEBUG_SLEEP
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* How many iterations between battery polls */
|
|
|
|
#define BATTERY_POLLING_COUNT 2
|
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
static DEFINE_MUTEX(pmu_info_proc_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* VIA registers - spaced 0x200 bytes apart */
|
|
|
|
#define RS 0x200 /* skip between registers */
|
|
|
|
#define B 0 /* B-side data */
|
|
|
|
#define A RS /* A-side data */
|
|
|
|
#define DIRB (2*RS) /* B-side direction (1=output) */
|
|
|
|
#define DIRA (3*RS) /* A-side direction (1=output) */
|
|
|
|
#define T1CL (4*RS) /* Timer 1 ctr/latch (low 8 bits) */
|
|
|
|
#define T1CH (5*RS) /* Timer 1 counter (high 8 bits) */
|
|
|
|
#define T1LL (6*RS) /* Timer 1 latch (low 8 bits) */
|
|
|
|
#define T1LH (7*RS) /* Timer 1 latch (high 8 bits) */
|
|
|
|
#define T2CL (8*RS) /* Timer 2 ctr/latch (low 8 bits) */
|
|
|
|
#define T2CH (9*RS) /* Timer 2 counter (high 8 bits) */
|
|
|
|
#define SR (10*RS) /* Shift register */
|
|
|
|
#define ACR (11*RS) /* Auxiliary control register */
|
|
|
|
#define PCR (12*RS) /* Peripheral control register */
|
|
|
|
#define IFR (13*RS) /* Interrupt flag register */
|
|
|
|
#define IER (14*RS) /* Interrupt enable register */
|
|
|
|
#define ANH (15*RS) /* A-side data, no handshake */
|
|
|
|
|
|
|
|
/* Bits in B data register: both active low */
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_PPC_PMAC
|
2005-04-17 02:20:36 +04:00
|
|
|
#define TACK 0x08 /* Transfer acknowledge (input) */
|
|
|
|
#define TREQ 0x10 /* Transfer request (output) */
|
2018-07-02 11:21:19 +03:00
|
|
|
#else
|
|
|
|
#define TACK 0x02
|
|
|
|
#define TREQ 0x04
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Bits in ACR */
|
|
|
|
#define SR_CTRL 0x1c /* Shift register control bits */
|
|
|
|
#define SR_EXT 0x0c /* Shift on external clock */
|
|
|
|
#define SR_OUT 0x10 /* Shift out if 1 */
|
|
|
|
|
|
|
|
/* Bits in IFR and IER */
|
|
|
|
#define IER_SET 0x80 /* set bits in IER */
|
|
|
|
#define IER_CLR 0 /* clear bits in IER */
|
|
|
|
#define SR_INT 0x04 /* Shift register full/empty */
|
|
|
|
#define CB2_INT 0x08
|
|
|
|
#define CB1_INT 0x10 /* transition on CB1 input */
|
|
|
|
|
|
|
|
static volatile enum pmu_state {
|
2018-07-02 11:21:18 +03:00
|
|
|
uninitialized = 0,
|
2005-04-17 02:20:36 +04:00
|
|
|
idle,
|
|
|
|
sending,
|
|
|
|
intack,
|
|
|
|
reading,
|
|
|
|
reading_intr,
|
|
|
|
locked,
|
|
|
|
} pmu_state;
|
|
|
|
|
|
|
|
static volatile enum int_data_state {
|
|
|
|
int_data_empty,
|
|
|
|
int_data_fill,
|
|
|
|
int_data_ready,
|
|
|
|
int_data_flush
|
|
|
|
} int_data_state[2] = { int_data_empty, int_data_empty };
|
|
|
|
|
|
|
|
static struct adb_request *current_req;
|
|
|
|
static struct adb_request *last_req;
|
|
|
|
static struct adb_request *req_awaiting_reply;
|
|
|
|
static unsigned char interrupt_data[2][32];
|
|
|
|
static int interrupt_data_len[2];
|
|
|
|
static int int_data_last;
|
|
|
|
static unsigned char *reply_ptr;
|
|
|
|
static int data_index;
|
|
|
|
static int data_len;
|
|
|
|
static volatile int adb_int_pending;
|
|
|
|
static volatile int disable_poll;
|
|
|
|
static int pmu_kind = PMU_UNKNOWN;
|
2007-02-10 23:35:12 +03:00
|
|
|
static int pmu_fully_inited;
|
2005-04-17 02:20:36 +04:00
|
|
|
static int pmu_has_adb;
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_PPC_PMAC
|
2018-07-02 11:21:18 +03:00
|
|
|
static volatile unsigned char __iomem *via1;
|
|
|
|
static volatile unsigned char __iomem *via2;
|
2018-07-02 11:21:19 +03:00
|
|
|
static struct device_node *vias;
|
2005-11-23 09:57:25 +03:00
|
|
|
static struct device_node *gpio_node;
|
2018-07-02 11:21:19 +03:00
|
|
|
#endif
|
2007-02-10 23:35:12 +03:00
|
|
|
static unsigned char __iomem *gpio_reg;
|
2016-09-06 14:53:24 +03:00
|
|
|
static int gpio_irq = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
static int gpio_irq_enabled = -1;
|
2007-02-10 23:35:12 +03:00
|
|
|
static volatile int pmu_suspended;
|
2005-04-17 02:20:36 +04:00
|
|
|
static spinlock_t pmu_lock;
|
|
|
|
static u8 pmu_intr_mask;
|
|
|
|
static int pmu_version;
|
|
|
|
static int drop_interrupts;
|
2007-12-11 17:25:59 +03:00
|
|
|
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
|
2005-04-17 02:20:36 +04:00
|
|
|
static int option_lid_wakeup = 1;
|
2007-12-11 17:25:59 +03:00
|
|
|
#endif /* CONFIG_SUSPEND && CONFIG_PPC32 */
|
2005-04-17 02:20:36 +04:00
|
|
|
static unsigned long async_req_locks;
|
2018-07-02 11:21:19 +03:00
|
|
|
|
|
|
|
#define NUM_IRQ_STATS 13
|
|
|
|
static unsigned int pmu_irq_stats[NUM_IRQ_STATS];
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
static struct proc_dir_entry *proc_pmu_root;
|
|
|
|
static struct proc_dir_entry *proc_pmu_info;
|
|
|
|
static struct proc_dir_entry *proc_pmu_irqstats;
|
|
|
|
static struct proc_dir_entry *proc_pmu_options;
|
|
|
|
static int option_server_mode;
|
|
|
|
|
|
|
|
int pmu_battery_count;
|
2021-04-07 15:58:03 +03:00
|
|
|
static int pmu_cur_battery;
|
2007-02-10 23:40:00 +03:00
|
|
|
unsigned int pmu_power_flags = PMU_PWR_AC_PRESENT;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct pmu_battery_info pmu_batteries[PMU_MAX_BATTERIES];
|
|
|
|
static int query_batt_timer = BATTERY_POLLING_COUNT;
|
|
|
|
static struct adb_request batt_req;
|
|
|
|
static struct proc_dir_entry *proc_pmu_batt[PMU_MAX_BATTERIES];
|
|
|
|
|
|
|
|
int asleep;
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADB
|
2007-02-10 23:35:12 +03:00
|
|
|
static int adb_dev_map;
|
2005-04-17 02:20:36 +04:00
|
|
|
static int pmu_adb_flags;
|
|
|
|
|
|
|
|
static int pmu_probe(void);
|
|
|
|
static int pmu_init(void);
|
|
|
|
static int pmu_send_request(struct adb_request *req, int sync);
|
|
|
|
static int pmu_adb_autopoll(int devs);
|
|
|
|
static int pmu_adb_reset_bus(void);
|
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
|
|
|
|
static int init_pmu(void);
|
|
|
|
static void pmu_start(void);
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
static irqreturn_t via_pmu_interrupt(int irq, void *arg);
|
|
|
|
static irqreturn_t gpio1_interrupt(int irq, void *arg);
|
2018-05-15 16:57:23 +03:00
|
|
|
static int pmu_info_proc_show(struct seq_file *m, void *v);
|
|
|
|
static int pmu_irqstats_proc_show(struct seq_file *m, void *v);
|
|
|
|
static int pmu_battery_proc_show(struct seq_file *m, void *v);
|
2005-04-17 02:20:36 +04:00
|
|
|
static void pmu_pass_intr(unsigned char *data, int len);
|
2020-02-04 04:37:17 +03:00
|
|
|
static const struct proc_ops pmu_options_proc_ops;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifdef CONFIG_ADB
|
2018-02-15 00:15:18 +03:00
|
|
|
const struct adb_driver via_pmu_driver = {
|
2018-03-29 03:36:04 +03:00
|
|
|
.name = "PMU",
|
|
|
|
.probe = pmu_probe,
|
|
|
|
.init = pmu_init,
|
|
|
|
.send_request = pmu_send_request,
|
|
|
|
.autopoll = pmu_adb_autopoll,
|
|
|
|
.poll = pmu_poll_adb,
|
|
|
|
.reset_bus = pmu_adb_reset_bus,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
|
|
|
|
extern void low_sleep_handler(void);
|
|
|
|
extern void enable_kernel_altivec(void);
|
|
|
|
extern void enable_kernel_fp(void);
|
|
|
|
|
|
|
|
#ifdef DEBUG_SLEEP
|
|
|
|
int pmu_polled_request(struct adb_request *req);
|
2007-12-11 17:25:59 +03:00
|
|
|
void pmu_blink(int n);
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This table indicates for each PMU opcode:
|
|
|
|
* - the number of data bytes to be sent with the command, or -1
|
|
|
|
* if a length byte should be sent,
|
|
|
|
* - the number of response bytes which the PMU will return, or
|
|
|
|
* -1 if it will send a length byte.
|
|
|
|
*/
|
2005-09-17 19:36:54 +04:00
|
|
|
static const s8 pmu_data_len[256][2] = {
|
2005-04-17 02:20:36 +04:00
|
|
|
/* 0 1 2 3 4 5 6 7 */
|
|
|
|
/*00*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*08*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*10*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*18*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0, 0},
|
|
|
|
/*20*/ {-1, 0},{ 0, 0},{ 2, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*28*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{ 0,-1},
|
|
|
|
/*30*/ { 4, 0},{20, 0},{-1, 0},{ 3, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*38*/ { 0, 4},{ 0,20},{ 2,-1},{ 2, 1},{ 3,-1},{-1,-1},{-1,-1},{ 4, 0},
|
|
|
|
/*40*/ { 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*48*/ { 0, 1},{ 0, 1},{-1,-1},{ 1, 0},{ 1, 0},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*50*/ { 1, 0},{ 0, 0},{ 2, 0},{ 2, 0},{-1, 0},{ 1, 0},{ 3, 0},{ 1, 0},
|
|
|
|
/*58*/ { 0, 1},{ 1, 0},{ 0, 2},{ 0, 2},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*60*/ { 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*68*/ { 0, 3},{ 0, 3},{ 0, 2},{ 0, 8},{ 0,-1},{ 0,-1},{-1,-1},{-1,-1},
|
|
|
|
/*70*/ { 1, 0},{ 1, 0},{ 1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*78*/ { 0,-1},{ 0,-1},{-1,-1},{-1,-1},{-1,-1},{ 5, 1},{ 4, 1},{ 4, 1},
|
|
|
|
/*80*/ { 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*88*/ { 0, 5},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*90*/ { 1, 0},{ 2, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*98*/ { 0, 1},{ 0, 1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*a0*/ { 2, 0},{ 2, 0},{ 2, 0},{ 4, 0},{-1, 0},{ 0, 0},{-1, 0},{-1, 0},
|
|
|
|
/*a8*/ { 1, 1},{ 1, 0},{ 3, 0},{ 2, 0},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*b0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*b8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*c0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*c8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
/*d0*/ { 0, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*d8*/ { 1, 1},{ 1, 1},{-1,-1},{-1,-1},{ 0, 1},{ 0,-1},{-1,-1},{-1,-1},
|
|
|
|
/*e0*/ {-1, 0},{ 4, 0},{ 0, 1},{-1, 0},{-1, 0},{ 4, 0},{-1, 0},{-1, 0},
|
|
|
|
/*e8*/ { 3,-1},{-1,-1},{ 0, 1},{-1,-1},{ 0,-1},{-1,-1},{-1,-1},{ 0, 0},
|
|
|
|
/*f0*/ {-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},{-1, 0},
|
|
|
|
/*f8*/ {-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1},
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *pbook_type[] = {
|
|
|
|
"Unknown PowerBook",
|
|
|
|
"PowerBook 2400/3400/3500(G3)",
|
|
|
|
"PowerBook G3 Series",
|
|
|
|
"1999 PowerBook G3",
|
|
|
|
"Core99"
|
|
|
|
};
|
|
|
|
|
2005-11-23 09:57:25 +03:00
|
|
|
int __init find_via_pmu(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_PPC_PMAC
|
2005-12-13 10:01:21 +03:00
|
|
|
u64 taddr;
|
2006-07-12 09:40:29 +04:00
|
|
|
const u32 *reg;
|
2005-11-23 09:57:25 +03:00
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state != uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
2005-11-23 09:57:25 +03:00
|
|
|
vias = of_find_node_by_name(NULL, "via-pmu");
|
|
|
|
if (vias == NULL)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
|
2007-04-27 07:41:15 +04:00
|
|
|
reg = of_get_property(vias, "reg", NULL);
|
2005-11-23 09:57:25 +03:00
|
|
|
if (reg == NULL) {
|
|
|
|
printk(KERN_ERR "via-pmu: No \"reg\" property !\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
taddr = of_translate_address(vias, reg);
|
2005-11-30 08:54:12 +03:00
|
|
|
if (taddr == OF_BAD_ADDR) {
|
2005-11-23 09:57:25 +03:00
|
|
|
printk(KERN_ERR "via-pmu: Can't translate address !\n");
|
|
|
|
goto fail;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&pmu_lock);
|
|
|
|
|
|
|
|
pmu_has_adb = 1;
|
|
|
|
|
|
|
|
pmu_intr_mask = PMU_INT_PCEJECT |
|
|
|
|
PMU_INT_SNDBRT |
|
|
|
|
PMU_INT_ADB |
|
|
|
|
PMU_INT_TICK;
|
|
|
|
|
2018-12-05 22:50:28 +03:00
|
|
|
if (of_node_name_eq(vias->parent, "ohare") ||
|
|
|
|
of_device_is_compatible(vias->parent, "ohare"))
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_kind = PMU_OHARE_BASED;
|
2007-05-03 11:26:52 +04:00
|
|
|
else if (of_device_is_compatible(vias->parent, "paddington"))
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_kind = PMU_PADDINGTON_BASED;
|
2007-05-03 11:26:52 +04:00
|
|
|
else if (of_device_is_compatible(vias->parent, "heathrow"))
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_kind = PMU_HEATHROW_BASED;
|
2007-05-03 11:26:52 +04:00
|
|
|
else if (of_device_is_compatible(vias->parent, "Keylargo")
|
|
|
|
|| of_device_is_compatible(vias->parent, "K2-Keylargo")) {
|
2005-11-23 09:57:25 +03:00
|
|
|
struct device_node *gpiop;
|
2007-04-24 07:51:59 +04:00
|
|
|
struct device_node *adbp;
|
2005-12-13 10:01:21 +03:00
|
|
|
u64 gaddr = OF_BAD_ADDR;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
pmu_kind = PMU_KEYLARGO_BASED;
|
2007-04-24 07:51:59 +04:00
|
|
|
adbp = of_find_node_by_type(NULL, "adb");
|
|
|
|
pmu_has_adb = (adbp != NULL);
|
|
|
|
of_node_put(adbp);
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_intr_mask = PMU_INT_PCEJECT |
|
|
|
|
PMU_INT_SNDBRT |
|
|
|
|
PMU_INT_ADB |
|
|
|
|
PMU_INT_TICK |
|
|
|
|
PMU_INT_ENVIRONMENT;
|
|
|
|
|
2005-11-23 09:57:25 +03:00
|
|
|
gpiop = of_find_node_by_name(NULL, "gpio");
|
|
|
|
if (gpiop) {
|
2007-04-27 07:41:15 +04:00
|
|
|
reg = of_get_property(gpiop, "reg", NULL);
|
2005-11-23 09:57:25 +03:00
|
|
|
if (reg)
|
|
|
|
gaddr = of_translate_address(gpiop, reg);
|
2005-12-13 10:01:21 +03:00
|
|
|
if (gaddr != OF_BAD_ADDR)
|
2005-11-23 09:57:25 +03:00
|
|
|
gpio_reg = ioremap(gaddr, 0x10);
|
2014-09-17 02:00:54 +04:00
|
|
|
of_node_put(gpiop);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2006-09-27 00:28:36 +04:00
|
|
|
if (gpio_reg == NULL) {
|
2005-11-23 09:57:25 +03:00
|
|
|
printk(KERN_ERR "via-pmu: Can't find GPIO reg !\n");
|
2014-09-17 02:00:53 +04:00
|
|
|
goto fail;
|
2006-09-27 00:28:36 +04:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
} else
|
|
|
|
pmu_kind = PMU_UNKNOWN;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
via1 = via2 = ioremap(taddr, 0x2000);
|
|
|
|
if (via1 == NULL) {
|
2005-11-23 09:57:25 +03:00
|
|
|
printk(KERN_ERR "via-pmu: Can't map address !\n");
|
2014-09-17 02:00:53 +04:00
|
|
|
goto fail_via_remap;
|
2005-11-23 09:57:25 +03:00
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via1[IER], IER_CLR | 0x7f); /* disable all intrs */
|
|
|
|
out_8(&via1[IFR], 0x7f); /* clear IFR */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
pmu_state = idle;
|
|
|
|
|
2014-09-17 02:00:53 +04:00
|
|
|
if (!init_pmu())
|
|
|
|
goto fail_init;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
sys_ctrler = SYS_CTRLER_PMU;
|
|
|
|
|
|
|
|
return 1;
|
2014-09-17 02:00:53 +04:00
|
|
|
|
|
|
|
fail_init:
|
2018-07-02 11:21:18 +03:00
|
|
|
iounmap(via1);
|
|
|
|
via1 = via2 = NULL;
|
2014-09-17 02:00:53 +04:00
|
|
|
fail_via_remap:
|
2006-09-27 00:28:36 +04:00
|
|
|
iounmap(gpio_reg);
|
|
|
|
gpio_reg = NULL;
|
2014-09-17 02:00:53 +04:00
|
|
|
fail:
|
|
|
|
of_node_put(vias);
|
2005-11-23 09:57:25 +03:00
|
|
|
vias = NULL;
|
2018-07-02 11:21:18 +03:00
|
|
|
pmu_state = uninitialized;
|
2005-11-23 09:57:25 +03:00
|
|
|
return 0;
|
2018-07-02 11:21:19 +03:00
|
|
|
#else
|
|
|
|
if (macintosh_config->adb_type != MAC_ADB_PB2)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
pmu_kind = PMU_UNKNOWN;
|
|
|
|
|
|
|
|
spin_lock_init(&pmu_lock);
|
|
|
|
|
|
|
|
pmu_has_adb = 1;
|
|
|
|
|
|
|
|
pmu_intr_mask = PMU_INT_PCEJECT |
|
|
|
|
PMU_INT_SNDBRT |
|
|
|
|
PMU_INT_ADB |
|
|
|
|
PMU_INT_TICK;
|
|
|
|
|
|
|
|
pmu_state = idle;
|
|
|
|
|
|
|
|
if (!init_pmu()) {
|
|
|
|
pmu_state = uninitialized;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
#endif /* !CONFIG_PPC_PMAC */
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_ADB
|
2005-11-23 09:57:25 +03:00
|
|
|
static int pmu_probe(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
return pmu_state == uninitialized ? -ENODEV : 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
static int pmu_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
return pmu_state == uninitialized ? -ENODEV : 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can't wait until pmu_init gets called, that happens too late.
|
|
|
|
* It happens after IDE and SCSI initialization, which can take a few
|
|
|
|
* seconds, and by that time the PMU could have given up on us and
|
|
|
|
* turned us off.
|
|
|
|
* Thus this is called with arch_initcall rather than device_initcall.
|
|
|
|
*/
|
|
|
|
static int __init via_pmu_start(void)
|
|
|
|
{
|
2018-07-02 11:21:19 +03:00
|
|
|
unsigned int __maybe_unused irq;
|
2006-07-03 15:36:01 +04:00
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
batt_req.complete = 1;
|
|
|
|
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_PPC_PMAC
|
2006-07-03 15:36:01 +04:00
|
|
|
irq = irq_of_parse_and_map(vias, 0);
|
2016-09-06 14:53:24 +03:00
|
|
|
if (!irq) {
|
2007-08-13 00:38:34 +04:00
|
|
|
printk(KERN_ERR "via-pmu: can't map interrupt\n");
|
2006-07-03 15:36:01 +04:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2010-07-29 14:16:34 +04:00
|
|
|
/* We set IRQF_NO_SUSPEND because we don't want the interrupt
|
|
|
|
* to be disabled between the 2 passes of driver suspend, we
|
|
|
|
* control our own disabling for that one
|
2009-10-09 15:27:54 +04:00
|
|
|
*/
|
2010-07-29 14:16:34 +04:00
|
|
|
if (request_irq(irq, via_pmu_interrupt, IRQF_NO_SUSPEND,
|
|
|
|
"VIA-PMU", (void *)0)) {
|
2006-07-03 15:36:01 +04:00
|
|
|
printk(KERN_ERR "via-pmu: can't request irq %d\n", irq);
|
|
|
|
return -ENODEV;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-11-23 09:57:25 +03:00
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED) {
|
|
|
|
gpio_node = of_find_node_by_name(NULL, "extint-gpio1");
|
|
|
|
if (gpio_node == NULL)
|
|
|
|
gpio_node = of_find_node_by_name(NULL,
|
|
|
|
"pmu-interrupt");
|
2006-07-03 15:36:01 +04:00
|
|
|
if (gpio_node)
|
|
|
|
gpio_irq = irq_of_parse_and_map(gpio_node, 0);
|
2005-11-23 09:57:25 +03:00
|
|
|
|
2016-09-06 14:53:24 +03:00
|
|
|
if (gpio_irq) {
|
2015-11-11 17:15:03 +03:00
|
|
|
if (request_irq(gpio_irq, gpio1_interrupt,
|
|
|
|
IRQF_NO_SUSPEND, "GPIO1 ADB",
|
|
|
|
(void *)0))
|
2005-11-23 09:57:25 +03:00
|
|
|
printk(KERN_ERR "pmu: can't get irq %d"
|
|
|
|
" (GPIO1)\n", gpio_irq);
|
|
|
|
else
|
|
|
|
gpio_irq_enabled = 1;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable interrupts */
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via1[IER], IER_SET | SR_INT | CB1_INT);
|
2018-07-02 11:21:19 +03:00
|
|
|
#else
|
|
|
|
if (request_irq(IRQ_MAC_ADB_SR, via_pmu_interrupt, IRQF_NO_SUSPEND,
|
|
|
|
"VIA-PMU-SR", NULL)) {
|
|
|
|
pr_err("%s: couldn't get SR irq\n", __func__);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
if (request_irq(IRQ_MAC_ADB_CL, via_pmu_interrupt, IRQF_NO_SUSPEND,
|
|
|
|
"VIA-PMU-CL", NULL)) {
|
|
|
|
pr_err("%s: couldn't get CL irq\n", __func__);
|
|
|
|
free_irq(IRQ_MAC_ADB_SR, NULL);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
#endif /* !CONFIG_PPC_PMAC */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
pmu_fully_inited = 1;
|
|
|
|
|
|
|
|
/* Make sure PMU settle down before continuing. This is _very_ important
|
|
|
|
* since the IDE probe may shut interrupts down for quite a bit of time. If
|
|
|
|
* a PMU communication is pending while this happens, the PMU may timeout
|
|
|
|
* Not that on Core99 machines, the PMU keeps sending us environement
|
|
|
|
* messages, we should find a way to either fix IDE or make it call
|
|
|
|
* pmu_suspend() before masking interrupts. This can also happens while
|
|
|
|
* scolling with some fbdevs.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
pmu_poll();
|
|
|
|
} while (pmu_state != idle);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
arch_initcall(via_pmu_start);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This has to be done after pci_init, which is a subsys_initcall.
|
|
|
|
*/
|
|
|
|
static int __init via_pmu_dev_init(void)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
#ifdef CONFIG_PMAC_BACKLIGHT
|
2006-06-25 16:47:08 +04:00
|
|
|
/* Initialize backlight */
|
2006-07-30 14:04:19 +04:00
|
|
|
pmu_backlight_init();
|
2006-06-25 16:47:08 +04:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-06-28 01:36:34 +04:00
|
|
|
#ifdef CONFIG_PPC32
|
2010-02-02 07:34:14 +03:00
|
|
|
if (of_machine_is_compatible("AAPL,3400/2400") ||
|
|
|
|
of_machine_is_compatible("AAPL,3500")) {
|
2005-04-17 02:20:36 +04:00
|
|
|
int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
|
|
|
|
NULL, PMAC_MB_INFO_MODEL, 0);
|
|
|
|
pmu_battery_count = 1;
|
|
|
|
if (mb == PMAC_TYPE_COMET)
|
|
|
|
pmu_batteries[0].flags |= PMU_BATT_TYPE_COMET;
|
|
|
|
else
|
|
|
|
pmu_batteries[0].flags |= PMU_BATT_TYPE_HOOPER;
|
2010-02-02 07:34:14 +03:00
|
|
|
} else if (of_machine_is_compatible("AAPL,PowerBook1998") ||
|
|
|
|
of_machine_is_compatible("PowerBook1,1")) {
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_battery_count = 2;
|
|
|
|
pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART;
|
|
|
|
pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
|
|
|
|
} else {
|
2007-04-24 07:53:04 +04:00
|
|
|
struct device_node* prim =
|
|
|
|
of_find_node_by_name(NULL, "power-mgt");
|
2006-07-12 09:40:29 +04:00
|
|
|
const u32 *prim_info = NULL;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (prim)
|
2007-04-27 07:41:15 +04:00
|
|
|
prim_info = of_get_property(prim, "prim-info", NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (prim_info) {
|
|
|
|
/* Other stuffs here yet unknown */
|
|
|
|
pmu_battery_count = (prim_info[6] >> 16) & 0xff;
|
|
|
|
pmu_batteries[0].flags |= PMU_BATT_TYPE_SMART;
|
|
|
|
if (pmu_battery_count > 1)
|
|
|
|
pmu_batteries[1].flags |= PMU_BATT_TYPE_SMART;
|
|
|
|
}
|
2007-04-24 07:53:04 +04:00
|
|
|
of_node_put(prim);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-06-28 01:36:34 +04:00
|
|
|
#endif /* CONFIG_PPC32 */
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Create /proc/pmu */
|
|
|
|
proc_pmu_root = proc_mkdir("pmu", NULL);
|
|
|
|
if (proc_pmu_root) {
|
2005-06-28 01:36:34 +04:00
|
|
|
long i;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
for (i=0; i<pmu_battery_count; i++) {
|
|
|
|
char title[16];
|
2005-06-28 01:36:34 +04:00
|
|
|
sprintf(title, "battery_%ld", i);
|
2018-05-15 16:57:23 +03:00
|
|
|
proc_pmu_batt[i] = proc_create_single_data(title, 0,
|
|
|
|
proc_pmu_root, pmu_battery_proc_show,
|
|
|
|
(void *)i);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2018-05-15 16:57:23 +03:00
|
|
|
proc_pmu_info = proc_create_single("info", 0, proc_pmu_root,
|
|
|
|
pmu_info_proc_show);
|
|
|
|
proc_pmu_irqstats = proc_create_single("interrupts", 0,
|
|
|
|
proc_pmu_root, pmu_irqstats_proc_show);
|
2009-11-26 23:53:06 +03:00
|
|
|
proc_pmu_options = proc_create("options", 0600, proc_pmu_root,
|
2020-02-04 04:37:17 +03:00
|
|
|
&pmu_options_proc_ops);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(via_pmu_dev_init);
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static int
|
2005-04-17 02:20:36 +04:00
|
|
|
init_pmu(void)
|
|
|
|
{
|
|
|
|
int timeout;
|
|
|
|
struct adb_request req;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
/* Negate TREQ. Set TACK to input and TREQ to output. */
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via2[B], in_8(&via2[B]) | TREQ);
|
|
|
|
out_8(&via2[DIRB], (in_8(&via2[DIRB]) | TREQ) & ~TACK);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
|
|
|
|
timeout = 100000;
|
|
|
|
while (!req.complete) {
|
|
|
|
if (--timeout < 0) {
|
|
|
|
printk(KERN_ERR "init_pmu: no response from PMU\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
udelay(10);
|
|
|
|
pmu_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ack all pending interrupts */
|
|
|
|
timeout = 100000;
|
|
|
|
interrupt_data[0][0] = 1;
|
|
|
|
while (interrupt_data[0][0] || pmu_state != idle) {
|
|
|
|
if (--timeout < 0) {
|
|
|
|
printk(KERN_ERR "init_pmu: timed out acking intrs\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (pmu_state == idle)
|
|
|
|
adb_int_pending = 1;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
via_pmu_interrupt(0, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
udelay(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Tell PMU we are ready. */
|
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED) {
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2);
|
|
|
|
while (!req.complete)
|
|
|
|
pmu_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read PMU version */
|
|
|
|
pmu_request(&req, NULL, 1, PMU_GET_VERSION);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
if (req.reply_len > 0)
|
|
|
|
pmu_version = req.reply[0];
|
|
|
|
|
|
|
|
/* Read server mode setting */
|
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED) {
|
|
|
|
pmu_request(&req, NULL, 2, PMU_POWER_EVENTS,
|
|
|
|
PMU_PWR_GET_POWERUP_EVENTS);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
if (req.reply_len == 2) {
|
|
|
|
if (req.reply[1] & PMU_PWR_WAKEUP_AC_INSERT)
|
|
|
|
option_server_mode = 1;
|
|
|
|
printk(KERN_INFO "via-pmu: Server Mode is %s\n",
|
|
|
|
option_server_mode ? "enabled" : "disabled");
|
|
|
|
}
|
|
|
|
}
|
2018-07-02 11:21:19 +03:00
|
|
|
|
|
|
|
printk(KERN_INFO "PMU driver v%d initialized for %s, firmware: %02x\n",
|
|
|
|
PMU_DRIVER_VERSION, pbook_type[pmu_kind], pmu_version);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pmu_get_model(void)
|
|
|
|
{
|
|
|
|
return pmu_kind;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pmu_set_server_mode(int server_mode)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
if (pmu_kind != PMU_KEYLARGO_BASED)
|
|
|
|
return;
|
|
|
|
|
|
|
|
option_server_mode = server_mode;
|
|
|
|
pmu_request(&req, NULL, 2, PMU_POWER_EVENTS, PMU_PWR_GET_POWERUP_EVENTS);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
if (req.reply_len < 2)
|
|
|
|
return;
|
|
|
|
if (server_mode)
|
|
|
|
pmu_request(&req, NULL, 4, PMU_POWER_EVENTS,
|
|
|
|
PMU_PWR_SET_POWERUP_EVENTS,
|
|
|
|
req.reply[0], PMU_PWR_WAKEUP_AC_INSERT);
|
|
|
|
else
|
|
|
|
pmu_request(&req, NULL, 4, PMU_POWER_EVENTS,
|
|
|
|
PMU_PWR_CLR_POWERUP_EVENTS,
|
|
|
|
req.reply[0], PMU_PWR_WAKEUP_AC_INSERT);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This new version of the code for 2400/3400/3500 powerbooks
|
|
|
|
* is inspired from the implementation in gkrellm-pmu
|
|
|
|
*/
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
2005-04-17 02:20:36 +04:00
|
|
|
done_battery_state_ohare(struct adb_request* req)
|
|
|
|
{
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_PPC_PMAC
|
2005-04-17 02:20:36 +04:00
|
|
|
/* format:
|
|
|
|
* [0] : flags
|
|
|
|
* 0x01 : AC indicator
|
|
|
|
* 0x02 : charging
|
|
|
|
* 0x04 : battery exist
|
|
|
|
* 0x08 :
|
|
|
|
* 0x10 :
|
|
|
|
* 0x20 : full charged
|
|
|
|
* 0x40 : pcharge reset
|
|
|
|
* 0x80 : battery exist
|
|
|
|
*
|
|
|
|
* [1][2] : battery voltage
|
|
|
|
* [3] : CPU temperature
|
|
|
|
* [4] : battery temperature
|
|
|
|
* [5] : current
|
|
|
|
* [6][7] : pcharge
|
|
|
|
* --tkoba
|
|
|
|
*/
|
|
|
|
unsigned int bat_flags = PMU_BATT_TYPE_HOOPER;
|
|
|
|
long pcharge, charge, vb, vmax, lmax;
|
|
|
|
long vmax_charging, vmax_charged;
|
|
|
|
long amperage, voltage, time, max;
|
|
|
|
int mb = pmac_call_feature(PMAC_FTR_GET_MB_INFO,
|
|
|
|
NULL, PMAC_MB_INFO_MODEL, 0);
|
|
|
|
|
|
|
|
if (req->reply[0] & 0x01)
|
|
|
|
pmu_power_flags |= PMU_PWR_AC_PRESENT;
|
|
|
|
else
|
|
|
|
pmu_power_flags &= ~PMU_PWR_AC_PRESENT;
|
|
|
|
|
|
|
|
if (mb == PMAC_TYPE_COMET) {
|
|
|
|
vmax_charged = 189;
|
|
|
|
vmax_charging = 213;
|
|
|
|
lmax = 6500;
|
|
|
|
} else {
|
|
|
|
vmax_charged = 330;
|
|
|
|
vmax_charging = 330;
|
|
|
|
lmax = 6500;
|
|
|
|
}
|
|
|
|
vmax = vmax_charged;
|
|
|
|
|
|
|
|
/* If battery installed */
|
|
|
|
if (req->reply[0] & 0x04) {
|
|
|
|
bat_flags |= PMU_BATT_PRESENT;
|
|
|
|
if (req->reply[0] & 0x02)
|
|
|
|
bat_flags |= PMU_BATT_CHARGING;
|
|
|
|
vb = (req->reply[1] << 8) | req->reply[2];
|
|
|
|
voltage = (vb * 265 + 72665) / 10;
|
|
|
|
amperage = req->reply[5];
|
|
|
|
if ((req->reply[0] & 0x01) == 0) {
|
|
|
|
if (amperage > 200)
|
|
|
|
vb += ((amperage - 200) * 15)/100;
|
|
|
|
} else if (req->reply[0] & 0x02) {
|
|
|
|
vb = (vb * 97) / 100;
|
|
|
|
vmax = vmax_charging;
|
|
|
|
}
|
|
|
|
charge = (100 * vb) / vmax;
|
|
|
|
if (req->reply[0] & 0x40) {
|
|
|
|
pcharge = (req->reply[6] << 8) + req->reply[7];
|
|
|
|
if (pcharge > lmax)
|
|
|
|
pcharge = lmax;
|
|
|
|
pcharge *= 100;
|
|
|
|
pcharge = 100 - pcharge / lmax;
|
|
|
|
if (pcharge < charge)
|
|
|
|
charge = pcharge;
|
|
|
|
}
|
|
|
|
if (amperage > 0)
|
|
|
|
time = (charge * 16440) / amperage;
|
|
|
|
else
|
|
|
|
time = 0;
|
|
|
|
max = 100;
|
|
|
|
amperage = -amperage;
|
|
|
|
} else
|
|
|
|
charge = max = amperage = voltage = time = 0;
|
|
|
|
|
|
|
|
pmu_batteries[pmu_cur_battery].flags = bat_flags;
|
|
|
|
pmu_batteries[pmu_cur_battery].charge = charge;
|
|
|
|
pmu_batteries[pmu_cur_battery].max_charge = max;
|
|
|
|
pmu_batteries[pmu_cur_battery].amperage = amperage;
|
|
|
|
pmu_batteries[pmu_cur_battery].voltage = voltage;
|
|
|
|
pmu_batteries[pmu_cur_battery].time_remaining = time;
|
2018-07-02 11:21:19 +03:00
|
|
|
#endif /* CONFIG_PPC_PMAC */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
clear_bit(0, &async_req_locks);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
2005-04-17 02:20:36 +04:00
|
|
|
done_battery_state_smart(struct adb_request* req)
|
|
|
|
{
|
|
|
|
/* format:
|
|
|
|
* [0] : format of this structure (known: 3,4,5)
|
|
|
|
* [1] : flags
|
|
|
|
*
|
|
|
|
* format 3 & 4:
|
|
|
|
*
|
|
|
|
* [2] : charge
|
|
|
|
* [3] : max charge
|
|
|
|
* [4] : current
|
|
|
|
* [5] : voltage
|
|
|
|
*
|
|
|
|
* format 5:
|
|
|
|
*
|
|
|
|
* [2][3] : charge
|
|
|
|
* [4][5] : max charge
|
|
|
|
* [6][7] : current
|
|
|
|
* [8][9] : voltage
|
|
|
|
*/
|
|
|
|
|
|
|
|
unsigned int bat_flags = PMU_BATT_TYPE_SMART;
|
|
|
|
int amperage;
|
|
|
|
unsigned int capa, max, voltage;
|
|
|
|
|
|
|
|
if (req->reply[1] & 0x01)
|
|
|
|
pmu_power_flags |= PMU_PWR_AC_PRESENT;
|
|
|
|
else
|
|
|
|
pmu_power_flags &= ~PMU_PWR_AC_PRESENT;
|
|
|
|
|
|
|
|
|
|
|
|
capa = max = amperage = voltage = 0;
|
|
|
|
|
|
|
|
if (req->reply[1] & 0x04) {
|
|
|
|
bat_flags |= PMU_BATT_PRESENT;
|
|
|
|
switch(req->reply[0]) {
|
|
|
|
case 3:
|
|
|
|
case 4: capa = req->reply[2];
|
|
|
|
max = req->reply[3];
|
|
|
|
amperage = *((signed char *)&req->reply[4]);
|
|
|
|
voltage = req->reply[5];
|
|
|
|
break;
|
|
|
|
case 5: capa = (req->reply[2] << 8) | req->reply[3];
|
|
|
|
max = (req->reply[4] << 8) | req->reply[5];
|
|
|
|
amperage = *((signed short *)&req->reply[6]);
|
|
|
|
voltage = (req->reply[8] << 8) | req->reply[9];
|
|
|
|
break;
|
|
|
|
default:
|
2013-04-22 07:02:19 +04:00
|
|
|
pr_warn("pmu.c: unrecognized battery info, "
|
|
|
|
"len: %d, %4ph\n", req->reply_len,
|
|
|
|
req->reply);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((req->reply[1] & 0x01) && (amperage > 0))
|
|
|
|
bat_flags |= PMU_BATT_CHARGING;
|
|
|
|
|
|
|
|
pmu_batteries[pmu_cur_battery].flags = bat_flags;
|
|
|
|
pmu_batteries[pmu_cur_battery].charge = capa;
|
|
|
|
pmu_batteries[pmu_cur_battery].max_charge = max;
|
|
|
|
pmu_batteries[pmu_cur_battery].amperage = amperage;
|
|
|
|
pmu_batteries[pmu_cur_battery].voltage = voltage;
|
|
|
|
if (amperage) {
|
|
|
|
if ((req->reply[1] & 0x01) && (amperage > 0))
|
|
|
|
pmu_batteries[pmu_cur_battery].time_remaining
|
|
|
|
= ((max-capa) * 3600) / amperage;
|
|
|
|
else
|
|
|
|
pmu_batteries[pmu_cur_battery].time_remaining
|
|
|
|
= (capa * 3600) / (-amperage);
|
|
|
|
} else
|
|
|
|
pmu_batteries[pmu_cur_battery].time_remaining = 0;
|
|
|
|
|
|
|
|
pmu_cur_battery = (pmu_cur_battery + 1) % pmu_battery_count;
|
|
|
|
|
|
|
|
clear_bit(0, &async_req_locks);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
2005-04-17 02:20:36 +04:00
|
|
|
query_battery_state(void)
|
|
|
|
{
|
|
|
|
if (test_and_set_bit(0, &async_req_locks))
|
|
|
|
return;
|
|
|
|
if (pmu_kind == PMU_OHARE_BASED)
|
|
|
|
pmu_request(&batt_req, done_battery_state_ohare,
|
|
|
|
1, PMU_BATTERY_STATE);
|
|
|
|
else
|
|
|
|
pmu_request(&batt_req, done_battery_state_smart,
|
|
|
|
2, PMU_SMART_BATTERY_STATE, pmu_cur_battery+1);
|
|
|
|
}
|
|
|
|
|
2009-11-26 23:53:06 +03:00
|
|
|
static int pmu_info_proc_show(struct seq_file *m, void *v)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2009-11-26 23:53:06 +03:00
|
|
|
seq_printf(m, "PMU driver version : %d\n", PMU_DRIVER_VERSION);
|
|
|
|
seq_printf(m, "PMU firmware version : %02x\n", pmu_version);
|
|
|
|
seq_printf(m, "AC Power : %d\n",
|
2006-03-14 08:20:42 +03:00
|
|
|
((pmu_power_flags & PMU_PWR_AC_PRESENT) != 0) || pmu_battery_count == 0);
|
2009-11-26 23:53:06 +03:00
|
|
|
seq_printf(m, "Battery count : %d\n", pmu_battery_count);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-26 23:53:06 +03:00
|
|
|
static int pmu_irqstats_proc_show(struct seq_file *m, void *v)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int i;
|
2018-07-02 11:21:19 +03:00
|
|
|
static const char *irq_names[NUM_IRQ_STATS] = {
|
|
|
|
"Unknown interrupt (type 0)",
|
|
|
|
"Unknown interrupt (type 1)",
|
2005-04-17 02:20:36 +04:00
|
|
|
"PC-Card eject button",
|
|
|
|
"Sound/Brightness button",
|
|
|
|
"ADB message",
|
|
|
|
"Battery state change",
|
|
|
|
"Environment interrupt",
|
|
|
|
"Tick timer",
|
|
|
|
"Ghost interrupt (zero len)",
|
|
|
|
"Empty interrupt (empty mask)",
|
2018-07-02 11:21:19 +03:00
|
|
|
"Max irqs in a row",
|
|
|
|
"Total CB1 triggered events",
|
|
|
|
"Total GPIO1 triggered events",
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2018-07-02 11:21:19 +03:00
|
|
|
for (i = 0; i < NUM_IRQ_STATS; i++) {
|
2009-11-26 23:53:06 +03:00
|
|
|
seq_printf(m, " %2u: %10u (%s)\n",
|
2005-04-17 02:20:36 +04:00
|
|
|
i, pmu_irq_stats[i], irq_names[i]);
|
|
|
|
}
|
2009-11-26 23:53:06 +03:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2009-11-26 23:53:06 +03:00
|
|
|
static int pmu_battery_proc_show(struct seq_file *m, void *v)
|
|
|
|
{
|
|
|
|
long batnum = (long)m->private;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-26 23:53:06 +03:00
|
|
|
seq_putc(m, '\n');
|
|
|
|
seq_printf(m, "flags : %08x\n", pmu_batteries[batnum].flags);
|
|
|
|
seq_printf(m, "charge : %d\n", pmu_batteries[batnum].charge);
|
|
|
|
seq_printf(m, "max_charge : %d\n", pmu_batteries[batnum].max_charge);
|
|
|
|
seq_printf(m, "current : %d\n", pmu_batteries[batnum].amperage);
|
|
|
|
seq_printf(m, "voltage : %d\n", pmu_batteries[batnum].voltage);
|
|
|
|
seq_printf(m, "time rem. : %d\n", pmu_batteries[batnum].time_remaining);
|
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2009-11-26 23:53:06 +03:00
|
|
|
static int pmu_options_proc_show(struct seq_file *m, void *v)
|
|
|
|
{
|
2007-12-11 17:25:59 +03:00
|
|
|
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED &&
|
|
|
|
pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
|
2009-11-26 23:53:06 +03:00
|
|
|
seq_printf(m, "lid_wakeup=%d\n", option_lid_wakeup);
|
2005-06-28 01:36:34 +04:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED)
|
2009-11-26 23:53:06 +03:00
|
|
|
seq_printf(m, "server_mode=%d\n", option_server_mode);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-11-26 23:53:06 +03:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2009-11-26 23:53:06 +03:00
|
|
|
|
|
|
|
static int pmu_options_proc_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
return single_open(file, pmu_options_proc_show, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static ssize_t pmu_options_proc_write(struct file *file,
|
|
|
|
const char __user *buffer, size_t count, loff_t *pos)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
char tmp[33];
|
|
|
|
char *label, *val;
|
2009-11-26 23:53:06 +03:00
|
|
|
size_t fcount = count;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (!count)
|
|
|
|
return -EINVAL;
|
|
|
|
if (count > 32)
|
|
|
|
count = 32;
|
|
|
|
if (copy_from_user(tmp, buffer, count))
|
|
|
|
return -EFAULT;
|
|
|
|
tmp[count] = 0;
|
|
|
|
|
|
|
|
label = tmp;
|
|
|
|
while(*label == ' ')
|
|
|
|
label++;
|
|
|
|
val = label;
|
|
|
|
while(*val && (*val != '=')) {
|
|
|
|
if (*val == ' ')
|
|
|
|
*val = 0;
|
|
|
|
val++;
|
|
|
|
}
|
|
|
|
if ((*val) == 0)
|
|
|
|
return -EINVAL;
|
|
|
|
*(val++) = 0;
|
|
|
|
while(*val == ' ')
|
|
|
|
val++;
|
2007-12-11 17:25:59 +03:00
|
|
|
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED &&
|
|
|
|
pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) >= 0)
|
|
|
|
if (!strcmp(label, "lid_wakeup"))
|
|
|
|
option_lid_wakeup = ((*val) == '1');
|
2005-06-28 01:36:34 +04:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED && !strcmp(label, "server_mode")) {
|
|
|
|
int new_value;
|
|
|
|
new_value = ((*val) == '1');
|
|
|
|
if (new_value != option_server_mode)
|
|
|
|
pmu_set_server_mode(new_value);
|
|
|
|
}
|
|
|
|
return fcount;
|
|
|
|
}
|
|
|
|
|
2020-02-04 04:37:17 +03:00
|
|
|
static const struct proc_ops pmu_options_proc_ops = {
|
|
|
|
.proc_open = pmu_options_proc_open,
|
|
|
|
.proc_read = seq_read,
|
|
|
|
.proc_lseek = seq_lseek,
|
|
|
|
.proc_release = single_release,
|
|
|
|
.proc_write = pmu_options_proc_write,
|
2009-11-26 23:53:06 +03:00
|
|
|
};
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef CONFIG_ADB
|
|
|
|
/* Send an ADB command */
|
2009-10-09 15:27:54 +04:00
|
|
|
static int pmu_send_request(struct adb_request *req, int sync)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int i, ret;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized || !pmu_fully_inited) {
|
2005-04-17 02:20:36 +04:00
|
|
|
req->complete = 1;
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
|
|
|
switch (req->data[0]) {
|
|
|
|
case PMU_PACKET:
|
|
|
|
for (i = 0; i < req->nbytes - 1; ++i)
|
|
|
|
req->data[i] = req->data[i+1];
|
|
|
|
--req->nbytes;
|
|
|
|
if (pmu_data_len[req->data[0]][1] != 0) {
|
|
|
|
req->reply[0] = ADB_RET_OK;
|
|
|
|
req->reply_len = 1;
|
|
|
|
} else
|
|
|
|
req->reply_len = 0;
|
|
|
|
ret = pmu_queue_request(req);
|
|
|
|
break;
|
|
|
|
case CUDA_PACKET:
|
|
|
|
switch (req->data[1]) {
|
|
|
|
case CUDA_GET_TIME:
|
|
|
|
if (req->nbytes != 2)
|
|
|
|
break;
|
|
|
|
req->data[0] = PMU_READ_RTC;
|
|
|
|
req->nbytes = 1;
|
|
|
|
req->reply_len = 3;
|
|
|
|
req->reply[0] = CUDA_PACKET;
|
|
|
|
req->reply[1] = 0;
|
|
|
|
req->reply[2] = CUDA_GET_TIME;
|
|
|
|
ret = pmu_queue_request(req);
|
|
|
|
break;
|
|
|
|
case CUDA_SET_TIME:
|
|
|
|
if (req->nbytes != 6)
|
|
|
|
break;
|
|
|
|
req->data[0] = PMU_SET_RTC;
|
|
|
|
req->nbytes = 5;
|
|
|
|
for (i = 1; i <= 4; ++i)
|
|
|
|
req->data[i] = req->data[i+1];
|
|
|
|
req->reply_len = 3;
|
|
|
|
req->reply[0] = CUDA_PACKET;
|
|
|
|
req->reply[1] = 0;
|
|
|
|
req->reply[2] = CUDA_SET_TIME;
|
|
|
|
ret = pmu_queue_request(req);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ADB_PACKET:
|
|
|
|
if (!pmu_has_adb)
|
|
|
|
return -ENXIO;
|
|
|
|
for (i = req->nbytes - 1; i > 1; --i)
|
|
|
|
req->data[i+2] = req->data[i];
|
|
|
|
req->data[3] = req->nbytes - 2;
|
|
|
|
req->data[2] = pmu_adb_flags;
|
|
|
|
/*req->data[1] = req->data[1];*/
|
|
|
|
req->data[0] = PMU_ADB_CMD;
|
|
|
|
req->nbytes += 2;
|
|
|
|
req->reply_expected = 1;
|
|
|
|
req->reply_len = 0;
|
|
|
|
ret = pmu_queue_request(req);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (ret) {
|
|
|
|
req->complete = 1;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sync)
|
|
|
|
while (!req->complete)
|
|
|
|
pmu_poll();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable/disable autopolling */
|
2009-10-09 15:27:54 +04:00
|
|
|
static int __pmu_adb_autopoll(int devs)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
if (devs) {
|
|
|
|
pmu_request(&req, NULL, 5, PMU_ADB_CMD, 0, 0x86,
|
|
|
|
adb_dev_map >> 8, adb_dev_map);
|
|
|
|
pmu_adb_flags = 2;
|
|
|
|
} else {
|
|
|
|
pmu_request(&req, NULL, 1, PMU_ADB_POLL_OFF);
|
|
|
|
pmu_adb_flags = 0;
|
|
|
|
}
|
|
|
|
while (!req.complete)
|
|
|
|
pmu_poll();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-09 15:27:54 +04:00
|
|
|
static int pmu_adb_autopoll(int devs)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb)
|
2009-10-09 15:27:54 +04:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
adb_dev_map = devs;
|
|
|
|
return __pmu_adb_autopoll(devs);
|
|
|
|
}
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Reset the ADB bus */
|
2009-10-09 15:27:54 +04:00
|
|
|
static int pmu_adb_reset_bus(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
int save_autopoll = adb_dev_map;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized || !pmu_fully_inited || !pmu_has_adb)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
/* anyone got a better idea?? */
|
2009-10-09 15:27:54 +04:00
|
|
|
__pmu_adb_autopoll(0);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2009-10-09 15:27:54 +04:00
|
|
|
req.nbytes = 4;
|
2005-04-17 02:20:36 +04:00
|
|
|
req.done = NULL;
|
|
|
|
req.data[0] = PMU_ADB_CMD;
|
2009-10-09 15:27:54 +04:00
|
|
|
req.data[1] = ADB_BUSRESET;
|
|
|
|
req.data[2] = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
req.data[3] = 0;
|
|
|
|
req.data[4] = 0;
|
|
|
|
req.reply_len = 0;
|
|
|
|
req.reply_expected = 1;
|
|
|
|
if (pmu_queue_request(&req) != 0) {
|
|
|
|
printk(KERN_ERR "pmu_adb_reset_bus: pmu_queue_request failed\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
|
|
|
|
if (save_autopoll != 0)
|
2009-10-09 15:27:54 +04:00
|
|
|
__pmu_adb_autopoll(save_autopoll);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
|
|
|
|
/* Construct and send a pmu request */
|
2005-09-17 19:36:54 +04:00
|
|
|
int
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_request(struct adb_request *req, void (*done)(struct adb_request *),
|
|
|
|
int nbytes, ...)
|
|
|
|
{
|
|
|
|
va_list list;
|
|
|
|
int i;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
if (nbytes < 0 || nbytes > 32) {
|
|
|
|
printk(KERN_ERR "pmu_request: bad nbytes (%d)\n", nbytes);
|
|
|
|
req->complete = 1;
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
req->nbytes = nbytes;
|
|
|
|
req->done = done;
|
|
|
|
va_start(list, nbytes);
|
|
|
|
for (i = 0; i < nbytes; ++i)
|
|
|
|
req->data[i] = va_arg(list, int);
|
|
|
|
va_end(list);
|
|
|
|
req->reply_len = 0;
|
|
|
|
req->reply_expected = 0;
|
|
|
|
return pmu_queue_request(req);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
int
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_queue_request(struct adb_request *req)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int nsend;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized) {
|
2005-04-17 02:20:36 +04:00
|
|
|
req->complete = 1;
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
if (req->nbytes <= 0) {
|
|
|
|
req->complete = 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
nsend = pmu_data_len[req->data[0]][0];
|
|
|
|
if (nsend >= 0 && req->nbytes != nsend + 1) {
|
|
|
|
req->complete = 1;
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->next = NULL;
|
|
|
|
req->sent = 0;
|
|
|
|
req->complete = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
2018-04-13 21:41:43 +03:00
|
|
|
if (current_req) {
|
2005-04-17 02:20:36 +04:00
|
|
|
last_req->next = req;
|
|
|
|
last_req = req;
|
|
|
|
} else {
|
|
|
|
current_req = req;
|
|
|
|
last_req = req;
|
|
|
|
if (pmu_state == idle)
|
|
|
|
pmu_start();
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
wait_for_ack(void)
|
|
|
|
{
|
|
|
|
/* Sightly increased the delay, I had one occurrence of the message
|
|
|
|
* reported
|
|
|
|
*/
|
|
|
|
int timeout = 4000;
|
2018-07-02 11:21:18 +03:00
|
|
|
while ((in_8(&via2[B]) & TACK) == 0) {
|
2005-04-17 02:20:36 +04:00
|
|
|
if (--timeout < 0) {
|
|
|
|
printk(KERN_ERR "PMU not responding (!ack)\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
udelay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* New PMU seems to be very sensitive to those timings, so we make sure
|
|
|
|
* PCI is flushed immediately */
|
|
|
|
static inline void
|
|
|
|
send_byte(int x)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via1[ACR], in_8(&via1[ACR]) | SR_OUT | SR_EXT);
|
|
|
|
out_8(&via1[SR], x);
|
|
|
|
out_8(&via2[B], in_8(&via2[B]) & ~TREQ); /* assert TREQ */
|
|
|
|
(void)in_8(&via2[B]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
recv_byte(void)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via1[ACR], (in_8(&via1[ACR]) & ~SR_OUT) | SR_EXT);
|
|
|
|
in_8(&via1[SR]); /* resets SR */
|
|
|
|
out_8(&via2[B], in_8(&via2[B]) & ~TREQ);
|
|
|
|
(void)in_8(&via2[B]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
pmu_done(struct adb_request *req)
|
|
|
|
{
|
|
|
|
void (*done)(struct adb_request *) = req->done;
|
|
|
|
mb();
|
|
|
|
req->complete = 1;
|
|
|
|
/* Here, we assume that if the request has a done member, the
|
|
|
|
* struct request will survive to setting req->complete to 1
|
|
|
|
*/
|
|
|
|
if (done)
|
|
|
|
(*done)(req);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_start(void)
|
|
|
|
{
|
|
|
|
struct adb_request *req;
|
|
|
|
|
|
|
|
/* assert pmu_state == idle */
|
|
|
|
/* get the packet to send */
|
|
|
|
req = current_req;
|
2018-04-13 21:41:43 +03:00
|
|
|
if (!req || pmu_state != idle
|
2005-04-17 02:20:36 +04:00
|
|
|
|| (/*req->reply_expected && */req_awaiting_reply))
|
|
|
|
return;
|
|
|
|
|
|
|
|
pmu_state = sending;
|
|
|
|
data_index = 1;
|
|
|
|
data_len = pmu_data_len[req->data[0]][0];
|
|
|
|
|
|
|
|
/* Sounds safer to make sure ACK is high before writing. This helped
|
|
|
|
* kill a problem with ADB and some iBooks
|
|
|
|
*/
|
|
|
|
wait_for_ack();
|
|
|
|
/* set the shift register to shift out and send a byte */
|
|
|
|
send_byte(req->data[0]);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_poll(void)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
if (disable_poll)
|
|
|
|
return;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
via_pmu_interrupt(0, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_poll_adb(void)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
if (disable_poll)
|
|
|
|
return;
|
|
|
|
/* Kicks ADB read when PMU is suspended */
|
|
|
|
adb_int_pending = 1;
|
|
|
|
do {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
via_pmu_interrupt(0, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
} while (pmu_suspended && (adb_int_pending || pmu_state != idle
|
|
|
|
|| req_awaiting_reply));
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_wait_complete(struct adb_request *req)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
while((pmu_state != idle && pmu_state != locked) || !req->complete)
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
via_pmu_interrupt(0, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* This function loops until the PMU is idle and prevents it from
|
|
|
|
* anwsering to ADB interrupts. pmu_request can still be called.
|
|
|
|
* This is done to avoid spurrious shutdowns when we know we'll have
|
|
|
|
* interrupts switched off for a long time
|
|
|
|
*/
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_suspend(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2007-11-13 22:08:32 +03:00
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
|
|
|
pmu_suspended++;
|
|
|
|
if (pmu_suspended > 1) {
|
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
if (req_awaiting_reply)
|
|
|
|
adb_int_pending = 1;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
via_pmu_interrupt(0, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
|
|
|
if (!adb_int_pending && pmu_state == idle && !req_awaiting_reply) {
|
|
|
|
if (gpio_irq >= 0)
|
|
|
|
disable_irq_nosync(gpio_irq);
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via1[IER], CB1_INT | IER_CLR);
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_resume(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized || pmu_suspended < 1)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
|
|
|
pmu_suspended--;
|
|
|
|
if (pmu_suspended > 0) {
|
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
adb_int_pending = 1;
|
|
|
|
if (gpio_irq >= 0)
|
|
|
|
enable_irq(gpio_irq);
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via1[IER], CB1_INT | IER_SET);
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
pmu_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Interrupt data could be the result data from an ADB cmd */
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
pmu_handle_data(unsigned char *data, int len)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-02 11:21:19 +03:00
|
|
|
unsigned char ints;
|
|
|
|
int idx;
|
2005-04-17 02:20:36 +04:00
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
asleep = 0;
|
|
|
|
if (drop_interrupts || len < 1) {
|
|
|
|
adb_int_pending = 0;
|
|
|
|
pmu_irq_stats[8]++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get PMU interrupt mask */
|
|
|
|
ints = data[0];
|
|
|
|
|
|
|
|
/* Record zero interrupts for stats */
|
|
|
|
if (ints == 0)
|
|
|
|
pmu_irq_stats[9]++;
|
|
|
|
|
|
|
|
/* Hack to deal with ADB autopoll flag */
|
|
|
|
if (ints & PMU_INT_ADB)
|
|
|
|
ints &= ~(PMU_INT_ADB_AUTO | PMU_INT_AUTO_SRQ_POLL);
|
|
|
|
|
|
|
|
next:
|
|
|
|
if (ints == 0) {
|
|
|
|
if (i > pmu_irq_stats[10])
|
|
|
|
pmu_irq_stats[10] = i;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
i++;
|
2018-07-02 11:21:19 +03:00
|
|
|
|
|
|
|
idx = ffs(ints) - 1;
|
|
|
|
ints &= ~BIT(idx);
|
|
|
|
|
|
|
|
pmu_irq_stats[idx]++;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Note: for some reason, we get an interrupt with len=1,
|
|
|
|
* data[0]==0 after each normal ADB interrupt, at least
|
|
|
|
* on the Pismo. Still investigating... --BenH
|
|
|
|
*/
|
2018-07-02 11:21:19 +03:00
|
|
|
switch (BIT(idx)) {
|
|
|
|
case PMU_INT_ADB:
|
2005-04-17 02:20:36 +04:00
|
|
|
if ((data[0] & PMU_INT_ADB_AUTO) == 0) {
|
|
|
|
struct adb_request *req = req_awaiting_reply;
|
2018-04-13 21:41:43 +03:00
|
|
|
if (!req) {
|
2005-04-17 02:20:36 +04:00
|
|
|
printk(KERN_ERR "PMU: extra ADB reply\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
req_awaiting_reply = NULL;
|
|
|
|
if (len <= 2)
|
|
|
|
req->reply_len = 0;
|
|
|
|
else {
|
|
|
|
memcpy(req->reply, data + 1, len - 1);
|
|
|
|
req->reply_len = len - 1;
|
|
|
|
}
|
|
|
|
pmu_done(req);
|
|
|
|
} else {
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_XMON
|
2005-04-17 02:20:36 +04:00
|
|
|
if (len == 4 && data[1] == 0x2c) {
|
|
|
|
extern int xmon_wants_key, xmon_adb_keycode;
|
|
|
|
if (xmon_wants_key) {
|
|
|
|
xmon_adb_keycode = data[2];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-07-02 11:21:19 +03:00
|
|
|
#endif /* CONFIG_XMON */
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef CONFIG_ADB
|
|
|
|
/*
|
|
|
|
* XXX On the [23]400 the PMU gives us an up
|
|
|
|
* event for keycodes 0x74 or 0x75 when the PC
|
|
|
|
* card eject buttons are released, so we
|
|
|
|
* ignore those events.
|
|
|
|
*/
|
|
|
|
if (!(pmu_kind == PMU_OHARE_BASED && len == 4
|
|
|
|
&& data[1] == 0x2c && data[3] == 0xff
|
|
|
|
&& (data[2] & ~1) == 0xf4))
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
adb_input(data+1, len-1, 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
#endif /* CONFIG_ADB */
|
|
|
|
}
|
2018-07-02 11:21:19 +03:00
|
|
|
break;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Sound/brightness button pressed */
|
2018-07-02 11:21:19 +03:00
|
|
|
case PMU_INT_SNDBRT:
|
2005-04-17 02:20:36 +04:00
|
|
|
#ifdef CONFIG_PMAC_BACKLIGHT
|
|
|
|
if (len == 3)
|
2006-07-30 14:04:19 +04:00
|
|
|
pmac_backlight_set_legacy_brightness_pmu(data[1] >> 4);
|
|
|
|
#endif
|
2018-07-02 11:21:19 +03:00
|
|
|
break;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Tick interrupt */
|
2018-07-02 11:21:19 +03:00
|
|
|
case PMU_INT_TICK:
|
|
|
|
/* Environment or tick interrupt, query batteries */
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pmu_battery_count) {
|
|
|
|
if ((--query_batt_timer) == 0) {
|
|
|
|
query_battery_state();
|
|
|
|
query_batt_timer = BATTERY_POLLING_COUNT;
|
|
|
|
}
|
|
|
|
}
|
2018-07-02 11:21:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PMU_INT_ENVIRONMENT:
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pmu_battery_count)
|
|
|
|
query_battery_state();
|
|
|
|
pmu_pass_intr(data, len);
|
2006-06-26 09:49:55 +04:00
|
|
|
/* len == 6 is probably a bad check. But how do I
|
|
|
|
* know what PMU versions send what events here? */
|
2022-04-07 13:11:32 +03:00
|
|
|
if (IS_ENABLED(CONFIG_ADB_PMU_EVENT) && len == 6) {
|
2006-06-26 09:49:55 +04:00
|
|
|
via_pmu_event(PMU_EVT_POWER, !!(data[1]&8));
|
|
|
|
via_pmu_event(PMU_EVT_LID, data[1]&1);
|
|
|
|
}
|
2018-07-02 11:21:19 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_pass_intr(data, len);
|
|
|
|
}
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static struct adb_request*
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
pmu_sr_intr(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct adb_request *req;
|
|
|
|
int bite = 0;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (in_8(&via2[B]) & TREQ) {
|
|
|
|
printk(KERN_ERR "PMU: spurious SR intr (%x)\n", in_8(&via2[B]));
|
2005-04-17 02:20:36 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
/* The ack may not yet be low when we get the interrupt */
|
2018-07-02 11:21:18 +03:00
|
|
|
while ((in_8(&via2[B]) & TACK) != 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
;
|
|
|
|
|
|
|
|
/* if reading grab the byte, and reset the interrupt */
|
|
|
|
if (pmu_state == reading || pmu_state == reading_intr)
|
2018-07-02 11:21:18 +03:00
|
|
|
bite = in_8(&via1[SR]);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* reset TREQ and wait for TACK to go high */
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via2[B], in_8(&via2[B]) | TREQ);
|
2005-04-17 02:20:36 +04:00
|
|
|
wait_for_ack();
|
|
|
|
|
|
|
|
switch (pmu_state) {
|
|
|
|
case sending:
|
|
|
|
req = current_req;
|
|
|
|
if (data_len < 0) {
|
|
|
|
data_len = req->nbytes - 1;
|
|
|
|
send_byte(data_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (data_index <= data_len) {
|
|
|
|
send_byte(req->data[data_index++]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
req->sent = 1;
|
|
|
|
data_len = pmu_data_len[req->data[0]][1];
|
|
|
|
if (data_len == 0) {
|
|
|
|
pmu_state = idle;
|
|
|
|
current_req = req->next;
|
|
|
|
if (req->reply_expected)
|
|
|
|
req_awaiting_reply = req;
|
|
|
|
else
|
|
|
|
return req;
|
|
|
|
} else {
|
|
|
|
pmu_state = reading;
|
|
|
|
data_index = 0;
|
|
|
|
reply_ptr = req->reply + req->reply_len;
|
|
|
|
recv_byte();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case intack:
|
|
|
|
data_index = 0;
|
|
|
|
data_len = -1;
|
|
|
|
pmu_state = reading_intr;
|
|
|
|
reply_ptr = interrupt_data[int_data_last];
|
|
|
|
recv_byte();
|
|
|
|
if (gpio_irq >= 0 && !gpio_irq_enabled) {
|
|
|
|
enable_irq(gpio_irq);
|
|
|
|
gpio_irq_enabled = 1;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case reading:
|
|
|
|
case reading_intr:
|
|
|
|
if (data_len == -1) {
|
|
|
|
data_len = bite;
|
|
|
|
if (bite > 32)
|
|
|
|
printk(KERN_ERR "PMU: bad reply len %d\n", bite);
|
|
|
|
} else if (data_index < 32) {
|
|
|
|
reply_ptr[data_index++] = bite;
|
|
|
|
}
|
|
|
|
if (data_index < data_len) {
|
|
|
|
recv_byte();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pmu_state == reading_intr) {
|
|
|
|
pmu_state = idle;
|
|
|
|
int_data_state[int_data_last] = int_data_ready;
|
|
|
|
interrupt_data_len[int_data_last] = data_len;
|
|
|
|
} else {
|
|
|
|
req = current_req;
|
|
|
|
/*
|
|
|
|
* For PMU sleep and freq change requests, we lock the
|
2007-10-20 01:22:55 +04:00
|
|
|
* PMU until it's explicitly unlocked. This avoids any
|
2005-04-17 02:20:36 +04:00
|
|
|
* spurrious event polling getting in
|
|
|
|
*/
|
|
|
|
current_req = req->next;
|
|
|
|
req->reply_len += data_index;
|
|
|
|
if (req->data[0] == PMU_SLEEP || req->data[0] == PMU_CPU_SPEED)
|
|
|
|
pmu_state = locked;
|
|
|
|
else
|
|
|
|
pmu_state = idle;
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
printk(KERN_ERR "via_pmu_interrupt: unknown state %d?\n",
|
|
|
|
pmu_state);
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static irqreturn_t
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
via_pmu_interrupt(int irq, void *arg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int intr;
|
|
|
|
int nloop = 0;
|
|
|
|
int int_data = -1;
|
|
|
|
struct adb_request *req = NULL;
|
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
/* This is a bit brutal, we can probably do better */
|
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
|
|
|
++disable_poll;
|
|
|
|
|
|
|
|
for (;;) {
|
2018-07-02 11:21:19 +03:00
|
|
|
/* On 68k Macs, VIA interrupts are dispatched individually.
|
|
|
|
* Unless we are polling, the relevant IRQ flag has already
|
|
|
|
* been cleared.
|
|
|
|
*/
|
|
|
|
intr = 0;
|
|
|
|
if (IS_ENABLED(CONFIG_PPC_PMAC) || !irq) {
|
|
|
|
intr = in_8(&via1[IFR]) & (SR_INT | CB1_INT);
|
|
|
|
out_8(&via1[IFR], intr);
|
|
|
|
}
|
|
|
|
#ifndef CONFIG_PPC_PMAC
|
|
|
|
switch (irq) {
|
|
|
|
case IRQ_MAC_ADB_CL:
|
|
|
|
intr = CB1_INT;
|
|
|
|
break;
|
|
|
|
case IRQ_MAC_ADB_SR:
|
|
|
|
intr = SR_INT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
if (intr == 0)
|
|
|
|
break;
|
|
|
|
handled = 1;
|
|
|
|
if (++nloop > 1000) {
|
|
|
|
printk(KERN_DEBUG "PMU: stuck in intr loop, "
|
|
|
|
"intr=%x, ier=%x pmu_state=%d\n",
|
2018-07-02 11:21:18 +03:00
|
|
|
intr, in_8(&via1[IER]), pmu_state);
|
2005-04-17 02:20:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (intr & CB1_INT) {
|
|
|
|
adb_int_pending = 1;
|
2018-07-02 11:21:19 +03:00
|
|
|
pmu_irq_stats[11]++;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
if (intr & SR_INT) {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
req = pmu_sr_intr();
|
2005-04-17 02:20:36 +04:00
|
|
|
if (req)
|
|
|
|
break;
|
|
|
|
}
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifndef CONFIG_PPC_PMAC
|
|
|
|
break;
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
recheck:
|
|
|
|
if (pmu_state == idle) {
|
|
|
|
if (adb_int_pending) {
|
|
|
|
if (int_data_state[0] == int_data_empty)
|
|
|
|
int_data_last = 0;
|
|
|
|
else if (int_data_state[1] == int_data_empty)
|
|
|
|
int_data_last = 1;
|
|
|
|
else
|
|
|
|
goto no_free_slot;
|
|
|
|
pmu_state = intack;
|
|
|
|
int_data_state[int_data_last] = int_data_fill;
|
|
|
|
/* Sounds safer to make sure ACK is high before writing.
|
|
|
|
* This helped kill a problem with ADB and some iBooks
|
|
|
|
*/
|
|
|
|
wait_for_ack();
|
|
|
|
send_byte(PMU_INT_ACK);
|
|
|
|
adb_int_pending = 0;
|
|
|
|
} else if (current_req)
|
|
|
|
pmu_start();
|
|
|
|
}
|
|
|
|
no_free_slot:
|
|
|
|
/* Mark the oldest buffer for flushing */
|
|
|
|
if (int_data_state[!int_data_last] == int_data_ready) {
|
|
|
|
int_data_state[!int_data_last] = int_data_flush;
|
|
|
|
int_data = !int_data_last;
|
|
|
|
} else if (int_data_state[int_data_last] == int_data_ready) {
|
|
|
|
int_data_state[int_data_last] = int_data_flush;
|
|
|
|
int_data = int_data_last;
|
|
|
|
}
|
|
|
|
--disable_poll;
|
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
|
|
|
|
/* Deal with completed PMU requests outside of the lock */
|
|
|
|
if (req) {
|
|
|
|
pmu_done(req);
|
|
|
|
req = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Deal with interrupt datas outside of the lock */
|
|
|
|
if (int_data >= 0) {
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
pmu_handle_data(interrupt_data[int_data], interrupt_data_len[int_data]);
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
|
|
|
++disable_poll;
|
|
|
|
int_data_state[int_data] = int_data_empty;
|
|
|
|
int_data = -1;
|
|
|
|
goto recheck;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_unlock(void)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
|
|
|
if (pmu_state == locked)
|
|
|
|
pmu_state = idle;
|
|
|
|
adb_int_pending = 1;
|
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-07-02 11:21:19 +03:00
|
|
|
static __maybe_unused irqreturn_t
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
gpio1_interrupt(int irq, void *arg)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if ((in_8(gpio_reg + 0x9) & 0x02) == 0) {
|
|
|
|
spin_lock_irqsave(&pmu_lock, flags);
|
|
|
|
if (gpio_irq_enabled > 0) {
|
|
|
|
disable_irq_nosync(gpio_irq);
|
|
|
|
gpio_irq_enabled = 0;
|
|
|
|
}
|
2018-07-02 11:21:19 +03:00
|
|
|
pmu_irq_stats[12]++;
|
2005-04-17 02:20:36 +04:00
|
|
|
adb_int_pending = 1;
|
|
|
|
spin_unlock_irqrestore(&pmu_lock, flags);
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 17:55:46 +04:00
|
|
|
via_pmu_interrupt(0, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_enable_irled(int on)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return ;
|
|
|
|
if (pmu_kind == PMU_KEYLARGO_BASED)
|
|
|
|
return ;
|
|
|
|
|
|
|
|
pmu_request(&req, NULL, 2, PMU_POWER_CTRL, PMU_POW_IRLED |
|
|
|
|
(on ? PMU_POW_ON : PMU_POW_OFF));
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
}
|
|
|
|
|
2018-09-12 03:18:44 +03:00
|
|
|
/* Offset between Unix time (1970-based) and Mac time (1904-based) */
|
|
|
|
#define RTC_OFFSET 2082844800
|
|
|
|
|
|
|
|
time64_t pmu_get_time(void)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
u32 now;
|
|
|
|
|
|
|
|
if (pmu_request(&req, NULL, 1, PMU_READ_RTC) < 0)
|
|
|
|
return 0;
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
if (req.reply_len != 4)
|
|
|
|
pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
|
|
|
|
now = (req.reply[0] << 24) + (req.reply[1] << 16) +
|
|
|
|
(req.reply[2] << 8) + req.reply[3];
|
|
|
|
return (time64_t)now - RTC_OFFSET;
|
|
|
|
}
|
|
|
|
|
|
|
|
int pmu_set_rtc_time(struct rtc_time *tm)
|
|
|
|
{
|
|
|
|
u32 now;
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
now = lower_32_bits(rtc_tm_to_time64(tm) + RTC_OFFSET);
|
|
|
|
if (pmu_request(&req, NULL, 5, PMU_SET_RTC,
|
|
|
|
now >> 24, now >> 16, now >> 8, now) < 0)
|
|
|
|
return -ENXIO;
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
if (req.reply_len != 0)
|
|
|
|
pr_err("%s: got %d byte reply\n", __func__, req.reply_len);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_restart(void)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
local_irq_disable();
|
|
|
|
|
|
|
|
drop_interrupts = 1;
|
|
|
|
|
|
|
|
if (pmu_kind != PMU_KEYLARGO_BASED) {
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, PMU_INT_ADB |
|
|
|
|
PMU_INT_TICK );
|
|
|
|
while(!req.complete)
|
|
|
|
pmu_poll();
|
|
|
|
}
|
|
|
|
|
|
|
|
pmu_request(&req, NULL, 1, PMU_RESET);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
for (;;)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_shutdown(void)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-04-17 02:20:36 +04:00
|
|
|
return;
|
|
|
|
|
|
|
|
local_irq_disable();
|
|
|
|
|
|
|
|
drop_interrupts = 1;
|
|
|
|
|
|
|
|
if (pmu_kind != PMU_KEYLARGO_BASED) {
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, PMU_INT_ADB |
|
|
|
|
PMU_INT_TICK );
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
} else {
|
|
|
|
/* Disable server mode on shutdown or we'll just
|
|
|
|
* wake up again
|
|
|
|
*/
|
|
|
|
pmu_set_server_mode(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
pmu_request(&req, NULL, 5, PMU_SHUTDOWN,
|
|
|
|
'M', 'A', 'T', 'T');
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
for (;;)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pmu_present(void)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
return pmu_state != uninitialized;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2007-12-11 17:25:59 +03:00
|
|
|
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Put the powerbook to sleep.
|
|
|
|
*/
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static u32 save_via[8];
|
2021-04-16 14:38:04 +03:00
|
|
|
static int __fake_sleep;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
2005-04-17 02:20:36 +04:00
|
|
|
save_via_state(void)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
save_via[0] = in_8(&via1[ANH]);
|
|
|
|
save_via[1] = in_8(&via1[DIRA]);
|
|
|
|
save_via[2] = in_8(&via1[B]);
|
|
|
|
save_via[3] = in_8(&via1[DIRB]);
|
|
|
|
save_via[4] = in_8(&via1[PCR]);
|
|
|
|
save_via[5] = in_8(&via1[ACR]);
|
|
|
|
save_via[6] = in_8(&via1[T1CL]);
|
|
|
|
save_via[7] = in_8(&via1[T1CH]);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
2005-04-17 02:20:36 +04:00
|
|
|
restore_via_state(void)
|
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
out_8(&via1[ANH], save_via[0]);
|
|
|
|
out_8(&via1[DIRA], save_via[1]);
|
|
|
|
out_8(&via1[B], save_via[2]);
|
|
|
|
out_8(&via1[DIRB], save_via[3]);
|
|
|
|
out_8(&via1[PCR], save_via[4]);
|
|
|
|
out_8(&via1[ACR], save_via[5]);
|
|
|
|
out_8(&via1[T1CL], save_via[6]);
|
|
|
|
out_8(&via1[T1CH], save_via[7]);
|
|
|
|
out_8(&via1[IER], IER_CLR | 0x7f); /* disable all intrs */
|
|
|
|
out_8(&via1[IFR], 0x7f); /* clear IFR */
|
|
|
|
out_8(&via1[IER], IER_SET | SR_INT | CB1_INT);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define GRACKLE_PM (1<<7)
|
|
|
|
#define GRACKLE_DOZE (1<<5)
|
|
|
|
#define GRACKLE_NAP (1<<4)
|
|
|
|
#define GRACKLE_SLEEP (1<<3)
|
|
|
|
|
2006-03-22 10:00:05 +03:00
|
|
|
static int powerbook_sleep_grackle(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
unsigned long save_l2cr;
|
|
|
|
unsigned short pmcr1;
|
|
|
|
struct adb_request req;
|
|
|
|
struct pci_dev *grackle;
|
|
|
|
|
2017-12-19 08:37:48 +03:00
|
|
|
grackle = pci_get_domain_bus_and_slot(0, 0, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (!grackle)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
pmu_request(&req, NULL, 2, PMU_POWER_CTRL,
|
|
|
|
PMU_POW_OFF|PMU_POW_BACKLIGHT|PMU_POW_IRLED|PMU_POW_MEDIABAY);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
|
|
|
|
/* For 750, save backside cache setting and disable it */
|
|
|
|
save_l2cr = _get_L2CR(); /* (returns -1 if not available) */
|
|
|
|
|
|
|
|
if (!__fake_sleep) {
|
|
|
|
/* Ask the PMU to put us to sleep */
|
|
|
|
pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 */
|
|
|
|
if (__fake_sleep)
|
|
|
|
mdelay(5000);
|
|
|
|
else
|
|
|
|
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);
|
|
|
|
|
2007-04-23 17:56:01 +04:00
|
|
|
pci_dev_put(grackle);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* 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 != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
|
|
|
|
_set_L2CR(save_l2cr);
|
|
|
|
|
|
|
|
/* Restore userland MMU context */
|
2016-04-29 16:26:01 +03:00
|
|
|
switch_mmu_context(NULL, current->active_mm, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Power things up */
|
|
|
|
pmu_unlock();
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
pmu_request(&req, NULL, 2, PMU_POWER_CTRL0,
|
|
|
|
PMU_POW0_ON|PMU_POW0_HARD_DRIVE);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
pmu_request(&req, NULL, 2, PMU_POWER_CTRL,
|
|
|
|
PMU_POW_ON|PMU_POW_BACKLIGHT|PMU_POW_CHARGER|PMU_POW_IRLED|PMU_POW_MEDIABAY);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static int
|
2005-04-17 02:20:36 +04:00
|
|
|
powerbook_sleep_Core99(void)
|
|
|
|
{
|
|
|
|
unsigned long save_l2cr;
|
|
|
|
unsigned long save_l3cr;
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
if (pmac_call_feature(PMAC_FTR_SLEEP_STATE,NULL,0,-1) < 0) {
|
|
|
|
printk(KERN_ERR "Sleep mode not supported on this machine\n");
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num_online_cpus() > 1 || cpu_is_offline(0))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
2005-05-27 23:53:02 +04:00
|
|
|
/* Stop environment and ADB interrupts */
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, 0);
|
|
|
|
pmu_wait_complete(&req);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Tell PMU what events will wake us up */
|
|
|
|
pmu_request(&req, NULL, 4, PMU_POWER_EVENTS, PMU_PWR_CLR_WAKEUP_EVENTS,
|
|
|
|
0xff, 0xff);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
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));
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
|
|
|
|
/* Save the state of the L2 and L3 caches */
|
|
|
|
save_l3cr = _get_L3CR(); /* (returns -1 if not available) */
|
|
|
|
save_l2cr = _get_L2CR(); /* (returns -1 if not available) */
|
|
|
|
|
|
|
|
if (!__fake_sleep) {
|
|
|
|
/* Ask the PMU to put us to sleep */
|
|
|
|
pmu_request(&req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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);
|
|
|
|
|
|
|
|
/* Call low-level ASM sleep handler */
|
|
|
|
if (__fake_sleep)
|
|
|
|
mdelay(5000);
|
|
|
|
else
|
|
|
|
low_sleep_handler();
|
|
|
|
|
|
|
|
/* Restore Apple core ASICs state */
|
|
|
|
pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 0);
|
|
|
|
|
|
|
|
/* Restore VIA */
|
|
|
|
restore_via_state();
|
|
|
|
|
2005-06-10 08:19:02 +04:00
|
|
|
/* tweak LPJ before cpufreq is there */
|
|
|
|
loops_per_jiffy *= 2;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Restore video */
|
|
|
|
pmac_call_early_video_resume();
|
|
|
|
|
|
|
|
/* Restore L2 cache */
|
|
|
|
if (save_l2cr != 0xffffffff && (save_l2cr & L2CR_L2E) != 0)
|
|
|
|
_set_L2CR(save_l2cr);
|
|
|
|
/* Restore L3 cache */
|
|
|
|
if (save_l3cr != 0xffffffff && (save_l3cr & L3CR_L3E) != 0)
|
|
|
|
_set_L3CR(save_l3cr);
|
|
|
|
|
|
|
|
/* Restore userland MMU context */
|
2016-04-29 16:26:01 +03:00
|
|
|
switch_mmu_context(NULL, current->active_mm, NULL);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Tell PMU we are ready */
|
|
|
|
pmu_unlock();
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SET_INTR_MASK, pmu_intr_mask);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
|
2005-06-10 08:19:02 +04:00
|
|
|
/* Restore LPJ, cpufreq will adjust the cpu frequency */
|
|
|
|
loops_per_jiffy /= 2;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PB3400_MEM_CTRL 0xf8000000
|
|
|
|
#define PB3400_MEM_CTRL_SLEEP 0x70
|
|
|
|
|
2007-12-19 14:45:31 +03:00
|
|
|
static void __iomem *pb3400_mem_ctrl;
|
|
|
|
|
|
|
|
static void powerbook_sleep_init_3400(void)
|
|
|
|
{
|
|
|
|
/* map in the memory controller registers */
|
|
|
|
pb3400_mem_ctrl = ioremap(PB3400_MEM_CTRL, 0x100);
|
|
|
|
if (pb3400_mem_ctrl == NULL)
|
|
|
|
printk(KERN_WARNING "ioremap failed: sleep won't be possible");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int powerbook_sleep_3400(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2007-12-11 17:25:59 +03:00
|
|
|
int i, x;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned int hid0;
|
2007-12-19 14:45:31 +03:00
|
|
|
unsigned long msr;
|
2005-04-17 02:20:36 +04:00
|
|
|
struct adb_request sleep_req;
|
|
|
|
unsigned int __iomem *mem_ctrl_sleep;
|
|
|
|
|
2007-12-19 14:45:31 +03:00
|
|
|
if (pb3400_mem_ctrl == NULL)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENOMEM;
|
2007-12-19 14:45:31 +03:00
|
|
|
mem_ctrl_sleep = pb3400_mem_ctrl + PB3400_MEM_CTRL_SLEEP;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Set the memory controller to keep the memory refreshed
|
|
|
|
while we're asleep */
|
|
|
|
for (i = 0x403f; i >= 0x4000; --i) {
|
|
|
|
out_be32(mem_ctrl_sleep, i);
|
|
|
|
do {
|
|
|
|
x = (in_be32(mem_ctrl_sleep) >> 16) & 0x3ff;
|
|
|
|
} while (x == 0);
|
|
|
|
if (x >= 0x100)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ask the PMU to put us to sleep */
|
|
|
|
pmu_request(&sleep_req, NULL, 5, PMU_SLEEP, 'M', 'A', 'T', 'T');
|
2007-12-19 14:45:31 +03:00
|
|
|
pmu_wait_complete(&sleep_req);
|
|
|
|
pmu_unlock();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-12-19 14:45:31 +03:00
|
|
|
pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 1);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
asleep = 1;
|
|
|
|
|
|
|
|
/* Put the CPU into sleep mode */
|
2005-11-07 08:41:59 +03:00
|
|
|
hid0 = mfspr(SPRN_HID0);
|
2005-04-17 02:20:36 +04:00
|
|
|
hid0 = (hid0 & ~(HID0_NAP | HID0_DOZE)) | HID0_SLEEP;
|
2005-11-07 08:41:59 +03:00
|
|
|
mtspr(SPRN_HID0, hid0);
|
2007-12-19 14:45:31 +03:00
|
|
|
local_irq_enable();
|
|
|
|
msr = mfmsr() | MSR_POW;
|
|
|
|
while (asleep) {
|
|
|
|
mb();
|
|
|
|
mtmsr(msr);
|
|
|
|
isync();
|
|
|
|
}
|
|
|
|
local_irq_disable();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* OK, we're awake again, start restoring things */
|
|
|
|
out_be32(mem_ctrl_sleep, 0x3f);
|
2007-12-19 14:45:31 +03:00
|
|
|
pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, 0);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-11 17:25:59 +03:00
|
|
|
#endif /* CONFIG_SUSPEND && CONFIG_PPC32 */
|
2005-06-28 01:36:34 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
/*
|
|
|
|
* Support for /dev/pmu device
|
|
|
|
*/
|
|
|
|
#define RB_SIZE 0x10
|
|
|
|
struct pmu_private {
|
|
|
|
struct list_head list;
|
|
|
|
int rb_get;
|
|
|
|
int rb_put;
|
|
|
|
struct rb_entry {
|
|
|
|
unsigned short len;
|
|
|
|
unsigned char data[16];
|
|
|
|
} rb_buf[RB_SIZE];
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
spinlock_t lock;
|
|
|
|
#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
|
|
|
|
int backlight_locker;
|
2006-07-30 14:04:19 +04:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static LIST_HEAD(all_pmu_pvt);
|
2005-09-17 19:36:54 +04:00
|
|
|
static DEFINE_SPINLOCK(all_pvt_lock);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static void
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_pass_intr(unsigned char *data, int len)
|
|
|
|
{
|
|
|
|
struct pmu_private *pp;
|
|
|
|
struct list_head *list;
|
|
|
|
int i;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (len > sizeof(pp->rb_buf[0].data))
|
|
|
|
len = sizeof(pp->rb_buf[0].data);
|
|
|
|
spin_lock_irqsave(&all_pvt_lock, flags);
|
|
|
|
for (list = &all_pmu_pvt; (list = list->next) != &all_pmu_pvt; ) {
|
|
|
|
pp = list_entry(list, struct pmu_private, list);
|
|
|
|
spin_lock(&pp->lock);
|
|
|
|
i = pp->rb_put + 1;
|
|
|
|
if (i >= RB_SIZE)
|
|
|
|
i = 0;
|
|
|
|
if (i != pp->rb_get) {
|
|
|
|
struct rb_entry *rp = &pp->rb_buf[pp->rb_put];
|
|
|
|
rp->len = len;
|
|
|
|
memcpy(rp->data, data, len);
|
|
|
|
pp->rb_put = i;
|
|
|
|
wake_up_interruptible(&pp->wait);
|
|
|
|
}
|
|
|
|
spin_unlock(&pp->lock);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&all_pvt_lock, flags);
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static int
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct pmu_private *pp;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
pp = kmalloc(sizeof(struct pmu_private), GFP_KERNEL);
|
2018-04-13 21:41:43 +03:00
|
|
|
if (!pp)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
pp->rb_get = pp->rb_put = 0;
|
|
|
|
spin_lock_init(&pp->lock);
|
|
|
|
init_waitqueue_head(&pp->wait);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&pmu_info_proc_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_lock_irqsave(&all_pvt_lock, flags);
|
|
|
|
#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
|
|
|
|
pp->backlight_locker = 0;
|
2006-07-30 14:04:19 +04:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
list_add(&pp->list, &all_pmu_pvt);
|
|
|
|
spin_unlock_irqrestore(&all_pvt_lock, flags);
|
|
|
|
file->private_data = pp;
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&pmu_info_proc_mutex);
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static ssize_t
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_read(struct file *file, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct pmu_private *pp = file->private_data;
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
unsigned long flags;
|
|
|
|
int ret = 0;
|
|
|
|
|
2018-04-13 21:41:43 +03:00
|
|
|
if (count < 1 || !pp)
|
2005-04-17 02:20:36 +04:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
add_wait_queue(&pp->wait, &wait);
|
2015-02-20 21:12:53 +03:00
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
ret = -EAGAIN;
|
|
|
|
if (pp->rb_get != pp->rb_put) {
|
|
|
|
int i = pp->rb_get;
|
|
|
|
struct rb_entry *rp = &pp->rb_buf[i];
|
|
|
|
ret = rp->len;
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
if (ret > count)
|
|
|
|
ret = count;
|
|
|
|
if (ret > 0 && copy_to_user(buf, rp->data, ret))
|
|
|
|
ret = -EFAULT;
|
|
|
|
if (++i >= RB_SIZE)
|
|
|
|
i = 0;
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
pp->rb_get = i;
|
|
|
|
}
|
|
|
|
if (ret >= 0)
|
|
|
|
break;
|
|
|
|
if (file->f_flags & O_NONBLOCK)
|
|
|
|
break;
|
|
|
|
ret = -ERESTARTSYS;
|
|
|
|
if (signal_pending(current))
|
|
|
|
break;
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
schedule();
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
}
|
2015-02-20 21:12:53 +03:00
|
|
|
__set_current_state(TASK_RUNNING);
|
2005-04-17 02:20:36 +04:00
|
|
|
remove_wait_queue(&pp->wait, &wait);
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static ssize_t
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-03 13:39:46 +03:00
|
|
|
static __poll_t
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_fpoll(struct file *filp, poll_table *wait)
|
|
|
|
{
|
|
|
|
struct pmu_private *pp = filp->private_data;
|
2017-07-03 13:39:46 +03:00
|
|
|
__poll_t mask = 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
unsigned long flags;
|
|
|
|
|
2018-04-13 21:41:43 +03:00
|
|
|
if (!pp)
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
poll_wait(filp, &pp->wait, wait);
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
if (pp->rb_get != pp->rb_put)
|
2018-02-12 01:34:03 +03:00
|
|
|
mask |= EPOLLIN;
|
2005-04-17 02:20:36 +04:00
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static int
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct pmu_private *pp = file->private_data;
|
|
|
|
unsigned long flags;
|
|
|
|
|
2018-04-13 21:41:43 +03:00
|
|
|
if (pp) {
|
2005-04-17 02:20:36 +04:00
|
|
|
file->private_data = NULL;
|
|
|
|
spin_lock_irqsave(&all_pvt_lock, flags);
|
|
|
|
list_del(&pp->list);
|
|
|
|
spin_unlock_irqrestore(&all_pvt_lock, flags);
|
2006-07-30 14:04:19 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
#if defined(CONFIG_INPUT_ADBHID) && defined(CONFIG_PMAC_BACKLIGHT)
|
2006-07-30 14:04:19 +04:00
|
|
|
if (pp->backlight_locker)
|
|
|
|
pmac_backlight_enable();
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
kfree(pp);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-11 17:25:59 +03:00
|
|
|
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
|
2007-12-12 20:35:19 +03:00
|
|
|
static void pmac_suspend_disable_irqs(void)
|
2007-12-11 17:25:59 +03:00
|
|
|
{
|
|
|
|
/* Call platform functions marked "on sleep" */
|
|
|
|
pmac_pfunc_i2c_suspend();
|
|
|
|
pmac_pfunc_base_suspend();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int powerbook_sleep(suspend_state_t state)
|
|
|
|
{
|
|
|
|
int error = 0;
|
|
|
|
|
|
|
|
/* Wait for completion of async requests */
|
|
|
|
while (!batt_req.complete)
|
|
|
|
pmu_poll();
|
|
|
|
|
|
|
|
/* Giveup the lazy FPU & vec so we don't have to back them
|
|
|
|
* up from the low level code
|
|
|
|
*/
|
|
|
|
enable_kernel_fp();
|
|
|
|
|
|
|
|
#ifdef CONFIG_ALTIVEC
|
|
|
|
if (cpu_has_feature(CPU_FTR_ALTIVEC))
|
|
|
|
enable_kernel_altivec();
|
|
|
|
#endif /* CONFIG_ALTIVEC */
|
|
|
|
|
|
|
|
switch (pmu_kind) {
|
|
|
|
case PMU_OHARE_BASED:
|
|
|
|
error = powerbook_sleep_3400();
|
|
|
|
break;
|
|
|
|
case PMU_HEATHROW_BASED:
|
|
|
|
case PMU_PADDINGTON_BASED:
|
|
|
|
error = powerbook_sleep_grackle();
|
|
|
|
break;
|
|
|
|
case PMU_KEYLARGO_BASED:
|
|
|
|
error = powerbook_sleep_Core99();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
mdelay(100);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-12 20:35:19 +03:00
|
|
|
static void pmac_suspend_enable_irqs(void)
|
2007-12-11 17:25:59 +03:00
|
|
|
{
|
|
|
|
/* Force a poll of ADB interrupts */
|
|
|
|
adb_int_pending = 1;
|
|
|
|
via_pmu_interrupt(0, NULL);
|
|
|
|
|
|
|
|
mdelay(10);
|
|
|
|
|
|
|
|
/* Call platform functions marked "on wake" */
|
|
|
|
pmac_pfunc_base_resume();
|
|
|
|
pmac_pfunc_i2c_resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int pmu_sleep_valid(suspend_state_t state)
|
|
|
|
{
|
|
|
|
return state == PM_SUSPEND_MEM
|
|
|
|
&& (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) >= 0);
|
|
|
|
}
|
|
|
|
|
2010-11-16 16:14:02 +03:00
|
|
|
static const struct platform_suspend_ops pmu_pm_ops = {
|
2007-12-11 17:25:59 +03:00
|
|
|
.enter = powerbook_sleep,
|
|
|
|
.valid = pmu_sleep_valid,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int register_pmu_pm_ops(void)
|
|
|
|
{
|
2007-12-12 20:35:19 +03:00
|
|
|
if (pmu_kind == PMU_OHARE_BASED)
|
|
|
|
powerbook_sleep_init_3400();
|
|
|
|
ppc_md.suspend_disable_irqs = pmac_suspend_disable_irqs;
|
|
|
|
ppc_md.suspend_enable_irqs = pmac_suspend_enable_irqs;
|
2007-12-11 17:25:59 +03:00
|
|
|
suspend_set_ops(&pmu_pm_ops);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(register_pmu_pm_ops);
|
|
|
|
#endif
|
|
|
|
|
2010-04-27 02:24:05 +04:00
|
|
|
static int pmu_ioctl(struct file *filp,
|
2005-04-17 02:20:36 +04:00
|
|
|
u_int cmd, u_long arg)
|
|
|
|
{
|
|
|
|
__u32 __user *argp = (__u32 __user *)arg;
|
2005-06-28 01:36:34 +04:00
|
|
|
int error = -EINVAL;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
2018-07-02 11:21:19 +03:00
|
|
|
#ifdef CONFIG_PPC_PMAC
|
2005-04-17 02:20:36 +04:00
|
|
|
case PMU_IOC_SLEEP:
|
|
|
|
if (!capable(CAP_SYS_ADMIN))
|
|
|
|
return -EACCES;
|
2007-12-11 17:25:59 +03:00
|
|
|
return pm_suspend(PM_SUSPEND_MEM);
|
2005-04-17 02:20:36 +04:00
|
|
|
case PMU_IOC_CAN_SLEEP:
|
2007-12-11 17:25:59 +03:00
|
|
|
if (pmac_call_feature(PMAC_FTR_SLEEP_STATE, NULL, 0, -1) < 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
return put_user(0, argp);
|
|
|
|
else
|
|
|
|
return put_user(1, argp);
|
2018-07-02 11:21:19 +03:00
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2006-06-25 16:47:08 +04:00
|
|
|
#ifdef CONFIG_PMAC_BACKLIGHT_LEGACY
|
|
|
|
/* Compatibility ioctl's for backlight */
|
2005-04-17 02:20:36 +04:00
|
|
|
case PMU_IOC_GET_BACKLIGHT:
|
2006-06-25 16:47:08 +04:00
|
|
|
{
|
|
|
|
int brightness;
|
|
|
|
|
|
|
|
brightness = pmac_backlight_get_legacy_brightness();
|
|
|
|
if (brightness < 0)
|
|
|
|
return brightness;
|
|
|
|
else
|
|
|
|
return put_user(brightness, argp);
|
|
|
|
|
|
|
|
}
|
2005-04-17 02:20:36 +04:00
|
|
|
case PMU_IOC_SET_BACKLIGHT:
|
|
|
|
{
|
2006-06-25 16:47:08 +04:00
|
|
|
int brightness;
|
|
|
|
|
|
|
|
error = get_user(brightness, argp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
return pmac_backlight_set_legacy_brightness(brightness);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
#ifdef CONFIG_INPUT_ADBHID
|
|
|
|
case PMU_IOC_GRAB_BACKLIGHT: {
|
2005-06-28 01:36:34 +04:00
|
|
|
struct pmu_private *pp = filp->private_data;
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
if (pp->backlight_locker)
|
|
|
|
return 0;
|
2006-07-30 14:04:19 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
pp->backlight_locker = 1;
|
2006-07-30 14:04:19 +04:00
|
|
|
pmac_backlight_disable();
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_INPUT_ADBHID */
|
2006-06-25 16:47:08 +04:00
|
|
|
#endif /* CONFIG_PMAC_BACKLIGHT_LEGACY */
|
2006-07-30 14:04:19 +04:00
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
case PMU_IOC_GET_MODEL:
|
|
|
|
return put_user(pmu_kind, argp);
|
|
|
|
case PMU_IOC_HAS_ADB:
|
|
|
|
return put_user(pmu_has_adb, argp);
|
|
|
|
}
|
2005-06-28 01:36:34 +04:00
|
|
|
return error;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2010-04-27 02:24:05 +04:00
|
|
|
static long pmu_unlocked_ioctl(struct file *filp,
|
|
|
|
u_int cmd, u_long arg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_lock(&pmu_info_proc_mutex);
|
2010-04-27 02:24:05 +04:00
|
|
|
ret = pmu_ioctl(filp, cmd, arg);
|
2010-06-02 16:28:52 +04:00
|
|
|
mutex_unlock(&pmu_info_proc_mutex);
|
2010-04-27 02:24:05 +04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-08-22 10:23:17 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
#define PMU_IOC_GET_BACKLIGHT32 _IOR('B', 1, compat_size_t)
|
|
|
|
#define PMU_IOC_SET_BACKLIGHT32 _IOW('B', 2, compat_size_t)
|
|
|
|
#define PMU_IOC_GET_MODEL32 _IOR('B', 3, compat_size_t)
|
|
|
|
#define PMU_IOC_HAS_ADB32 _IOR('B', 4, compat_size_t)
|
|
|
|
#define PMU_IOC_CAN_SLEEP32 _IOR('B', 5, compat_size_t)
|
|
|
|
#define PMU_IOC_GRAB_BACKLIGHT32 _IOR('B', 6, compat_size_t)
|
|
|
|
|
|
|
|
static long compat_pmu_ioctl (struct file *filp, u_int cmd, u_long arg)
|
|
|
|
{
|
|
|
|
switch (cmd) {
|
|
|
|
case PMU_IOC_SLEEP:
|
|
|
|
break;
|
|
|
|
case PMU_IOC_GET_BACKLIGHT32:
|
|
|
|
cmd = PMU_IOC_GET_BACKLIGHT;
|
|
|
|
break;
|
|
|
|
case PMU_IOC_SET_BACKLIGHT32:
|
|
|
|
cmd = PMU_IOC_SET_BACKLIGHT;
|
|
|
|
break;
|
|
|
|
case PMU_IOC_GET_MODEL32:
|
|
|
|
cmd = PMU_IOC_GET_MODEL;
|
|
|
|
break;
|
|
|
|
case PMU_IOC_HAS_ADB32:
|
|
|
|
cmd = PMU_IOC_HAS_ADB;
|
|
|
|
break;
|
|
|
|
case PMU_IOC_CAN_SLEEP32:
|
|
|
|
cmd = PMU_IOC_CAN_SLEEP;
|
|
|
|
break;
|
|
|
|
case PMU_IOC_GRAB_BACKLIGHT32:
|
|
|
|
cmd = PMU_IOC_GRAB_BACKLIGHT;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENOIOCTLCMD;
|
|
|
|
}
|
|
|
|
return pmu_unlocked_ioctl(filp, cmd, (unsigned long)compat_ptr(arg));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-12 11:55:33 +03:00
|
|
|
static const struct file_operations pmu_device_fops = {
|
2005-04-17 02:20:36 +04:00
|
|
|
.read = pmu_read,
|
|
|
|
.write = pmu_write,
|
|
|
|
.poll = pmu_fpoll,
|
2010-04-27 02:24:05 +04:00
|
|
|
.unlocked_ioctl = pmu_unlocked_ioctl,
|
2010-08-22 10:23:17 +04:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compat_ioctl = compat_pmu_ioctl,
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
.open = pmu_open,
|
|
|
|
.release = pmu_release,
|
llseek: automatically add .llseek fop
All file_operations should get a .llseek operation so we can make
nonseekable_open the default for future file operations without a
.llseek pointer.
The three cases that we can automatically detect are no_llseek, seq_lseek
and default_llseek. For cases where we can we can automatically prove that
the file offset is always ignored, we use noop_llseek, which maintains
the current behavior of not returning an error from a seek.
New drivers should normally not use noop_llseek but instead use no_llseek
and call nonseekable_open at open time. Existing drivers can be converted
to do the same when the maintainer knows for certain that no user code
relies on calling seek on the device file.
The generated code is often incorrectly indented and right now contains
comments that clarify for each added line why a specific variant was
chosen. In the version that gets submitted upstream, the comments will
be gone and I will manually fix the indentation, because there does not
seem to be a way to do that using coccinelle.
Some amount of new code is currently sitting in linux-next that should get
the same modifications, which I will do at the end of the merge window.
Many thanks to Julia Lawall for helping me learn to write a semantic
patch that does all this.
===== begin semantic patch =====
// This adds an llseek= method to all file operations,
// as a preparation for making no_llseek the default.
//
// The rules are
// - use no_llseek explicitly if we do nonseekable_open
// - use seq_lseek for sequential files
// - use default_llseek if we know we access f_pos
// - use noop_llseek if we know we don't access f_pos,
// but we still want to allow users to call lseek
//
@ open1 exists @
identifier nested_open;
@@
nested_open(...)
{
<+...
nonseekable_open(...)
...+>
}
@ open exists@
identifier open_f;
identifier i, f;
identifier open1.nested_open;
@@
int open_f(struct inode *i, struct file *f)
{
<+...
(
nonseekable_open(...)
|
nested_open(...)
)
...+>
}
@ read disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ read_no_fpos disable optional_qualifier exists @
identifier read_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t read_f(struct file *f, char *p, size_t s, loff_t *off)
{
... when != off
}
@ write @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
expression E;
identifier func;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
<+...
(
*off = E
|
*off += E
|
func(..., off, ...)
|
E = *off
)
...+>
}
@ write_no_fpos @
identifier write_f;
identifier f, p, s, off;
type ssize_t, size_t, loff_t;
@@
ssize_t write_f(struct file *f, const char *p, size_t s, loff_t *off)
{
... when != off
}
@ fops0 @
identifier fops;
@@
struct file_operations fops = {
...
};
@ has_llseek depends on fops0 @
identifier fops0.fops;
identifier llseek_f;
@@
struct file_operations fops = {
...
.llseek = llseek_f,
...
};
@ has_read depends on fops0 @
identifier fops0.fops;
identifier read_f;
@@
struct file_operations fops = {
...
.read = read_f,
...
};
@ has_write depends on fops0 @
identifier fops0.fops;
identifier write_f;
@@
struct file_operations fops = {
...
.write = write_f,
...
};
@ has_open depends on fops0 @
identifier fops0.fops;
identifier open_f;
@@
struct file_operations fops = {
...
.open = open_f,
...
};
// use no_llseek if we call nonseekable_open
////////////////////////////////////////////
@ nonseekable1 depends on !has_llseek && has_open @
identifier fops0.fops;
identifier nso ~= "nonseekable_open";
@@
struct file_operations fops = {
... .open = nso, ...
+.llseek = no_llseek, /* nonseekable */
};
@ nonseekable2 depends on !has_llseek @
identifier fops0.fops;
identifier open.open_f;
@@
struct file_operations fops = {
... .open = open_f, ...
+.llseek = no_llseek, /* open uses nonseekable */
};
// use seq_lseek for sequential files
/////////////////////////////////////
@ seq depends on !has_llseek @
identifier fops0.fops;
identifier sr ~= "seq_read";
@@
struct file_operations fops = {
... .read = sr, ...
+.llseek = seq_lseek, /* we have seq_read */
};
// use default_llseek if there is a readdir
///////////////////////////////////////////
@ fops1 depends on !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier readdir_e;
@@
// any other fop is used that changes pos
struct file_operations fops = {
... .readdir = readdir_e, ...
+.llseek = default_llseek, /* readdir is present */
};
// use default_llseek if at least one of read/write touches f_pos
/////////////////////////////////////////////////////////////////
@ fops2 depends on !fops1 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read.read_f;
@@
// read fops use offset
struct file_operations fops = {
... .read = read_f, ...
+.llseek = default_llseek, /* read accesses f_pos */
};
@ fops3 depends on !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write.write_f;
@@
// write fops use offset
struct file_operations fops = {
... .write = write_f, ...
+ .llseek = default_llseek, /* write accesses f_pos */
};
// Use noop_llseek if neither read nor write accesses f_pos
///////////////////////////////////////////////////////////
@ fops4 depends on !fops1 && !fops2 && !fops3 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
identifier write_no_fpos.write_f;
@@
// write fops use offset
struct file_operations fops = {
...
.write = write_f,
.read = read_f,
...
+.llseek = noop_llseek, /* read and write both use no f_pos */
};
@ depends on has_write && !has_read && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier write_no_fpos.write_f;
@@
struct file_operations fops = {
... .write = write_f, ...
+.llseek = noop_llseek, /* write uses no f_pos */
};
@ depends on has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
identifier read_no_fpos.read_f;
@@
struct file_operations fops = {
... .read = read_f, ...
+.llseek = noop_llseek, /* read uses no f_pos */
};
@ depends on !has_read && !has_write && !fops1 && !fops2 && !has_llseek && !nonseekable1 && !nonseekable2 && !seq @
identifier fops0.fops;
@@
struct file_operations fops = {
...
+.llseek = noop_llseek, /* no read or write fn */
};
===== End semantic patch =====
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: Julia Lawall <julia@diku.dk>
Cc: Christoph Hellwig <hch@infradead.org>
2010-08-15 20:52:59 +04:00
|
|
|
.llseek = noop_llseek,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static struct miscdevice pmu_device = {
|
2005-04-17 02:20:36 +04:00
|
|
|
PMU_MINOR, "pmu", &pmu_device_fops
|
|
|
|
};
|
|
|
|
|
2005-06-28 01:36:34 +04:00
|
|
|
static int pmu_device_init(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
if (pmu_state == uninitialized)
|
2005-06-28 01:36:34 +04:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
if (misc_register(&pmu_device) < 0)
|
|
|
|
printk(KERN_ERR "via-pmu: cannot register misc device.\n");
|
2005-06-28 01:36:34 +04:00
|
|
|
return 0;
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
2005-06-28 01:36:34 +04:00
|
|
|
device_initcall(pmu_device_init);
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_SLEEP
|
2005-09-17 19:36:54 +04:00
|
|
|
static inline void
|
2018-07-02 11:21:18 +03:00
|
|
|
polled_handshake(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
via2[B] &= ~TREQ; eieio();
|
|
|
|
while ((via2[B] & TACK) != 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
;
|
2018-07-02 11:21:18 +03:00
|
|
|
via2[B] |= TREQ; eieio();
|
|
|
|
while ((via2[B] & TACK) == 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static inline void
|
2018-07-02 11:21:18 +03:00
|
|
|
polled_send_byte(int x)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2018-07-02 11:21:18 +03:00
|
|
|
via1[ACR] |= SR_OUT | SR_EXT; eieio();
|
|
|
|
via1[SR] = x; eieio();
|
|
|
|
polled_handshake();
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
static inline int
|
2018-07-02 11:21:18 +03:00
|
|
|
polled_recv_byte(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
via1[ACR] = (via1[ACR] & ~SR_OUT) | SR_EXT; eieio();
|
|
|
|
x = via1[SR]; eieio();
|
|
|
|
polled_handshake();
|
|
|
|
x = via1[SR]; eieio();
|
2005-04-17 02:20:36 +04:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
2005-09-17 19:36:54 +04:00
|
|
|
int
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_polled_request(struct adb_request *req)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
int i, l, c;
|
|
|
|
|
|
|
|
req->complete = 1;
|
|
|
|
c = req->data[0];
|
|
|
|
l = pmu_data_len[c][0];
|
|
|
|
if (l >= 0 && req->nbytes != l + 1)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
local_irq_save(flags);
|
|
|
|
while (pmu_state != idle)
|
|
|
|
pmu_poll();
|
|
|
|
|
2018-07-02 11:21:18 +03:00
|
|
|
while ((via2[B] & TACK) == 0)
|
2005-04-17 02:20:36 +04:00
|
|
|
;
|
2018-07-02 11:21:18 +03:00
|
|
|
polled_send_byte(c);
|
2005-04-17 02:20:36 +04:00
|
|
|
if (l < 0) {
|
|
|
|
l = req->nbytes - 1;
|
2018-07-02 11:21:18 +03:00
|
|
|
polled_send_byte(l);
|
2005-04-17 02:20:36 +04:00
|
|
|
}
|
|
|
|
for (i = 1; i <= l; ++i)
|
2018-07-02 11:21:18 +03:00
|
|
|
polled_send_byte(req->data[i]);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
l = pmu_data_len[c][1];
|
|
|
|
if (l < 0)
|
2018-07-02 11:21:18 +03:00
|
|
|
l = polled_recv_byte();
|
2005-04-17 02:20:36 +04:00
|
|
|
for (i = 0; i < l; ++i)
|
2018-07-02 11:21:18 +03:00
|
|
|
req->reply[i + req->reply_len] = polled_recv_byte();
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
if (req->done)
|
|
|
|
(*req->done)(req);
|
|
|
|
|
|
|
|
local_irq_restore(flags);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-12-11 17:25:59 +03:00
|
|
|
/* N.B. This doesn't work on the 3400 */
|
|
|
|
void pmu_blink(int n)
|
|
|
|
{
|
|
|
|
struct adb_request req;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-12-11 17:25:59 +03:00
|
|
|
memset(&req, 0, sizeof(req));
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-12-11 17:25:59 +03:00
|
|
|
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 /* DEBUG_SLEEP */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2007-12-11 17:25:59 +03:00
|
|
|
#if defined(CONFIG_SUSPEND) && defined(CONFIG_PPC32)
|
2007-05-07 19:08:00 +04:00
|
|
|
int pmu_sys_suspended;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
2011-05-20 09:37:22 +04:00
|
|
|
static int pmu_syscore_suspend(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2011-05-20 09:37:22 +04:00
|
|
|
/* Suspend PMU event interrupts */
|
2005-04-17 02:20:36 +04:00
|
|
|
pmu_suspend();
|
|
|
|
pmu_sys_suspended = 1;
|
2007-12-20 07:00:21 +03:00
|
|
|
|
|
|
|
#ifdef CONFIG_PMAC_BACKLIGHT
|
|
|
|
/* Tell backlight code not to muck around with the chip anymore */
|
|
|
|
pmu_backlight_set_sleep(1);
|
|
|
|
#endif
|
|
|
|
|
2005-04-17 02:20:36 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-05-20 09:37:22 +04:00
|
|
|
static void pmu_syscore_resume(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
|
|
|
struct adb_request req;
|
|
|
|
|
|
|
|
if (!pmu_sys_suspended)
|
2011-05-20 09:37:22 +04:00
|
|
|
return;
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
/* Tell PMU we are ready */
|
|
|
|
pmu_request(&req, NULL, 2, PMU_SYSTEM_READY, 2);
|
|
|
|
pmu_wait_complete(&req);
|
|
|
|
|
2007-12-20 07:00:21 +03:00
|
|
|
#ifdef CONFIG_PMAC_BACKLIGHT
|
|
|
|
/* Tell backlight code it can use the chip again */
|
|
|
|
pmu_backlight_set_sleep(0);
|
|
|
|
#endif
|
2005-04-17 02:20:36 +04:00
|
|
|
/* Resume PMU event interrupts */
|
|
|
|
pmu_resume();
|
|
|
|
pmu_sys_suspended = 0;
|
|
|
|
}
|
|
|
|
|
2011-05-20 09:37:22 +04:00
|
|
|
static struct syscore_ops pmu_syscore_ops = {
|
|
|
|
.suspend = pmu_syscore_suspend,
|
|
|
|
.resume = pmu_syscore_resume,
|
2005-04-17 02:20:36 +04:00
|
|
|
};
|
|
|
|
|
2011-05-20 09:37:22 +04:00
|
|
|
static int pmu_syscore_register(void)
|
2005-04-17 02:20:36 +04:00
|
|
|
{
|
2011-05-20 09:37:22 +04:00
|
|
|
register_syscore_ops(&pmu_syscore_ops);
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-05-20 09:37:22 +04:00
|
|
|
subsys_initcall(pmu_syscore_register);
|
|
|
|
#endif /* CONFIG_SUSPEND && CONFIG_PPC32 */
|
2005-04-17 02:20:36 +04:00
|
|
|
|
|
|
|
EXPORT_SYMBOL(pmu_request);
|
2006-01-07 03:30:44 +03:00
|
|
|
EXPORT_SYMBOL(pmu_queue_request);
|
2005-04-17 02:20:36 +04:00
|
|
|
EXPORT_SYMBOL(pmu_poll);
|
|
|
|
EXPORT_SYMBOL(pmu_poll_adb);
|
|
|
|
EXPORT_SYMBOL(pmu_wait_complete);
|
|
|
|
EXPORT_SYMBOL(pmu_suspend);
|
|
|
|
EXPORT_SYMBOL(pmu_resume);
|
|
|
|
EXPORT_SYMBOL(pmu_unlock);
|
2008-03-08 22:20:17 +03:00
|
|
|
#if defined(CONFIG_PPC32)
|
2005-04-17 02:20:36 +04:00
|
|
|
EXPORT_SYMBOL(pmu_enable_irled);
|
|
|
|
EXPORT_SYMBOL(pmu_battery_count);
|
|
|
|
EXPORT_SYMBOL(pmu_batteries);
|
|
|
|
EXPORT_SYMBOL(pmu_power_flags);
|
2007-12-11 17:25:59 +03:00
|
|
|
#endif /* CONFIG_SUSPEND && CONFIG_PPC32 */
|
2005-04-17 02:20:36 +04:00
|
|
|
|