2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* PowerMac G5 SMU driver
|
|
|
|
*
|
|
|
|
* Copyright 2004 J. Mayer <l_indien@magic.fr>
|
|
|
|
* Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
|
|
|
|
*
|
|
|
|
* Released under the term of the GNU GPL v2.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* TODO:
|
2005-09-23 12:44:06 +08:00
|
|
|
* - maybe add timeout to commands ?
|
|
|
|
* - blocking version of time functions
|
|
|
|
* - polling version of i2c commands (including timer that works with
|
2008-02-03 23:18:02 +08:00
|
|
|
* interrupts off)
|
2005-09-23 12:44:06 +08:00
|
|
|
* - maybe avoid some data copies with i2c by directly using the smu cmd
|
|
|
|
* buffer and a lower level internal interface
|
|
|
|
* - understand SMU -> CPU events and implement reception of them via
|
|
|
|
* the userland interface
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dmapool.h>
|
|
|
|
#include <linux/bootmem.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
#include <linux/highmem.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/rtc.h>
|
2005-09-23 12:44:06 +08:00
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/miscdevice.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/poll.h>
|
2006-03-26 17:37:14 +08:00
|
|
|
#include <linux/mutex.h>
|
2008-05-23 14:27:02 +08:00
|
|
|
#include <linux/of_device.h>
|
2013-09-18 03:28:33 +08:00
|
|
|
#include <linux/of_irq.h>
|
2008-05-23 14:27:02 +08:00
|
|
|
#include <linux/of_platform.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2016-07-05 13:03:50 +08:00
|
|
|
#include <linux/memblock.h>
|
2017-02-03 02:15:33 +08:00
|
|
|
#include <linux/sched/signal.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/byteorder.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/prom.h>
|
|
|
|
#include <asm/machdep.h>
|
|
|
|
#include <asm/pmac_feature.h>
|
|
|
|
#include <asm/smu.h>
|
|
|
|
#include <asm/sections.h>
|
2016-12-25 03:46:01 +08:00
|
|
|
#include <linux/uaccess.h>
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2005-11-07 11:29:02 +08:00
|
|
|
#define VERSION "0.7"
|
2005-09-23 12:44:06 +08:00
|
|
|
#define AUTHOR "(c) 2005 Benjamin Herrenschmidt, IBM Corp."
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
#undef DEBUG_SMU
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG_SMU
|
2005-12-14 10:10:10 +08:00
|
|
|
#define DPRINTK(fmt, args...) do { printk(KERN_DEBUG fmt , ##args); } while (0)
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
|
|
|
#define DPRINTK(fmt, args...) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is the command buffer passed to the SMU hardware
|
|
|
|
*/
|
2005-09-23 12:44:06 +08:00
|
|
|
#define SMU_MAX_DATA 254
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct smu_cmd_buf {
|
|
|
|
u8 cmd;
|
|
|
|
u8 length;
|
2005-09-23 12:44:06 +08:00
|
|
|
u8 data[SMU_MAX_DATA];
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct smu_device {
|
|
|
|
spinlock_t lock;
|
|
|
|
struct device_node *of_node;
|
2010-08-06 23:25:50 +08:00
|
|
|
struct platform_device *of_dev;
|
2005-09-23 12:44:06 +08:00
|
|
|
int doorbell; /* doorbell gpio */
|
2005-04-17 06:20:36 +08:00
|
|
|
u32 __iomem *db_buf; /* doorbell buffer */
|
2006-07-10 19:44:44 +08:00
|
|
|
struct device_node *db_node;
|
|
|
|
unsigned int db_irq;
|
2005-09-23 12:44:06 +08:00
|
|
|
int msg;
|
2006-07-10 19:44:44 +08:00
|
|
|
struct device_node *msg_node;
|
|
|
|
unsigned int msg_irq;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct smu_cmd_buf *cmd_buf; /* command buffer virtual */
|
|
|
|
u32 cmd_buf_abs; /* command buffer absolute */
|
2005-09-23 12:44:06 +08:00
|
|
|
struct list_head cmd_list;
|
|
|
|
struct smu_cmd *cmd_cur; /* pending command */
|
2008-02-07 11:29:43 +08:00
|
|
|
int broken_nap;
|
2005-09-23 12:44:06 +08:00
|
|
|
struct list_head cmd_i2c_list;
|
|
|
|
struct smu_i2c_cmd *cmd_i2c_cur; /* pending i2c command */
|
|
|
|
struct timer_list i2c_timer;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* I don't think there will ever be more than one SMU, so
|
|
|
|
* for now, just hard code that
|
|
|
|
*/
|
2010-06-02 20:28:52 +08:00
|
|
|
static DEFINE_MUTEX(smu_mutex);
|
2005-04-17 06:20:36 +08:00
|
|
|
static struct smu_device *smu;
|
2006-03-26 17:37:14 +08:00
|
|
|
static DEFINE_MUTEX(smu_part_access);
|
2006-07-10 19:44:44 +08:00
|
|
|
static int smu_irq_inited;
|
2016-07-05 13:03:50 +08:00
|
|
|
static unsigned long smu_cmdbuf_abs;
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2017-10-22 04:43:53 +08:00
|
|
|
static void smu_i2c_retry(struct timer_list *t);
|
2006-01-07 08:30:44 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2005-09-23 12:44:06 +08:00
|
|
|
* SMU driver low level stuff
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
static void smu_start_cmd(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
unsigned long faddr, fend;
|
|
|
|
struct smu_cmd *cmd;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
if (list_empty(&smu->cmd_list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Fetch first command in queue */
|
|
|
|
cmd = list_entry(smu->cmd_list.next, struct smu_cmd, link);
|
|
|
|
smu->cmd_cur = cmd;
|
|
|
|
list_del(&cmd->link);
|
|
|
|
|
|
|
|
DPRINTK("SMU: starting cmd %x, %d bytes data\n", cmd->cmd,
|
|
|
|
cmd->data_len);
|
2013-04-22 11:02:19 +08:00
|
|
|
DPRINTK("SMU: data buffer: %8ph\n", cmd->data_buf);
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
/* Fill the SMU command buffer */
|
|
|
|
smu->cmd_buf->cmd = cmd->cmd;
|
|
|
|
smu->cmd_buf->length = cmd->data_len;
|
|
|
|
memcpy(smu->cmd_buf->data, cmd->data_buf, cmd->data_len);
|
|
|
|
|
|
|
|
/* Flush command and data to RAM */
|
|
|
|
faddr = (unsigned long)smu->cmd_buf;
|
|
|
|
fend = faddr + smu->cmd_buf->length + 2;
|
|
|
|
flush_inval_dcache_range(faddr, fend);
|
|
|
|
|
2008-02-07 11:29:43 +08:00
|
|
|
|
|
|
|
/* We also disable NAP mode for the duration of the command
|
|
|
|
* on U3 based machines.
|
|
|
|
* This is slightly racy as it can be written back to 1 by a sysctl
|
|
|
|
* but that never happens in practice. There seem to be an issue with
|
|
|
|
* U3 based machines such as the iMac G5 where napping for the
|
|
|
|
* whole duration of the command prevents the SMU from fetching it
|
|
|
|
* from memory. This might be related to the strange i2c based
|
|
|
|
* mechanism the SMU uses to access memory.
|
|
|
|
*/
|
|
|
|
if (smu->broken_nap)
|
|
|
|
powersave_nap = 0;
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
/* This isn't exactly a DMA mapping here, I suspect
|
2005-04-17 06:20:36 +08:00
|
|
|
* the SMU is actually communicating with us via i2c to the
|
|
|
|
* northbridge or the CPU to access RAM.
|
|
|
|
*/
|
2005-09-23 12:44:06 +08:00
|
|
|
writel(smu->cmd_buf_abs, smu->db_buf);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Ring the SMU doorbell */
|
2005-09-23 12:44:06 +08:00
|
|
|
pmac_do_feature_call(PMAC_FTR_WRITE_GPIO, NULL, smu->doorbell, 4);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
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 21:55:46 +08:00
|
|
|
static irqreturn_t smu_db_intr(int irq, void *arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
unsigned long flags;
|
|
|
|
struct smu_cmd *cmd;
|
|
|
|
void (*done)(struct smu_cmd *cmd, void *misc) = NULL;
|
|
|
|
void *misc = NULL;
|
|
|
|
u8 gpio;
|
|
|
|
int rc = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
/* SMU completed the command, well, we hope, let's make sure
|
|
|
|
* of it
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&smu->lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell);
|
2005-09-30 06:25:17 +08:00
|
|
|
if ((gpio & 7) != 7) {
|
|
|
|
spin_unlock_irqrestore(&smu->lock, flags);
|
2005-09-23 12:44:06 +08:00
|
|
|
return IRQ_HANDLED;
|
2005-09-30 06:25:17 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
cmd = smu->cmd_cur;
|
|
|
|
smu->cmd_cur = NULL;
|
|
|
|
if (cmd == NULL)
|
|
|
|
goto bail;
|
|
|
|
|
|
|
|
if (rc == 0) {
|
|
|
|
unsigned long faddr;
|
|
|
|
int reply_len;
|
|
|
|
u8 ack;
|
|
|
|
|
|
|
|
/* CPU might have brought back the cache line, so we need
|
|
|
|
* to flush again before peeking at the SMU response. We
|
|
|
|
* flush the entire buffer for now as we haven't read the
|
2008-02-03 21:42:53 +08:00
|
|
|
* reply length (it's only 2 cache lines anyway)
|
2005-09-23 12:44:06 +08:00
|
|
|
*/
|
|
|
|
faddr = (unsigned long)smu->cmd_buf;
|
|
|
|
flush_inval_dcache_range(faddr, faddr + 256);
|
|
|
|
|
|
|
|
/* Now check ack */
|
|
|
|
ack = (~cmd->cmd) & 0xff;
|
|
|
|
if (ack != smu->cmd_buf->cmd) {
|
|
|
|
DPRINTK("SMU: incorrect ack, want %x got %x\n",
|
|
|
|
ack, smu->cmd_buf->cmd);
|
|
|
|
rc = -EIO;
|
|
|
|
}
|
|
|
|
reply_len = rc == 0 ? smu->cmd_buf->length : 0;
|
|
|
|
DPRINTK("SMU: reply len: %d\n", reply_len);
|
|
|
|
if (reply_len > cmd->reply_len) {
|
|
|
|
printk(KERN_WARNING "SMU: reply buffer too small,"
|
|
|
|
"got %d bytes for a %d bytes buffer\n",
|
|
|
|
reply_len, cmd->reply_len);
|
|
|
|
reply_len = cmd->reply_len;
|
|
|
|
}
|
|
|
|
cmd->reply_len = reply_len;
|
|
|
|
if (cmd->reply_buf && reply_len)
|
|
|
|
memcpy(cmd->reply_buf, smu->cmd_buf->data, reply_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now complete the command. Write status last in order as we lost
|
|
|
|
* ownership of the command structure as soon as it's no longer -1
|
|
|
|
*/
|
|
|
|
done = cmd->done;
|
|
|
|
misc = cmd->misc;
|
|
|
|
mb();
|
|
|
|
cmd->status = rc;
|
2008-02-07 11:29:43 +08:00
|
|
|
|
|
|
|
/* Re-enable NAP mode */
|
|
|
|
if (smu->broken_nap)
|
|
|
|
powersave_nap = 1;
|
2005-09-23 12:44:06 +08:00
|
|
|
bail:
|
|
|
|
/* Start next command if any */
|
|
|
|
smu_start_cmd();
|
|
|
|
spin_unlock_irqrestore(&smu->lock, flags);
|
|
|
|
|
|
|
|
/* Call command completion handler if any */
|
|
|
|
if (done)
|
|
|
|
done(cmd, misc);
|
|
|
|
|
|
|
|
/* It's an edge interrupt, nothing to do */
|
|
|
|
return IRQ_HANDLED;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
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 21:55:46 +08:00
|
|
|
static irqreturn_t smu_msg_intr(int irq, void *arg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
/* I don't quite know what to do with this one, we seem to never
|
|
|
|
* receive it, so I suspect we have to arm it someway in the SMU
|
|
|
|
* to start getting events that way.
|
|
|
|
*/
|
|
|
|
|
|
|
|
printk(KERN_INFO "SMU: message interrupt !\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
/* It's an edge interrupt, nothing to do */
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
/*
|
|
|
|
* Queued command management.
|
|
|
|
*
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
int smu_queue_cmd(struct smu_cmd *cmd)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
if (smu == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
if (cmd->data_len > SMU_MAX_DATA ||
|
|
|
|
cmd->reply_len > SMU_MAX_DATA)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
cmd->status = 1;
|
|
|
|
spin_lock_irqsave(&smu->lock, flags);
|
|
|
|
list_add_tail(&cmd->link, &smu->cmd_list);
|
|
|
|
if (smu->cmd_cur == NULL)
|
|
|
|
smu_start_cmd();
|
|
|
|
spin_unlock_irqrestore(&smu->lock, flags);
|
|
|
|
|
2006-07-10 19:44:44 +08:00
|
|
|
/* Workaround for early calls when irq isn't available */
|
2016-09-06 19:53:24 +08:00
|
|
|
if (!smu_irq_inited || !smu->db_irq)
|
2006-07-10 19:44:44 +08:00
|
|
|
smu_spinwait_cmd(cmd);
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
EXPORT_SYMBOL(smu_queue_cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
int smu_queue_simple(struct smu_simple_cmd *scmd, u8 command,
|
|
|
|
unsigned int data_len,
|
|
|
|
void (*done)(struct smu_cmd *cmd, void *misc),
|
|
|
|
void *misc, ...)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
struct smu_cmd *cmd = &scmd->cmd;
|
|
|
|
va_list list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (data_len > sizeof(scmd->buffer))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
memset(scmd, 0, sizeof(*scmd));
|
|
|
|
cmd->cmd = command;
|
|
|
|
cmd->data_len = data_len;
|
|
|
|
cmd->data_buf = scmd->buffer;
|
|
|
|
cmd->reply_len = sizeof(scmd->buffer);
|
|
|
|
cmd->reply_buf = scmd->buffer;
|
|
|
|
cmd->done = done;
|
|
|
|
cmd->misc = misc;
|
|
|
|
|
|
|
|
va_start(list, misc);
|
|
|
|
for (i = 0; i < data_len; ++i)
|
|
|
|
scmd->buffer[i] = (u8)va_arg(list, int);
|
|
|
|
va_end(list);
|
|
|
|
|
|
|
|
return smu_queue_cmd(cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
EXPORT_SYMBOL(smu_queue_simple);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
void smu_poll(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
u8 gpio;
|
|
|
|
|
|
|
|
if (smu == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell);
|
|
|
|
if ((gpio & 7) == 7)
|
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 21:55:46 +08:00
|
|
|
smu_db_intr(smu->db_irq, smu);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
EXPORT_SYMBOL(smu_poll);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
void smu_done_complete(struct smu_cmd *cmd, void *misc)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
struct completion *comp = misc;
|
|
|
|
|
|
|
|
complete(comp);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
EXPORT_SYMBOL(smu_done_complete);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
void smu_spinwait_cmd(struct smu_cmd *cmd)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
while(cmd->status == 1)
|
|
|
|
smu_poll();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(smu_spinwait_cmd);
|
|
|
|
|
|
|
|
|
|
|
|
/* RTC low level commands */
|
|
|
|
static inline int bcd2hex (int n)
|
|
|
|
{
|
|
|
|
return (((n & 0xf0) >> 4) * 10) + (n & 0xf);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
static inline int hex2bcd (int n)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
return ((n / 10) << 4) + (n % 10);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static inline void smu_fill_set_rtc_cmd(struct smu_cmd_buf *cmd_buf,
|
|
|
|
struct rtc_time *time)
|
|
|
|
{
|
|
|
|
cmd_buf->cmd = 0x8e;
|
|
|
|
cmd_buf->length = 8;
|
|
|
|
cmd_buf->data[0] = 0x80;
|
|
|
|
cmd_buf->data[1] = hex2bcd(time->tm_sec);
|
|
|
|
cmd_buf->data[2] = hex2bcd(time->tm_min);
|
|
|
|
cmd_buf->data[3] = hex2bcd(time->tm_hour);
|
|
|
|
cmd_buf->data[4] = time->tm_wday;
|
|
|
|
cmd_buf->data[5] = hex2bcd(time->tm_mday);
|
|
|
|
cmd_buf->data[6] = hex2bcd(time->tm_mon) + 1;
|
|
|
|
cmd_buf->data[7] = hex2bcd(time->tm_year - 100);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
int smu_get_rtc_time(struct rtc_time *time, int spinwait)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
struct smu_simple_cmd cmd;
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (smu == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
memset(time, 0, sizeof(struct rtc_time));
|
2005-09-23 12:44:06 +08:00
|
|
|
rc = smu_queue_simple(&cmd, SMU_CMD_RTC_COMMAND, 1, NULL, NULL,
|
|
|
|
SMU_CMD_RTC_GET_DATETIME);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
smu_spinwait_simple(&cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
time->tm_sec = bcd2hex(cmd.buffer[0]);
|
|
|
|
time->tm_min = bcd2hex(cmd.buffer[1]);
|
|
|
|
time->tm_hour = bcd2hex(cmd.buffer[2]);
|
|
|
|
time->tm_wday = bcd2hex(cmd.buffer[3]);
|
|
|
|
time->tm_mday = bcd2hex(cmd.buffer[4]);
|
|
|
|
time->tm_mon = bcd2hex(cmd.buffer[5]) - 1;
|
|
|
|
time->tm_year = bcd2hex(cmd.buffer[6]) + 100;
|
|
|
|
|
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
int smu_set_rtc_time(struct rtc_time *time, int spinwait)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
struct smu_simple_cmd cmd;
|
2005-04-17 06:20:36 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (smu == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
rc = smu_queue_simple(&cmd, SMU_CMD_RTC_COMMAND, 8, NULL, NULL,
|
|
|
|
SMU_CMD_RTC_SET_DATETIME,
|
|
|
|
hex2bcd(time->tm_sec),
|
|
|
|
hex2bcd(time->tm_min),
|
|
|
|
hex2bcd(time->tm_hour),
|
|
|
|
time->tm_wday,
|
|
|
|
hex2bcd(time->tm_mday),
|
|
|
|
hex2bcd(time->tm_mon) + 1,
|
|
|
|
hex2bcd(time->tm_year - 100));
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
smu_spinwait_simple(&cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void smu_shutdown(void)
|
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
struct smu_simple_cmd cmd;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (smu == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
if (smu_queue_simple(&cmd, SMU_CMD_POWER_COMMAND, 9, NULL, NULL,
|
|
|
|
'S', 'H', 'U', 'T', 'D', 'O', 'W', 'N', 0))
|
|
|
|
return;
|
|
|
|
smu_spinwait_simple(&cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (;;)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
void smu_restart(void)
|
|
|
|
{
|
2005-09-23 12:44:06 +08:00
|
|
|
struct smu_simple_cmd cmd;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (smu == NULL)
|
|
|
|
return;
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
if (smu_queue_simple(&cmd, SMU_CMD_POWER_COMMAND, 8, NULL, NULL,
|
|
|
|
'R', 'E', 'S', 'T', 'A', 'R', 'T', 0))
|
|
|
|
return;
|
|
|
|
smu_spinwait_simple(&cmd);
|
2005-04-17 06:20:36 +08:00
|
|
|
for (;;)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
int smu_present(void)
|
|
|
|
{
|
|
|
|
return smu != NULL;
|
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
EXPORT_SYMBOL(smu_present);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
|
2005-11-07 11:29:02 +08:00
|
|
|
int __init smu_init (void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct device_node *np;
|
2006-07-12 13:40:29 +08:00
|
|
|
const u32 *data;
|
2008-06-24 02:14:52 +08:00
|
|
|
int ret = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
np = of_find_node_by_type(NULL, "smu");
|
|
|
|
if (np == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2008-02-07 11:29:43 +08:00
|
|
|
printk(KERN_INFO "SMU: Driver %s %s\n", VERSION, AUTHOR);
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2016-07-05 13:03:50 +08:00
|
|
|
/*
|
|
|
|
* SMU based G5s need some memory below 2Gb. Thankfully this is
|
|
|
|
* called at a time where memblock is still available.
|
|
|
|
*/
|
|
|
|
smu_cmdbuf_abs = memblock_alloc_base(4096, 4096, 0x80000000UL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (smu_cmdbuf_abs == 0) {
|
2016-07-05 13:03:50 +08:00
|
|
|
printk(KERN_ERR "SMU: Command buffer allocation failed !\n");
|
2008-06-24 02:14:52 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
goto fail_np;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
smu = alloc_bootmem(sizeof(struct smu_device));
|
|
|
|
|
|
|
|
spin_lock_init(&smu->lock);
|
2005-09-23 12:44:06 +08:00
|
|
|
INIT_LIST_HEAD(&smu->cmd_list);
|
|
|
|
INIT_LIST_HEAD(&smu->cmd_i2c_list);
|
2005-04-17 06:20:36 +08:00
|
|
|
smu->of_node = np;
|
2016-09-06 19:53:24 +08:00
|
|
|
smu->db_irq = 0;
|
|
|
|
smu->msg_irq = 0;
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* smu_cmdbuf_abs is in the low 2G of RAM, can be converted to a
|
|
|
|
* 32 bits value safely
|
|
|
|
*/
|
|
|
|
smu->cmd_buf_abs = (u32)smu_cmdbuf_abs;
|
2012-07-26 05:19:54 +08:00
|
|
|
smu->cmd_buf = __va(smu_cmdbuf_abs);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2006-07-10 19:44:44 +08:00
|
|
|
smu->db_node = of_find_node_by_name(NULL, "smu-doorbell");
|
|
|
|
if (smu->db_node == NULL) {
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_ERR "SMU: Can't find doorbell GPIO !\n");
|
2008-06-24 02:14:52 +08:00
|
|
|
ret = -ENXIO;
|
|
|
|
goto fail_bootmem;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2007-04-27 11:41:15 +08:00
|
|
|
data = of_get_property(smu->db_node, "reg", NULL);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (data == NULL) {
|
|
|
|
printk(KERN_ERR "SMU: Can't find doorbell GPIO address !\n");
|
2008-06-24 02:14:52 +08:00
|
|
|
ret = -ENXIO;
|
|
|
|
goto fail_db_node;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Current setup has one doorbell GPIO that does both doorbell
|
|
|
|
* and ack. GPIOs are at 0x50, best would be to find that out
|
|
|
|
* in the device-tree though.
|
|
|
|
*/
|
2005-09-23 12:44:06 +08:00
|
|
|
smu->doorbell = *data;
|
|
|
|
if (smu->doorbell < 0x50)
|
|
|
|
smu->doorbell += 0x50;
|
|
|
|
|
|
|
|
/* Now look for the smu-interrupt GPIO */
|
|
|
|
do {
|
2006-07-10 19:44:44 +08:00
|
|
|
smu->msg_node = of_find_node_by_name(NULL, "smu-interrupt");
|
|
|
|
if (smu->msg_node == NULL)
|
2005-09-23 12:44:06 +08:00
|
|
|
break;
|
2007-04-27 11:41:15 +08:00
|
|
|
data = of_get_property(smu->msg_node, "reg", NULL);
|
2005-09-23 12:44:06 +08:00
|
|
|
if (data == NULL) {
|
2006-07-10 19:44:44 +08:00
|
|
|
of_node_put(smu->msg_node);
|
|
|
|
smu->msg_node = NULL;
|
2005-09-23 12:44:06 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
smu->msg = *data;
|
|
|
|
if (smu->msg < 0x50)
|
|
|
|
smu->msg += 0x50;
|
|
|
|
} while(0);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Doorbell buffer is currently hard-coded, I didn't find a proper
|
|
|
|
* device-tree entry giving the address. Best would probably to use
|
|
|
|
* an offset for K2 base though, but let's do it that way for now.
|
|
|
|
*/
|
|
|
|
smu->db_buf = ioremap(0x8000860c, 0x1000);
|
|
|
|
if (smu->db_buf == NULL) {
|
|
|
|
printk(KERN_ERR "SMU: Can't map doorbell buffer pointer !\n");
|
2008-06-24 02:14:52 +08:00
|
|
|
ret = -ENXIO;
|
|
|
|
goto fail_msg_node;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-02-07 11:29:43 +08:00
|
|
|
/* U3 has an issue with NAP mode when issuing SMU commands */
|
|
|
|
smu->broken_nap = pmac_get_uninorth_variant() < 4;
|
|
|
|
if (smu->broken_nap)
|
|
|
|
printk(KERN_INFO "SMU: using NAP mode workaround\n");
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
sys_ctrler = SYS_CTRLER_SMU;
|
|
|
|
return 0;
|
|
|
|
|
2008-06-24 02:14:52 +08:00
|
|
|
fail_msg_node:
|
2015-02-05 04:32:27 +08:00
|
|
|
of_node_put(smu->msg_node);
|
2008-06-24 02:14:52 +08:00
|
|
|
fail_db_node:
|
|
|
|
of_node_put(smu->db_node);
|
|
|
|
fail_bootmem:
|
2012-12-12 08:03:10 +08:00
|
|
|
free_bootmem(__pa(smu), sizeof(struct smu_device));
|
2005-04-17 06:20:36 +08:00
|
|
|
smu = NULL;
|
2008-06-24 02:14:52 +08:00
|
|
|
fail_np:
|
|
|
|
of_node_put(np);
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
static int smu_late_init(void)
|
|
|
|
{
|
|
|
|
if (!smu)
|
|
|
|
return 0;
|
|
|
|
|
2017-10-22 04:43:53 +08:00
|
|
|
timer_setup(&smu->i2c_timer, smu_i2c_retry, 0);
|
2006-01-07 08:30:44 +08:00
|
|
|
|
2006-07-10 19:44:44 +08:00
|
|
|
if (smu->db_node) {
|
|
|
|
smu->db_irq = irq_of_parse_and_map(smu->db_node, 0);
|
2016-09-06 19:53:24 +08:00
|
|
|
if (!smu->db_irq)
|
2017-07-19 05:43:12 +08:00
|
|
|
printk(KERN_ERR "smu: failed to map irq for node %pOF\n",
|
|
|
|
smu->db_node);
|
2006-07-10 19:44:44 +08:00
|
|
|
}
|
|
|
|
if (smu->msg_node) {
|
|
|
|
smu->msg_irq = irq_of_parse_and_map(smu->msg_node, 0);
|
2016-09-06 19:53:24 +08:00
|
|
|
if (!smu->msg_irq)
|
2017-07-19 05:43:12 +08:00
|
|
|
printk(KERN_ERR "smu: failed to map irq for node %pOF\n",
|
|
|
|
smu->msg_node);
|
2006-07-10 19:44:44 +08:00
|
|
|
}
|
|
|
|
|
2005-09-23 12:44:06 +08:00
|
|
|
/*
|
|
|
|
* Try to request the interrupts
|
|
|
|
*/
|
|
|
|
|
2016-09-06 19:53:24 +08:00
|
|
|
if (smu->db_irq) {
|
2005-09-23 12:44:06 +08:00
|
|
|
if (request_irq(smu->db_irq, smu_db_intr,
|
2006-07-02 10:29:38 +08:00
|
|
|
IRQF_SHARED, "SMU doorbell", smu) < 0) {
|
2005-09-23 12:44:06 +08:00
|
|
|
printk(KERN_WARNING "SMU: can't "
|
|
|
|
"request interrupt %d\n",
|
|
|
|
smu->db_irq);
|
2016-09-06 19:53:24 +08:00
|
|
|
smu->db_irq = 0;
|
2005-09-23 12:44:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-06 19:53:24 +08:00
|
|
|
if (smu->msg_irq) {
|
2005-09-23 12:44:06 +08:00
|
|
|
if (request_irq(smu->msg_irq, smu_msg_intr,
|
2006-07-02 10:29:38 +08:00
|
|
|
IRQF_SHARED, "SMU message", smu) < 0) {
|
2005-09-23 12:44:06 +08:00
|
|
|
printk(KERN_WARNING "SMU: can't "
|
|
|
|
"request interrupt %d\n",
|
|
|
|
smu->msg_irq);
|
2016-09-06 19:53:24 +08:00
|
|
|
smu->msg_irq = 0;
|
2005-09-23 12:44:06 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-10 19:44:44 +08:00
|
|
|
smu_irq_inited = 1;
|
2005-09-23 12:44:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2006-01-07 08:30:44 +08:00
|
|
|
/* This has to be before arch_initcall as the low i2c stuff relies on the
|
|
|
|
* above having been done before we reach arch_initcalls
|
|
|
|
*/
|
|
|
|
core_initcall(smu_late_init);
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* sysfs visibility
|
|
|
|
*/
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
static void smu_expose_childs(struct work_struct *unused)
|
2005-09-23 12:44:06 +08:00
|
|
|
{
|
2006-01-07 08:35:26 +08:00
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
for (np = NULL; (np = of_get_next_child(smu->of_node, np)) != NULL;)
|
2007-05-03 15:26:52 +08:00
|
|
|
if (of_device_is_compatible(np, "smu-sensors"))
|
2006-01-07 08:30:44 +08:00
|
|
|
of_platform_device_create(np, "smu-sensors",
|
|
|
|
&smu->of_dev->dev);
|
2005-09-23 12:44:06 +08:00
|
|
|
}
|
|
|
|
|
2006-11-22 22:57:56 +08:00
|
|
|
static DECLARE_WORK(smu_expose_childs_work, smu_expose_childs);
|
2005-09-23 12:44:06 +08:00
|
|
|
|
2011-02-23 10:59:54 +08:00
|
|
|
static int smu_platform_probe(struct platform_device* dev)
|
2005-09-23 12:44:06 +08:00
|
|
|
{
|
|
|
|
if (!smu)
|
|
|
|
return -ENODEV;
|
|
|
|
smu->of_dev = dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ok, we are matched, now expose all i2c busses. We have to defer
|
|
|
|
* that unfortunately or it would deadlock inside the device model
|
|
|
|
*/
|
|
|
|
schedule_work(&smu_expose_childs_work);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-10 09:43:14 +08:00
|
|
|
static const struct of_device_id smu_platform_match[] =
|
2005-09-23 12:44:06 +08:00
|
|
|
{
|
|
|
|
{
|
|
|
|
.type = "smu",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
|
2011-02-23 10:59:54 +08:00
|
|
|
static struct platform_driver smu_of_platform_driver =
|
2005-09-23 12:44:06 +08:00
|
|
|
{
|
2010-04-14 07:13:02 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "smu",
|
|
|
|
.of_match_table = smu_platform_match,
|
|
|
|
},
|
2005-09-23 12:44:06 +08:00
|
|
|
.probe = smu_platform_probe,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init smu_init_sysfs(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* For now, we don't power manage machines with an SMU chip,
|
|
|
|
* I'm a bit too far from figuring out how that works with those
|
|
|
|
* new chipsets, but that will come back and bite us
|
|
|
|
*/
|
2011-02-23 10:59:54 +08:00
|
|
|
platform_driver_register(&smu_of_platform_driver);
|
2005-09-23 12:44:06 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(smu_init_sysfs);
|
|
|
|
|
2010-08-06 23:25:50 +08:00
|
|
|
struct platform_device *smu_get_ofdev(void)
|
2005-09-23 12:44:06 +08:00
|
|
|
{
|
|
|
|
if (!smu)
|
|
|
|
return NULL;
|
|
|
|
return smu->of_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL_GPL(smu_get_ofdev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* i2c interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void smu_i2c_complete_command(struct smu_i2c_cmd *cmd, int fail)
|
|
|
|
{
|
|
|
|
void (*done)(struct smu_i2c_cmd *cmd, void *misc) = cmd->done;
|
|
|
|
void *misc = cmd->misc;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
/* Check for read case */
|
|
|
|
if (!fail && cmd->read) {
|
|
|
|
if (cmd->pdata[0] < 1)
|
|
|
|
fail = 1;
|
|
|
|
else
|
|
|
|
memcpy(cmd->info.data, &cmd->pdata[1],
|
|
|
|
cmd->info.datalen);
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTK("SMU: completing, success: %d\n", !fail);
|
|
|
|
|
|
|
|
/* Update status and mark no pending i2c command with lock
|
|
|
|
* held so nobody comes in while we dequeue an eventual
|
|
|
|
* pending next i2c command
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&smu->lock, flags);
|
|
|
|
smu->cmd_i2c_cur = NULL;
|
|
|
|
wmb();
|
|
|
|
cmd->status = fail ? -EIO : 0;
|
|
|
|
|
|
|
|
/* Is there another i2c command waiting ? */
|
|
|
|
if (!list_empty(&smu->cmd_i2c_list)) {
|
|
|
|
struct smu_i2c_cmd *newcmd;
|
|
|
|
|
|
|
|
/* Fetch it, new current, remove from list */
|
|
|
|
newcmd = list_entry(smu->cmd_i2c_list.next,
|
|
|
|
struct smu_i2c_cmd, link);
|
|
|
|
smu->cmd_i2c_cur = newcmd;
|
|
|
|
list_del(&cmd->link);
|
|
|
|
|
|
|
|
/* Queue with low level smu */
|
|
|
|
list_add_tail(&cmd->scmd.link, &smu->cmd_list);
|
|
|
|
if (smu->cmd_cur == NULL)
|
|
|
|
smu_start_cmd();
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&smu->lock, flags);
|
|
|
|
|
|
|
|
/* Call command completion handler if any */
|
|
|
|
if (done)
|
|
|
|
done(cmd, misc);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-22 04:43:53 +08:00
|
|
|
static void smu_i2c_retry(struct timer_list *unused)
|
2005-09-23 12:44:06 +08:00
|
|
|
{
|
2006-01-07 08:30:44 +08:00
|
|
|
struct smu_i2c_cmd *cmd = smu->cmd_i2c_cur;
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
DPRINTK("SMU: i2c failure, requeuing...\n");
|
|
|
|
|
|
|
|
/* requeue command simply by resetting reply_len */
|
|
|
|
cmd->pdata[0] = 0xff;
|
2006-01-07 08:30:44 +08:00
|
|
|
cmd->scmd.reply_len = sizeof(cmd->pdata);
|
2005-09-23 12:44:06 +08:00
|
|
|
smu_queue_cmd(&cmd->scmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void smu_i2c_low_completion(struct smu_cmd *scmd, void *misc)
|
|
|
|
{
|
|
|
|
struct smu_i2c_cmd *cmd = misc;
|
|
|
|
int fail = 0;
|
|
|
|
|
|
|
|
DPRINTK("SMU: i2c compl. stage=%d status=%x pdata[0]=%x rlen: %x\n",
|
|
|
|
cmd->stage, scmd->status, cmd->pdata[0], scmd->reply_len);
|
|
|
|
|
|
|
|
/* Check for possible status */
|
|
|
|
if (scmd->status < 0)
|
|
|
|
fail = 1;
|
|
|
|
else if (cmd->read) {
|
|
|
|
if (cmd->stage == 0)
|
|
|
|
fail = cmd->pdata[0] != 0;
|
|
|
|
else
|
|
|
|
fail = cmd->pdata[0] >= 0x80;
|
|
|
|
} else {
|
|
|
|
fail = cmd->pdata[0] != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle failures by requeuing command, after 5ms interval
|
|
|
|
*/
|
|
|
|
if (fail && --cmd->retries > 0) {
|
|
|
|
DPRINTK("SMU: i2c failure, starting timer...\n");
|
2006-01-07 08:30:44 +08:00
|
|
|
BUG_ON(cmd != smu->cmd_i2c_cur);
|
2006-07-10 19:44:44 +08:00
|
|
|
if (!smu_irq_inited) {
|
|
|
|
mdelay(5);
|
2017-10-22 04:43:53 +08:00
|
|
|
smu_i2c_retry(NULL);
|
2006-07-10 19:44:44 +08:00
|
|
|
return;
|
|
|
|
}
|
2006-01-07 08:30:44 +08:00
|
|
|
mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5));
|
2005-09-23 12:44:06 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If failure or stage 1, command is complete */
|
|
|
|
if (fail || cmd->stage != 0) {
|
|
|
|
smu_i2c_complete_command(cmd, fail);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTK("SMU: going to stage 1\n");
|
|
|
|
|
|
|
|
/* Ok, initial command complete, now poll status */
|
|
|
|
scmd->reply_buf = cmd->pdata;
|
2006-01-07 08:30:44 +08:00
|
|
|
scmd->reply_len = sizeof(cmd->pdata);
|
2005-09-23 12:44:06 +08:00
|
|
|
scmd->data_buf = cmd->pdata;
|
|
|
|
scmd->data_len = 1;
|
|
|
|
cmd->pdata[0] = 0;
|
|
|
|
cmd->stage = 1;
|
|
|
|
cmd->retries = 20;
|
|
|
|
smu_queue_cmd(scmd);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int smu_queue_i2c(struct smu_i2c_cmd *cmd)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (smu == NULL)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
/* Fill most fields of scmd */
|
|
|
|
cmd->scmd.cmd = SMU_CMD_I2C_COMMAND;
|
|
|
|
cmd->scmd.done = smu_i2c_low_completion;
|
|
|
|
cmd->scmd.misc = cmd;
|
|
|
|
cmd->scmd.reply_buf = cmd->pdata;
|
2006-01-07 08:30:44 +08:00
|
|
|
cmd->scmd.reply_len = sizeof(cmd->pdata);
|
2005-09-23 12:44:06 +08:00
|
|
|
cmd->scmd.data_buf = (u8 *)(char *)&cmd->info;
|
|
|
|
cmd->scmd.status = 1;
|
|
|
|
cmd->stage = 0;
|
|
|
|
cmd->pdata[0] = 0xff;
|
|
|
|
cmd->retries = 20;
|
|
|
|
cmd->status = 1;
|
|
|
|
|
|
|
|
/* Check transfer type, sanitize some "info" fields
|
|
|
|
* based on transfer type and do more checking
|
|
|
|
*/
|
|
|
|
cmd->info.caddr = cmd->info.devaddr;
|
|
|
|
cmd->read = cmd->info.devaddr & 0x01;
|
|
|
|
switch(cmd->info.type) {
|
|
|
|
case SMU_I2C_TRANSFER_SIMPLE:
|
|
|
|
memset(&cmd->info.sublen, 0, 4);
|
|
|
|
break;
|
|
|
|
case SMU_I2C_TRANSFER_COMBINED:
|
|
|
|
cmd->info.devaddr &= 0xfe;
|
|
|
|
case SMU_I2C_TRANSFER_STDSUB:
|
|
|
|
if (cmd->info.sublen > 3)
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finish setting up command based on transfer direction
|
|
|
|
*/
|
|
|
|
if (cmd->read) {
|
|
|
|
if (cmd->info.datalen > SMU_I2C_READ_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
memset(cmd->info.data, 0xff, cmd->info.datalen);
|
|
|
|
cmd->scmd.data_len = 9;
|
|
|
|
} else {
|
|
|
|
if (cmd->info.datalen > SMU_I2C_WRITE_MAX)
|
|
|
|
return -EINVAL;
|
|
|
|
cmd->scmd.data_len = 9 + cmd->info.datalen;
|
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTK("SMU: i2c enqueuing command\n");
|
|
|
|
DPRINTK("SMU: %s, len=%d bus=%x addr=%x sub0=%x type=%x\n",
|
|
|
|
cmd->read ? "read" : "write", cmd->info.datalen,
|
|
|
|
cmd->info.bus, cmd->info.caddr,
|
|
|
|
cmd->info.subaddr[0], cmd->info.type);
|
|
|
|
|
|
|
|
|
|
|
|
/* Enqueue command in i2c list, and if empty, enqueue also in
|
|
|
|
* main command list
|
|
|
|
*/
|
|
|
|
spin_lock_irqsave(&smu->lock, flags);
|
|
|
|
if (smu->cmd_i2c_cur == NULL) {
|
|
|
|
smu->cmd_i2c_cur = cmd;
|
|
|
|
list_add_tail(&cmd->scmd.link, &smu->cmd_list);
|
|
|
|
if (smu->cmd_cur == NULL)
|
|
|
|
smu_start_cmd();
|
|
|
|
} else
|
|
|
|
list_add_tail(&cmd->link, &smu->cmd_i2c_list);
|
|
|
|
spin_unlock_irqrestore(&smu->lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-07 11:29:02 +08:00
|
|
|
/*
|
|
|
|
* Handling of "partitions"
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int smu_read_datablock(u8 *dest, unsigned int addr, unsigned int len)
|
|
|
|
{
|
2006-10-01 14:28:10 +08:00
|
|
|
DECLARE_COMPLETION_ONSTACK(comp);
|
2005-11-07 11:29:02 +08:00
|
|
|
unsigned int chunk;
|
|
|
|
struct smu_cmd cmd;
|
|
|
|
int rc;
|
|
|
|
u8 params[8];
|
|
|
|
|
|
|
|
/* We currently use a chunk size of 0xe. We could check the
|
|
|
|
* SMU firmware version and use bigger sizes though
|
|
|
|
*/
|
|
|
|
chunk = 0xe;
|
|
|
|
|
|
|
|
while (len) {
|
|
|
|
unsigned int clen = min(len, chunk);
|
|
|
|
|
|
|
|
cmd.cmd = SMU_CMD_MISC_ee_COMMAND;
|
|
|
|
cmd.data_len = 7;
|
|
|
|
cmd.data_buf = params;
|
|
|
|
cmd.reply_len = chunk;
|
|
|
|
cmd.reply_buf = dest;
|
|
|
|
cmd.done = smu_done_complete;
|
|
|
|
cmd.misc = ∁
|
|
|
|
params[0] = SMU_CMD_MISC_ee_GET_DATABLOCK_REC;
|
|
|
|
params[1] = 0x4;
|
|
|
|
*((u32 *)¶ms[2]) = addr;
|
|
|
|
params[6] = clen;
|
|
|
|
|
|
|
|
rc = smu_queue_cmd(&cmd);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
wait_for_completion(&comp);
|
|
|
|
if (cmd.status != 0)
|
|
|
|
return rc;
|
|
|
|
if (cmd.reply_len != clen) {
|
|
|
|
printk(KERN_DEBUG "SMU: short read in "
|
|
|
|
"smu_read_datablock, got: %d, want: %d\n",
|
|
|
|
cmd.reply_len, clen);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
len -= clen;
|
|
|
|
addr += clen;
|
|
|
|
dest += clen;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct smu_sdbp_header *smu_create_sdb_partition(int id)
|
|
|
|
{
|
2006-10-01 14:28:10 +08:00
|
|
|
DECLARE_COMPLETION_ONSTACK(comp);
|
2005-11-07 11:29:02 +08:00
|
|
|
struct smu_simple_cmd cmd;
|
|
|
|
unsigned int addr, len, tlen;
|
|
|
|
struct smu_sdbp_header *hdr;
|
|
|
|
struct property *prop;
|
|
|
|
|
|
|
|
/* First query the partition info */
|
2005-12-14 10:10:10 +08:00
|
|
|
DPRINTK("SMU: Query partition infos ... (irq=%d)\n", smu->db_irq);
|
2005-11-07 11:29:02 +08:00
|
|
|
smu_queue_simple(&cmd, SMU_CMD_PARTITION_COMMAND, 2,
|
|
|
|
smu_done_complete, &comp,
|
|
|
|
SMU_CMD_PARTITION_LATEST, id);
|
|
|
|
wait_for_completion(&comp);
|
2005-12-14 10:10:10 +08:00
|
|
|
DPRINTK("SMU: done, status: %d, reply_len: %d\n",
|
|
|
|
cmd.cmd.status, cmd.cmd.reply_len);
|
2005-11-07 11:29:02 +08:00
|
|
|
|
|
|
|
/* Partition doesn't exist (or other error) */
|
|
|
|
if (cmd.cmd.status != 0 || cmd.cmd.reply_len != 6)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* Fetch address and length from reply */
|
|
|
|
addr = *((u16 *)cmd.buffer);
|
|
|
|
len = cmd.buffer[3] << 2;
|
|
|
|
/* Calucluate total length to allocate, including the 17 bytes
|
|
|
|
* for "sdb-partition-XX" that we append at the end of the buffer
|
|
|
|
*/
|
|
|
|
tlen = sizeof(struct property) + len + 18;
|
|
|
|
|
2006-12-13 16:34:52 +08:00
|
|
|
prop = kzalloc(tlen, GFP_KERNEL);
|
2005-11-07 11:29:02 +08:00
|
|
|
if (prop == NULL)
|
|
|
|
return NULL;
|
|
|
|
hdr = (struct smu_sdbp_header *)(prop + 1);
|
|
|
|
prop->name = ((char *)prop) + tlen - 18;
|
|
|
|
sprintf(prop->name, "sdb-partition-%02x", id);
|
|
|
|
prop->length = len;
|
2007-04-03 08:58:52 +08:00
|
|
|
prop->value = hdr;
|
2005-11-07 11:29:02 +08:00
|
|
|
prop->next = NULL;
|
|
|
|
|
|
|
|
/* Read the datablock */
|
|
|
|
if (smu_read_datablock((u8 *)hdr, addr, len)) {
|
|
|
|
printk(KERN_DEBUG "SMU: datablock read failed while reading "
|
|
|
|
"partition %02x !\n", id);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Got it, check a few things and create the property */
|
|
|
|
if (hdr->id != id) {
|
|
|
|
printk(KERN_DEBUG "SMU: Reading partition %02x and got "
|
|
|
|
"%02x !\n", id, hdr->id);
|
|
|
|
goto failure;
|
|
|
|
}
|
2012-10-03 00:58:46 +08:00
|
|
|
if (of_add_property(smu->of_node, prop)) {
|
2005-11-07 11:29:02 +08:00
|
|
|
printk(KERN_DEBUG "SMU: Failed creating sdb-partition-%02x "
|
|
|
|
"property !\n", id);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hdr;
|
|
|
|
failure:
|
|
|
|
kfree(prop);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note: Only allowed to return error code in pointers (using ERR_PTR)
|
|
|
|
* when interruptible is 1
|
|
|
|
*/
|
2006-07-12 13:40:29 +08:00
|
|
|
const struct smu_sdbp_header *__smu_get_sdb_partition(int id,
|
|
|
|
unsigned int *size, int interruptible)
|
2005-11-07 11:27:33 +08:00
|
|
|
{
|
|
|
|
char pname[32];
|
2006-07-12 13:40:29 +08:00
|
|
|
const struct smu_sdbp_header *part;
|
2005-11-07 11:27:33 +08:00
|
|
|
|
|
|
|
if (!smu)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
sprintf(pname, "sdb-partition-%02x", id);
|
2005-11-07 11:29:02 +08:00
|
|
|
|
2005-12-14 10:10:10 +08:00
|
|
|
DPRINTK("smu_get_sdb_partition(%02x)\n", id);
|
|
|
|
|
2005-11-07 11:29:02 +08:00
|
|
|
if (interruptible) {
|
|
|
|
int rc;
|
2006-03-26 17:37:14 +08:00
|
|
|
rc = mutex_lock_interruptible(&smu_part_access);
|
2005-11-07 11:29:02 +08:00
|
|
|
if (rc)
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
} else
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_lock(&smu_part_access);
|
2005-11-07 11:29:02 +08:00
|
|
|
|
2007-04-27 11:41:15 +08:00
|
|
|
part = of_get_property(smu->of_node, pname, size);
|
2005-11-07 11:29:02 +08:00
|
|
|
if (part == NULL) {
|
2005-12-14 10:10:10 +08:00
|
|
|
DPRINTK("trying to extract from SMU ...\n");
|
2005-11-07 11:29:02 +08:00
|
|
|
part = smu_create_sdb_partition(id);
|
|
|
|
if (part != NULL && size)
|
|
|
|
*size = part->len << 2;
|
|
|
|
}
|
2006-03-26 17:37:14 +08:00
|
|
|
mutex_unlock(&smu_part_access);
|
2005-11-07 11:29:02 +08:00
|
|
|
return part;
|
|
|
|
}
|
|
|
|
|
2006-07-12 13:40:29 +08:00
|
|
|
const struct smu_sdbp_header *smu_get_sdb_partition(int id, unsigned int *size)
|
2005-11-07 11:29:02 +08:00
|
|
|
{
|
|
|
|
return __smu_get_sdb_partition(id, size, 0);
|
2005-11-07 11:27:33 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(smu_get_sdb_partition);
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Userland driver interface
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
static LIST_HEAD(smu_clist);
|
|
|
|
static DEFINE_SPINLOCK(smu_clist_lock);
|
|
|
|
|
|
|
|
enum smu_file_mode {
|
|
|
|
smu_file_commands,
|
|
|
|
smu_file_events,
|
|
|
|
smu_file_closing
|
|
|
|
};
|
|
|
|
|
|
|
|
struct smu_private
|
|
|
|
{
|
|
|
|
struct list_head list;
|
|
|
|
enum smu_file_mode mode;
|
|
|
|
int busy;
|
|
|
|
struct smu_cmd cmd;
|
|
|
|
spinlock_t lock;
|
|
|
|
wait_queue_head_t wait;
|
|
|
|
u8 buffer[SMU_MAX_DATA];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int smu_open(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct smu_private *pp;
|
|
|
|
unsigned long flags;
|
|
|
|
|
some kmalloc/memset ->kzalloc (tree wide)
Transform some calls to kmalloc/memset to a single kzalloc (or kcalloc).
Here is a short excerpt of the semantic patch performing
this transformation:
@@
type T2;
expression x;
identifier f,fld;
expression E;
expression E1,E2;
expression e1,e2,e3,y;
statement S;
@@
x =
- kmalloc
+ kzalloc
(E1,E2)
... when != \(x->fld=E;\|y=f(...,x,...);\|f(...,x,...);\|x=E;\|while(...) S\|for(e1;e2;e3) S\)
- memset((T2)x,0,E1);
@@
expression E1,E2,E3;
@@
- kzalloc(E1 * E2,E3)
+ kcalloc(E1,E2,E3)
[akpm@linux-foundation.org: get kcalloc args the right way around]
Signed-off-by: Yoann Padioleau <padator@wanadoo.fr>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Acked-by: Russell King <rmk@arm.linux.org.uk>
Cc: Bryan Wu <bryan.wu@analog.com>
Acked-by: Jiri Slaby <jirislaby@gmail.com>
Cc: Dave Airlie <airlied@linux.ie>
Acked-by: Roland Dreier <rolandd@cisco.com>
Cc: Jiri Kosina <jkosina@suse.cz>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Acked-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Acked-by: Pierre Ossman <drzeus-list@drzeus.cx>
Cc: Jeff Garzik <jeff@garzik.org>
Cc: "David S. Miller" <davem@davemloft.net>
Acked-by: Greg KH <greg@kroah.com>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Cc: "Antonino A. Daplas" <adaplas@pol.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2007-07-19 16:49:03 +08:00
|
|
|
pp = kzalloc(sizeof(struct smu_private), GFP_KERNEL);
|
2005-09-23 12:44:06 +08:00
|
|
|
if (pp == 0)
|
|
|
|
return -ENOMEM;
|
|
|
|
spin_lock_init(&pp->lock);
|
|
|
|
pp->mode = smu_file_commands;
|
|
|
|
init_waitqueue_head(&pp->wait);
|
|
|
|
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_lock(&smu_mutex);
|
2005-09-23 12:44:06 +08:00
|
|
|
spin_lock_irqsave(&smu_clist_lock, flags);
|
|
|
|
list_add(&pp->list, &smu_clist);
|
|
|
|
spin_unlock_irqrestore(&smu_clist_lock, flags);
|
|
|
|
file->private_data = pp;
|
2010-06-02 20:28:52 +08:00
|
|
|
mutex_unlock(&smu_mutex);
|
2005-09-23 12:44:06 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void smu_user_cmd_done(struct smu_cmd *cmd, void *misc)
|
|
|
|
{
|
|
|
|
struct smu_private *pp = misc;
|
|
|
|
|
|
|
|
wake_up_all(&pp->wait);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t smu_write(struct file *file, const char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct smu_private *pp = file->private_data;
|
|
|
|
unsigned long flags;
|
|
|
|
struct smu_user_cmd_hdr hdr;
|
|
|
|
int rc = 0;
|
|
|
|
|
|
|
|
if (pp->busy)
|
|
|
|
return -EBUSY;
|
|
|
|
else if (copy_from_user(&hdr, buf, sizeof(hdr)))
|
|
|
|
return -EFAULT;
|
|
|
|
else if (hdr.cmdtype == SMU_CMDTYPE_WANTS_EVENTS) {
|
|
|
|
pp->mode = smu_file_events;
|
|
|
|
return 0;
|
2005-11-07 11:29:02 +08:00
|
|
|
} else if (hdr.cmdtype == SMU_CMDTYPE_GET_PARTITION) {
|
2006-07-12 13:40:29 +08:00
|
|
|
const struct smu_sdbp_header *part;
|
2005-11-07 11:29:02 +08:00
|
|
|
part = __smu_get_sdb_partition(hdr.cmd, NULL, 1);
|
|
|
|
if (part == NULL)
|
|
|
|
return -EINVAL;
|
|
|
|
else if (IS_ERR(part))
|
|
|
|
return PTR_ERR(part);
|
|
|
|
return 0;
|
2005-09-23 12:44:06 +08:00
|
|
|
} else if (hdr.cmdtype != SMU_CMDTYPE_SMU)
|
|
|
|
return -EINVAL;
|
|
|
|
else if (pp->mode != smu_file_commands)
|
|
|
|
return -EBADFD;
|
|
|
|
else if (hdr.data_len > SMU_MAX_DATA)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
if (pp->busy) {
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
pp->busy = 1;
|
|
|
|
pp->cmd.status = 1;
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
|
|
|
|
if (copy_from_user(pp->buffer, buf + sizeof(hdr), hdr.data_len)) {
|
|
|
|
pp->busy = 0;
|
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
|
|
|
|
pp->cmd.cmd = hdr.cmd;
|
|
|
|
pp->cmd.data_len = hdr.data_len;
|
|
|
|
pp->cmd.reply_len = SMU_MAX_DATA;
|
|
|
|
pp->cmd.data_buf = pp->buffer;
|
|
|
|
pp->cmd.reply_buf = pp->buffer;
|
|
|
|
pp->cmd.done = smu_user_cmd_done;
|
|
|
|
pp->cmd.misc = pp;
|
|
|
|
rc = smu_queue_cmd(&pp->cmd);
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t smu_read_command(struct file *file, struct smu_private *pp,
|
|
|
|
char __user *buf, size_t count)
|
|
|
|
{
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
struct smu_user_reply_hdr hdr;
|
|
|
|
unsigned long flags;
|
|
|
|
int size, rc = 0;
|
|
|
|
|
|
|
|
if (!pp->busy)
|
|
|
|
return 0;
|
|
|
|
if (count < sizeof(struct smu_user_reply_hdr))
|
|
|
|
return -EOVERFLOW;
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
if (pp->cmd.status == 1) {
|
2010-03-29 13:34:46 +08:00
|
|
|
if (file->f_flags & O_NONBLOCK) {
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
2005-09-23 12:44:06 +08:00
|
|
|
return -EAGAIN;
|
2010-03-29 13:34:46 +08:00
|
|
|
}
|
2005-09-23 12:44:06 +08:00
|
|
|
add_wait_queue(&pp->wait, &wait);
|
|
|
|
for (;;) {
|
|
|
|
set_current_state(TASK_INTERRUPTIBLE);
|
|
|
|
rc = 0;
|
|
|
|
if (pp->cmd.status != 1)
|
|
|
|
break;
|
|
|
|
rc = -ERESTARTSYS;
|
|
|
|
if (signal_pending(current))
|
|
|
|
break;
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
schedule();
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
}
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
remove_wait_queue(&pp->wait, &wait);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
if (pp->cmd.status != 0)
|
|
|
|
pp->cmd.reply_len = 0;
|
|
|
|
size = sizeof(hdr) + pp->cmd.reply_len;
|
|
|
|
if (count < size)
|
|
|
|
size = count;
|
|
|
|
rc = size;
|
|
|
|
hdr.status = pp->cmd.status;
|
|
|
|
hdr.reply_len = pp->cmd.reply_len;
|
|
|
|
if (copy_to_user(buf, &hdr, sizeof(hdr)))
|
|
|
|
return -EFAULT;
|
|
|
|
size -= sizeof(hdr);
|
|
|
|
if (size && copy_to_user(buf + sizeof(hdr), pp->buffer, size))
|
|
|
|
return -EFAULT;
|
|
|
|
pp->busy = 0;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t smu_read_events(struct file *file, struct smu_private *pp,
|
|
|
|
char __user *buf, size_t count)
|
|
|
|
{
|
|
|
|
/* Not implemented */
|
|
|
|
msleep_interruptible(1000);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static ssize_t smu_read(struct file *file, char __user *buf,
|
|
|
|
size_t count, loff_t *ppos)
|
|
|
|
{
|
|
|
|
struct smu_private *pp = file->private_data;
|
|
|
|
|
|
|
|
if (pp->mode == smu_file_commands)
|
|
|
|
return smu_read_command(file, pp, buf, count);
|
|
|
|
if (pp->mode == smu_file_events)
|
|
|
|
return smu_read_events(file, pp, buf, count);
|
|
|
|
|
|
|
|
return -EBADFD;
|
|
|
|
}
|
|
|
|
|
2017-07-03 18:39:46 +08:00
|
|
|
static __poll_t smu_fpoll(struct file *file, poll_table *wait)
|
2005-09-23 12:44:06 +08:00
|
|
|
{
|
|
|
|
struct smu_private *pp = file->private_data;
|
2017-07-03 18:39:46 +08:00
|
|
|
__poll_t mask = 0;
|
2005-09-23 12:44:06 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (pp == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (pp->mode == smu_file_commands) {
|
|
|
|
poll_wait(file, &pp->wait, wait);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
if (pp->busy && pp->cmd.status != 1)
|
2018-02-12 06:34:03 +08:00
|
|
|
mask |= EPOLLIN;
|
2005-09-23 12:44:06 +08:00
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
2014-06-21 03:44:27 +08:00
|
|
|
}
|
|
|
|
if (pp->mode == smu_file_events) {
|
2005-09-23 12:44:06 +08:00
|
|
|
/* Not yet implemented */
|
|
|
|
}
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smu_release(struct inode *inode, struct file *file)
|
|
|
|
{
|
|
|
|
struct smu_private *pp = file->private_data;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int busy;
|
|
|
|
|
|
|
|
if (pp == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
file->private_data = NULL;
|
|
|
|
|
|
|
|
/* Mark file as closing to avoid races with new request */
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
|
|
|
pp->mode = smu_file_closing;
|
|
|
|
busy = pp->busy;
|
|
|
|
|
|
|
|
/* Wait for any pending request to complete */
|
|
|
|
if (busy && pp->cmd.status == 1) {
|
|
|
|
DECLARE_WAITQUEUE(wait, current);
|
|
|
|
|
|
|
|
add_wait_queue(&pp->wait, &wait);
|
|
|
|
for (;;) {
|
|
|
|
set_current_state(TASK_UNINTERRUPTIBLE);
|
|
|
|
if (pp->cmd.status != 1)
|
|
|
|
break;
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
2007-04-17 13:53:25 +08:00
|
|
|
schedule();
|
|
|
|
spin_lock_irqsave(&pp->lock, flags);
|
2005-09-23 12:44:06 +08:00
|
|
|
}
|
|
|
|
set_current_state(TASK_RUNNING);
|
|
|
|
remove_wait_queue(&pp->wait, &wait);
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&pp->lock, flags);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&smu_clist_lock, flags);
|
|
|
|
list_del(&pp->list);
|
|
|
|
spin_unlock_irqrestore(&smu_clist_lock, flags);
|
|
|
|
kfree(pp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-02-12 16:55:33 +08:00
|
|
|
static const struct file_operations smu_device_fops = {
|
2005-09-23 12:44:06 +08:00
|
|
|
.llseek = no_llseek,
|
|
|
|
.read = smu_read,
|
|
|
|
.write = smu_write,
|
|
|
|
.poll = smu_fpoll,
|
|
|
|
.open = smu_open,
|
|
|
|
.release = smu_release,
|
|
|
|
};
|
|
|
|
|
2005-09-27 12:09:39 +08:00
|
|
|
static struct miscdevice pmu_device = {
|
2005-09-23 12:44:06 +08:00
|
|
|
MISC_DYNAMIC_MINOR, "smu", &smu_device_fops
|
|
|
|
};
|
|
|
|
|
|
|
|
static int smu_device_init(void)
|
|
|
|
{
|
|
|
|
if (!smu)
|
|
|
|
return -ENODEV;
|
|
|
|
if (misc_register(&pmu_device) < 0)
|
|
|
|
printk(KERN_ERR "via-pmu: cannot register misc device.\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
device_initcall(smu_device_init);
|