Blame view
drivers/macintosh/smu.c
30.6 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 |
/* * 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. */ /* |
1da177e4c Linux-2.6.12-rc2 |
11 |
* TODO: |
0365ba7fb [PATCH] ppc64: SM... |
12 13 14 |
* - maybe add timeout to commands ? * - blocking version of time functions * - polling version of i2c commands (including timer that works with |
f18816ba2 drivers/macintosh... |
15 |
* interrupts off) |
0365ba7fb [PATCH] ppc64: SM... |
16 17 18 19 |
* - 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 |
1da177e4c Linux-2.6.12-rc2 |
20 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
21 22 23 24 25 26 27 28 29 30 |
#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> |
0365ba7fb [PATCH] ppc64: SM... |
31 32 33 |
#include <linux/completion.h> #include <linux/miscdevice.h> #include <linux/delay.h> |
0365ba7fb [PATCH] ppc64: SM... |
34 |
#include <linux/poll.h> |
14cc3e2b6 [PATCH] sem2mutex... |
35 |
#include <linux/mutex.h> |
ad9e05aef macintosh: Use li... |
36 37 |
#include <linux/of_device.h> #include <linux/of_platform.h> |
5a0e3ad6a include cleanup: ... |
38 |
#include <linux/slab.h> |
1da177e4c Linux-2.6.12-rc2 |
39 40 41 42 43 44 45 46 47 |
#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> #include <asm/abs_addr.h> |
0365ba7fb [PATCH] ppc64: SM... |
48 |
#include <asm/uaccess.h> |
0365ba7fb [PATCH] ppc64: SM... |
49 |
|
183d02025 [PATCH] ppc64: SM... |
50 |
#define VERSION "0.7" |
0365ba7fb [PATCH] ppc64: SM... |
51 |
#define AUTHOR "(c) 2005 Benjamin Herrenschmidt, IBM Corp." |
1da177e4c Linux-2.6.12-rc2 |
52 |
|
0365ba7fb [PATCH] ppc64: SM... |
53 |
#undef DEBUG_SMU |
1da177e4c Linux-2.6.12-rc2 |
54 55 |
#ifdef DEBUG_SMU |
1beb6a7d6 [PATCH] powerpc: ... |
56 |
#define DPRINTK(fmt, args...) do { printk(KERN_DEBUG fmt , ##args); } while (0) |
1da177e4c Linux-2.6.12-rc2 |
57 58 59 60 61 62 63 |
#else #define DPRINTK(fmt, args...) do { } while (0) #endif /* * This is the command buffer passed to the SMU hardware */ |
0365ba7fb [PATCH] ppc64: SM... |
64 |
#define SMU_MAX_DATA 254 |
1da177e4c Linux-2.6.12-rc2 |
65 66 67 |
struct smu_cmd_buf { u8 cmd; u8 length; |
0365ba7fb [PATCH] ppc64: SM... |
68 |
u8 data[SMU_MAX_DATA]; |
1da177e4c Linux-2.6.12-rc2 |
69 70 71 72 73 |
}; struct smu_device { spinlock_t lock; struct device_node *of_node; |
2dc115813 of/device: Replac... |
74 |
struct platform_device *of_dev; |
0365ba7fb [PATCH] ppc64: SM... |
75 |
int doorbell; /* doorbell gpio */ |
1da177e4c Linux-2.6.12-rc2 |
76 |
u32 __iomem *db_buf; /* doorbell buffer */ |
f620753b9 [PATCH] powerpc: ... |
77 78 |
struct device_node *db_node; unsigned int db_irq; |
0365ba7fb [PATCH] ppc64: SM... |
79 |
int msg; |
f620753b9 [PATCH] powerpc: ... |
80 81 |
struct device_node *msg_node; unsigned int msg_irq; |
1da177e4c Linux-2.6.12-rc2 |
82 83 |
struct smu_cmd_buf *cmd_buf; /* command buffer virtual */ u32 cmd_buf_abs; /* command buffer absolute */ |
0365ba7fb [PATCH] ppc64: SM... |
84 85 |
struct list_head cmd_list; struct smu_cmd *cmd_cur; /* pending command */ |
592a607bb [POWERPC] Disable... |
86 |
int broken_nap; |
0365ba7fb [PATCH] ppc64: SM... |
87 88 89 |
struct list_head cmd_i2c_list; struct smu_i2c_cmd *cmd_i2c_cur; /* pending i2c command */ struct timer_list i2c_timer; |
1da177e4c Linux-2.6.12-rc2 |
90 91 92 93 94 95 |
}; /* * I don't think there will ever be more than one SMU, so * for now, just hard code that */ |
d851b6e04 mac: autoconvert ... |
96 |
static DEFINE_MUTEX(smu_mutex); |
1da177e4c Linux-2.6.12-rc2 |
97 |
static struct smu_device *smu; |
14cc3e2b6 [PATCH] sem2mutex... |
98 |
static DEFINE_MUTEX(smu_part_access); |
f620753b9 [PATCH] powerpc: ... |
99 |
static int smu_irq_inited; |
0365ba7fb [PATCH] ppc64: SM... |
100 |
|
730745a5c [PATCH] 1/5 power... |
101 |
static void smu_i2c_retry(unsigned long data); |
1da177e4c Linux-2.6.12-rc2 |
102 |
/* |
0365ba7fb [PATCH] ppc64: SM... |
103 |
* SMU driver low level stuff |
1da177e4c Linux-2.6.12-rc2 |
104 |
*/ |
1da177e4c Linux-2.6.12-rc2 |
105 |
|
0365ba7fb [PATCH] ppc64: SM... |
106 |
static void smu_start_cmd(void) |
1da177e4c Linux-2.6.12-rc2 |
107 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
108 109 |
unsigned long faddr, fend; struct smu_cmd *cmd; |
1da177e4c Linux-2.6.12-rc2 |
110 |
|
0365ba7fb [PATCH] ppc64: SM... |
111 112 113 114 115 116 117 118 119 120 121 |
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 ", cmd->cmd, cmd->data_len); |
183d02025 [PATCH] ppc64: SM... |
122 123 |
DPRINTK("SMU: data buffer: %02x %02x %02x %02x %02x %02x %02x %02x ", |
0365ba7fb [PATCH] ppc64: SM... |
124 |
((u8 *)cmd->data_buf)[0], ((u8 *)cmd->data_buf)[1], |
183d02025 [PATCH] ppc64: SM... |
125 126 127 |
((u8 *)cmd->data_buf)[2], ((u8 *)cmd->data_buf)[3], ((u8 *)cmd->data_buf)[4], ((u8 *)cmd->data_buf)[5], ((u8 *)cmd->data_buf)[6], ((u8 *)cmd->data_buf)[7]); |
0365ba7fb [PATCH] ppc64: SM... |
128 129 130 131 132 133 134 135 136 137 |
/* 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); |
592a607bb [POWERPC] Disable... |
138 139 140 141 142 143 144 145 146 147 148 149 |
/* 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; |
0365ba7fb [PATCH] ppc64: SM... |
150 |
/* This isn't exactly a DMA mapping here, I suspect |
1da177e4c Linux-2.6.12-rc2 |
151 152 153 |
* the SMU is actually communicating with us via i2c to the * northbridge or the CPU to access RAM. */ |
0365ba7fb [PATCH] ppc64: SM... |
154 |
writel(smu->cmd_buf_abs, smu->db_buf); |
1da177e4c Linux-2.6.12-rc2 |
155 156 |
/* Ring the SMU doorbell */ |
0365ba7fb [PATCH] ppc64: SM... |
157 |
pmac_do_feature_call(PMAC_FTR_WRITE_GPIO, NULL, smu->doorbell, 4); |
1da177e4c Linux-2.6.12-rc2 |
158 |
} |
0365ba7fb [PATCH] ppc64: SM... |
159 |
|
7d12e780e IRQ: Maintain reg... |
160 |
static irqreturn_t smu_db_intr(int irq, void *arg) |
1da177e4c Linux-2.6.12-rc2 |
161 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
162 163 164 165 166 167 |
unsigned long flags; struct smu_cmd *cmd; void (*done)(struct smu_cmd *cmd, void *misc) = NULL; void *misc = NULL; u8 gpio; int rc = 0; |
1da177e4c Linux-2.6.12-rc2 |
168 |
|
0365ba7fb [PATCH] ppc64: SM... |
169 170 171 172 |
/* SMU completed the command, well, we hope, let's make sure * of it */ spin_lock_irqsave(&smu->lock, flags); |
1da177e4c Linux-2.6.12-rc2 |
173 |
|
0365ba7fb [PATCH] ppc64: SM... |
174 |
gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell); |
a44fe13ea [PATCH] Fix ppc64... |
175 176 |
if ((gpio & 7) != 7) { spin_unlock_irqrestore(&smu->lock, flags); |
0365ba7fb [PATCH] ppc64: SM... |
177 |
return IRQ_HANDLED; |
a44fe13ea [PATCH] Fix ppc64... |
178 |
} |
0365ba7fb [PATCH] ppc64: SM... |
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
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 |
efad798b9 Spelling fixes: l... |
193 |
* reply length (it's only 2 cache lines anyway) |
0365ba7fb [PATCH] ppc64: SM... |
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
*/ 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 ", ack, smu->cmd_buf->cmd); rc = -EIO; } reply_len = rc == 0 ? smu->cmd_buf->length : 0; DPRINTK("SMU: reply len: %d ", reply_len); if (reply_len > cmd->reply_len) { printk(KERN_WARNING "SMU: reply buffer too small," "got %d bytes for a %d bytes buffer ", 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; |
592a607bb [POWERPC] Disable... |
228 229 230 231 |
/* Re-enable NAP mode */ if (smu->broken_nap) powersave_nap = 1; |
0365ba7fb [PATCH] ppc64: SM... |
232 233 234 235 236 237 238 239 240 241 242 |
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; |
1da177e4c Linux-2.6.12-rc2 |
243 |
} |
0365ba7fb [PATCH] ppc64: SM... |
244 |
|
7d12e780e IRQ: Maintain reg... |
245 |
static irqreturn_t smu_msg_intr(int irq, void *arg) |
1da177e4c Linux-2.6.12-rc2 |
246 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
247 248 249 250 251 252 253 |
/* 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 ! "); |
1da177e4c Linux-2.6.12-rc2 |
254 |
|
0365ba7fb [PATCH] ppc64: SM... |
255 256 257 |
/* It's an edge interrupt, nothing to do */ return IRQ_HANDLED; } |
1da177e4c Linux-2.6.12-rc2 |
258 |
|
1da177e4c Linux-2.6.12-rc2 |
259 |
|
0365ba7fb [PATCH] ppc64: SM... |
260 261 262 263 |
/* * Queued command management. * */ |
1da177e4c Linux-2.6.12-rc2 |
264 |
|
0365ba7fb [PATCH] ppc64: SM... |
265 266 267 |
int smu_queue_cmd(struct smu_cmd *cmd) { unsigned long flags; |
1da177e4c Linux-2.6.12-rc2 |
268 |
|
0365ba7fb [PATCH] ppc64: SM... |
269 270 271 272 273 274 275 276 277 278 279 280 |
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); |
f620753b9 [PATCH] powerpc: ... |
281 282 283 |
/* Workaround for early calls when irq isn't available */ if (!smu_irq_inited || smu->db_irq == NO_IRQ) smu_spinwait_cmd(cmd); |
0365ba7fb [PATCH] ppc64: SM... |
284 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
285 |
} |
0365ba7fb [PATCH] ppc64: SM... |
286 |
EXPORT_SYMBOL(smu_queue_cmd); |
1da177e4c Linux-2.6.12-rc2 |
287 |
|
0365ba7fb [PATCH] ppc64: SM... |
288 289 290 291 292 |
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, ...) |
1da177e4c Linux-2.6.12-rc2 |
293 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
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); |
1da177e4c Linux-2.6.12-rc2 |
316 |
} |
0365ba7fb [PATCH] ppc64: SM... |
317 |
EXPORT_SYMBOL(smu_queue_simple); |
1da177e4c Linux-2.6.12-rc2 |
318 |
|
0365ba7fb [PATCH] ppc64: SM... |
319 320 |
void smu_poll(void) |
1da177e4c Linux-2.6.12-rc2 |
321 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
322 323 324 325 326 327 328 |
u8 gpio; if (smu == NULL) return; gpio = pmac_do_feature_call(PMAC_FTR_READ_GPIO, NULL, smu->doorbell); if ((gpio & 7) == 7) |
7d12e780e IRQ: Maintain reg... |
329 |
smu_db_intr(smu->db_irq, smu); |
1da177e4c Linux-2.6.12-rc2 |
330 |
} |
0365ba7fb [PATCH] ppc64: SM... |
331 |
EXPORT_SYMBOL(smu_poll); |
1da177e4c Linux-2.6.12-rc2 |
332 |
|
0365ba7fb [PATCH] ppc64: SM... |
333 |
void smu_done_complete(struct smu_cmd *cmd, void *misc) |
1da177e4c Linux-2.6.12-rc2 |
334 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
335 336 337 |
struct completion *comp = misc; complete(comp); |
1da177e4c Linux-2.6.12-rc2 |
338 |
} |
0365ba7fb [PATCH] ppc64: SM... |
339 |
EXPORT_SYMBOL(smu_done_complete); |
1da177e4c Linux-2.6.12-rc2 |
340 |
|
0365ba7fb [PATCH] ppc64: SM... |
341 |
void smu_spinwait_cmd(struct smu_cmd *cmd) |
1da177e4c Linux-2.6.12-rc2 |
342 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
343 344 345 346 347 348 349 350 351 352 |
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); |
1da177e4c Linux-2.6.12-rc2 |
353 |
} |
0365ba7fb [PATCH] ppc64: SM... |
354 355 |
static inline int hex2bcd (int n) |
1da177e4c Linux-2.6.12-rc2 |
356 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
357 |
return ((n / 10) << 4) + (n % 10); |
1da177e4c Linux-2.6.12-rc2 |
358 |
} |
0365ba7fb [PATCH] ppc64: SM... |
359 |
|
1da177e4c Linux-2.6.12-rc2 |
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
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); } |
1da177e4c Linux-2.6.12-rc2 |
375 |
|
0365ba7fb [PATCH] ppc64: SM... |
376 |
int smu_get_rtc_time(struct rtc_time *time, int spinwait) |
1da177e4c Linux-2.6.12-rc2 |
377 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
378 |
struct smu_simple_cmd cmd; |
1da177e4c Linux-2.6.12-rc2 |
379 380 381 382 383 384 |
int rc; if (smu == NULL) return -ENODEV; memset(time, 0, sizeof(struct rtc_time)); |
0365ba7fb [PATCH] ppc64: SM... |
385 386 387 388 389 |
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); |
1da177e4c Linux-2.6.12-rc2 |
390 |
|
0365ba7fb [PATCH] ppc64: SM... |
391 392 393 394 395 396 397 398 399 |
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; |
1da177e4c Linux-2.6.12-rc2 |
400 |
} |
0365ba7fb [PATCH] ppc64: SM... |
401 402 |
int smu_set_rtc_time(struct rtc_time *time, int spinwait) |
1da177e4c Linux-2.6.12-rc2 |
403 |
{ |
0365ba7fb [PATCH] ppc64: SM... |
404 |
struct smu_simple_cmd cmd; |
1da177e4c Linux-2.6.12-rc2 |
405 406 407 408 |
int rc; if (smu == NULL) return -ENODEV; |
0365ba7fb [PATCH] ppc64: SM... |
409 410 411 412 413 414 415 416 417 418 419 420 |
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); |
1da177e4c Linux-2.6.12-rc2 |
421 |
|
0365ba7fb [PATCH] ppc64: SM... |
422 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
423 |
} |
0365ba7fb [PATCH] ppc64: SM... |
424 |
|
1da177e4c Linux-2.6.12-rc2 |
425 426 |
void smu_shutdown(void) { |
0365ba7fb [PATCH] ppc64: SM... |
427 |
struct smu_simple_cmd cmd; |
1da177e4c Linux-2.6.12-rc2 |
428 429 430 |
if (smu == NULL) return; |
0365ba7fb [PATCH] ppc64: SM... |
431 432 433 434 |
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); |
1da177e4c Linux-2.6.12-rc2 |
435 436 |
for (;;) ; |
1da177e4c Linux-2.6.12-rc2 |
437 |
} |
0365ba7fb [PATCH] ppc64: SM... |
438 |
|
1da177e4c Linux-2.6.12-rc2 |
439 440 |
void smu_restart(void) { |
0365ba7fb [PATCH] ppc64: SM... |
441 |
struct smu_simple_cmd cmd; |
1da177e4c Linux-2.6.12-rc2 |
442 443 444 |
if (smu == NULL) return; |
0365ba7fb [PATCH] ppc64: SM... |
445 446 447 448 |
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); |
1da177e4c Linux-2.6.12-rc2 |
449 450 |
for (;;) ; |
1da177e4c Linux-2.6.12-rc2 |
451 |
} |
0365ba7fb [PATCH] ppc64: SM... |
452 |
|
1da177e4c Linux-2.6.12-rc2 |
453 454 455 456 |
int smu_present(void) { return smu != NULL; } |
0365ba7fb [PATCH] ppc64: SM... |
457 |
EXPORT_SYMBOL(smu_present); |
1da177e4c Linux-2.6.12-rc2 |
458 |
|
183d02025 [PATCH] ppc64: SM... |
459 |
int __init smu_init (void) |
1da177e4c Linux-2.6.12-rc2 |
460 461 |
{ struct device_node *np; |
018a3d1db [POWERPC] powerma... |
462 |
const u32 *data; |
73f38fe1b drivers/macintosh... |
463 |
int ret = 0; |
1da177e4c Linux-2.6.12-rc2 |
464 465 466 467 |
np = of_find_node_by_type(NULL, "smu"); if (np == NULL) return -ENODEV; |
592a607bb [POWERPC] Disable... |
468 469 |
printk(KERN_INFO "SMU: Driver %s %s ", VERSION, AUTHOR); |
0365ba7fb [PATCH] ppc64: SM... |
470 |
|
1da177e4c Linux-2.6.12-rc2 |
471 472 473 |
if (smu_cmdbuf_abs == 0) { printk(KERN_ERR "SMU: Command buffer not allocated ! "); |
73f38fe1b drivers/macintosh... |
474 475 |
ret = -EINVAL; goto fail_np; |
1da177e4c Linux-2.6.12-rc2 |
476 477 478 |
} smu = alloc_bootmem(sizeof(struct smu_device)); |
1da177e4c Linux-2.6.12-rc2 |
479 480 |
spin_lock_init(&smu->lock); |
0365ba7fb [PATCH] ppc64: SM... |
481 482 |
INIT_LIST_HEAD(&smu->cmd_list); INIT_LIST_HEAD(&smu->cmd_i2c_list); |
1da177e4c Linux-2.6.12-rc2 |
483 |
smu->of_node = np; |
0365ba7fb [PATCH] ppc64: SM... |
484 485 |
smu->db_irq = NO_IRQ; smu->msg_irq = NO_IRQ; |
0365ba7fb [PATCH] ppc64: SM... |
486 |
|
1da177e4c Linux-2.6.12-rc2 |
487 488 489 490 491 |
/* 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; smu->cmd_buf = (struct smu_cmd_buf *)abs_to_virt(smu_cmdbuf_abs); |
f620753b9 [PATCH] powerpc: ... |
492 493 |
smu->db_node = of_find_node_by_name(NULL, "smu-doorbell"); if (smu->db_node == NULL) { |
1da177e4c Linux-2.6.12-rc2 |
494 495 |
printk(KERN_ERR "SMU: Can't find doorbell GPIO ! "); |
73f38fe1b drivers/macintosh... |
496 497 |
ret = -ENXIO; goto fail_bootmem; |
1da177e4c Linux-2.6.12-rc2 |
498 |
} |
01b2726dd [POWERPC] Rename ... |
499 |
data = of_get_property(smu->db_node, "reg", NULL); |
1da177e4c Linux-2.6.12-rc2 |
500 501 502 |
if (data == NULL) { printk(KERN_ERR "SMU: Can't find doorbell GPIO address ! "); |
73f38fe1b drivers/macintosh... |
503 504 |
ret = -ENXIO; goto fail_db_node; |
1da177e4c Linux-2.6.12-rc2 |
505 506 507 508 509 510 |
} /* 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. */ |
0365ba7fb [PATCH] ppc64: SM... |
511 512 513 |
smu->doorbell = *data; if (smu->doorbell < 0x50) smu->doorbell += 0x50; |
0365ba7fb [PATCH] ppc64: SM... |
514 515 516 |
/* Now look for the smu-interrupt GPIO */ do { |
f620753b9 [PATCH] powerpc: ... |
517 518 |
smu->msg_node = of_find_node_by_name(NULL, "smu-interrupt"); if (smu->msg_node == NULL) |
0365ba7fb [PATCH] ppc64: SM... |
519 |
break; |
01b2726dd [POWERPC] Rename ... |
520 |
data = of_get_property(smu->msg_node, "reg", NULL); |
0365ba7fb [PATCH] ppc64: SM... |
521 |
if (data == NULL) { |
f620753b9 [PATCH] powerpc: ... |
522 523 |
of_node_put(smu->msg_node); smu->msg_node = NULL; |
0365ba7fb [PATCH] ppc64: SM... |
524 525 526 527 528 |
break; } smu->msg = *data; if (smu->msg < 0x50) smu->msg += 0x50; |
0365ba7fb [PATCH] ppc64: SM... |
529 |
} while(0); |
1da177e4c Linux-2.6.12-rc2 |
530 531 532 533 534 535 536 537 538 |
/* 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 ! "); |
73f38fe1b drivers/macintosh... |
539 540 |
ret = -ENXIO; goto fail_msg_node; |
1da177e4c Linux-2.6.12-rc2 |
541 |
} |
592a607bb [POWERPC] Disable... |
542 543 544 545 546 |
/* 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 "); |
1da177e4c Linux-2.6.12-rc2 |
547 548 |
sys_ctrler = SYS_CTRLER_SMU; return 0; |
73f38fe1b drivers/macintosh... |
549 550 551 552 553 554 555 |
fail_msg_node: if (smu->msg_node) of_node_put(smu->msg_node); fail_db_node: of_node_put(smu->db_node); fail_bootmem: free_bootmem((unsigned long)smu, sizeof(struct smu_device)); |
1da177e4c Linux-2.6.12-rc2 |
556 |
smu = NULL; |
73f38fe1b drivers/macintosh... |
557 558 559 |
fail_np: of_node_put(np); return ret; |
1da177e4c Linux-2.6.12-rc2 |
560 |
} |
0365ba7fb [PATCH] ppc64: SM... |
561 562 563 564 565 566 |
static int smu_late_init(void) { if (!smu) return 0; |
730745a5c [PATCH] 1/5 power... |
567 568 569 |
init_timer(&smu->i2c_timer); smu->i2c_timer.function = smu_i2c_retry; smu->i2c_timer.data = (unsigned long)smu; |
f620753b9 [PATCH] powerpc: ... |
570 571 572 573 574 575 576 577 578 579 580 581 582 583 |
if (smu->db_node) { smu->db_irq = irq_of_parse_and_map(smu->db_node, 0); if (smu->db_irq == NO_IRQ) printk(KERN_ERR "smu: failed to map irq for node %s ", smu->db_node->full_name); } if (smu->msg_node) { smu->msg_irq = irq_of_parse_and_map(smu->msg_node, 0); if (smu->msg_irq == NO_IRQ) printk(KERN_ERR "smu: failed to map irq for node %s ", smu->msg_node->full_name); } |
0365ba7fb [PATCH] ppc64: SM... |
584 585 586 587 588 589 |
/* * Try to request the interrupts */ if (smu->db_irq != NO_IRQ) { if (request_irq(smu->db_irq, smu_db_intr, |
dace14537 [PATCH] irq-flags... |
590 |
IRQF_SHARED, "SMU doorbell", smu) < 0) { |
0365ba7fb [PATCH] ppc64: SM... |
591 592 593 594 595 596 597 598 599 600 |
printk(KERN_WARNING "SMU: can't " "request interrupt %d ", smu->db_irq); smu->db_irq = NO_IRQ; } } if (smu->msg_irq != NO_IRQ) { if (request_irq(smu->msg_irq, smu_msg_intr, |
dace14537 [PATCH] irq-flags... |
601 |
IRQF_SHARED, "SMU message", smu) < 0) { |
0365ba7fb [PATCH] ppc64: SM... |
602 603 604 605 606 607 608 |
printk(KERN_WARNING "SMU: can't " "request interrupt %d ", smu->msg_irq); smu->msg_irq = NO_IRQ; } } |
f620753b9 [PATCH] powerpc: ... |
609 |
smu_irq_inited = 1; |
0365ba7fb [PATCH] ppc64: SM... |
610 611 |
return 0; } |
730745a5c [PATCH] 1/5 power... |
612 613 614 615 |
/* 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); |
0365ba7fb [PATCH] ppc64: SM... |
616 617 618 619 |
/* * sysfs visibility */ |
c4028958b WorkStruct: make ... |
620 |
static void smu_expose_childs(struct work_struct *unused) |
0365ba7fb [PATCH] ppc64: SM... |
621 |
{ |
a28d3af2a [PATCH] 2/5 power... |
622 623 624 |
struct device_node *np; for (np = NULL; (np = of_get_next_child(smu->of_node, np)) != NULL;) |
55b61fec2 [POWERPC] Rename ... |
625 |
if (of_device_is_compatible(np, "smu-sensors")) |
730745a5c [PATCH] 1/5 power... |
626 627 |
of_platform_device_create(np, "smu-sensors", &smu->of_dev->dev); |
0365ba7fb [PATCH] ppc64: SM... |
628 |
} |
c4028958b WorkStruct: make ... |
629 |
static DECLARE_WORK(smu_expose_childs_work, smu_expose_childs); |
0365ba7fb [PATCH] ppc64: SM... |
630 |
|
000061245 dt/powerpc: Elimi... |
631 |
static int smu_platform_probe(struct platform_device* dev) |
0365ba7fb [PATCH] ppc64: SM... |
632 633 634 635 636 637 638 639 640 641 642 643 644 |
{ 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; } |
46759a7c1 powerpc/macintosh... |
645 |
static const struct of_device_id smu_platform_match[] = |
0365ba7fb [PATCH] ppc64: SM... |
646 647 648 649 650 651 |
{ { .type = "smu", }, {}, }; |
000061245 dt/powerpc: Elimi... |
652 |
static struct platform_driver smu_of_platform_driver = |
0365ba7fb [PATCH] ppc64: SM... |
653 |
{ |
4018294b5 of: Remove duplic... |
654 655 656 657 658 |
.driver = { .name = "smu", .owner = THIS_MODULE, .of_match_table = smu_platform_match, }, |
0365ba7fb [PATCH] ppc64: SM... |
659 660 661 662 663 |
.probe = smu_platform_probe, }; static int __init smu_init_sysfs(void) { |
0365ba7fb [PATCH] ppc64: SM... |
664 |
/* |
0365ba7fb [PATCH] ppc64: SM... |
665 666 667 668 |
* 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 */ |
000061245 dt/powerpc: Elimi... |
669 |
platform_driver_register(&smu_of_platform_driver); |
0365ba7fb [PATCH] ppc64: SM... |
670 671 672 673 |
return 0; } device_initcall(smu_init_sysfs); |
2dc115813 of/device: Replac... |
674 |
struct platform_device *smu_get_ofdev(void) |
0365ba7fb [PATCH] ppc64: SM... |
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 |
{ 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 ", !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); } static void smu_i2c_retry(unsigned long data) { |
730745a5c [PATCH] 1/5 power... |
740 |
struct smu_i2c_cmd *cmd = smu->cmd_i2c_cur; |
0365ba7fb [PATCH] ppc64: SM... |
741 742 743 744 745 746 |
DPRINTK("SMU: i2c failure, requeuing... "); /* requeue command simply by resetting reply_len */ cmd->pdata[0] = 0xff; |
730745a5c [PATCH] 1/5 power... |
747 |
cmd->scmd.reply_len = sizeof(cmd->pdata); |
0365ba7fb [PATCH] ppc64: SM... |
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 |
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 ", 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... "); |
730745a5c [PATCH] 1/5 power... |
778 |
BUG_ON(cmd != smu->cmd_i2c_cur); |
f620753b9 [PATCH] powerpc: ... |
779 780 781 782 783 |
if (!smu_irq_inited) { mdelay(5); smu_i2c_retry(0); return; } |
730745a5c [PATCH] 1/5 power... |
784 |
mod_timer(&smu->i2c_timer, jiffies + msecs_to_jiffies(5)); |
0365ba7fb [PATCH] ppc64: SM... |
785 786 787 788 789 790 791 792 793 794 795 796 797 798 |
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 "); /* Ok, initial command complete, now poll status */ scmd->reply_buf = cmd->pdata; |
730745a5c [PATCH] 1/5 power... |
799 |
scmd->reply_len = sizeof(cmd->pdata); |
0365ba7fb [PATCH] ppc64: SM... |
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 |
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; |
730745a5c [PATCH] 1/5 power... |
821 |
cmd->scmd.reply_len = sizeof(cmd->pdata); |
0365ba7fb [PATCH] ppc64: SM... |
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 |
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 "); DPRINTK("SMU: %s, len=%d bus=%x addr=%x sub0=%x type=%x ", 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; } |
183d02025 [PATCH] ppc64: SM... |
885 886 887 888 889 890 |
/* * Handling of "partitions" */ static int smu_read_datablock(u8 *dest, unsigned int addr, unsigned int len) { |
6e9a4738c [PATCH] completio... |
891 |
DECLARE_COMPLETION_ONSTACK(comp); |
183d02025 [PATCH] ppc64: SM... |
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 |
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 ", 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) { |
6e9a4738c [PATCH] completio... |
939 |
DECLARE_COMPLETION_ONSTACK(comp); |
183d02025 [PATCH] ppc64: SM... |
940 941 942 943 944 945 |
struct smu_simple_cmd cmd; unsigned int addr, len, tlen; struct smu_sdbp_header *hdr; struct property *prop; /* First query the partition info */ |
1beb6a7d6 [PATCH] powerpc: ... |
946 947 |
DPRINTK("SMU: Query partition infos ... (irq=%d) ", smu->db_irq); |
183d02025 [PATCH] ppc64: SM... |
948 949 950 951 |
smu_queue_simple(&cmd, SMU_CMD_PARTITION_COMMAND, 2, smu_done_complete, &comp, SMU_CMD_PARTITION_LATEST, id); wait_for_completion(&comp); |
1beb6a7d6 [PATCH] powerpc: ... |
952 953 954 |
DPRINTK("SMU: done, status: %d, reply_len: %d ", cmd.cmd.status, cmd.cmd.reply_len); |
183d02025 [PATCH] ppc64: SM... |
955 956 957 958 959 960 961 962 963 964 965 966 |
/* 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; |
cd8612808 [PATCH] Fix numer... |
967 |
prop = kzalloc(tlen, GFP_KERNEL); |
183d02025 [PATCH] ppc64: SM... |
968 969 970 971 972 973 |
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; |
1a38147ed [POWERPC] Make st... |
974 |
prop->value = hdr; |
183d02025 [PATCH] ppc64: SM... |
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 |
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 ! ", 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 ! ", id, hdr->id); goto failure; } if (prom_add_property(smu->of_node, prop)) { printk(KERN_DEBUG "SMU: Failed creating sdb-partition-%02x " "property ! ", 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 */ |
018a3d1db [POWERPC] powerma... |
1008 1009 |
const struct smu_sdbp_header *__smu_get_sdb_partition(int id, unsigned int *size, int interruptible) |
4350147a8 [PATCH] ppc64: SM... |
1010 1011 |
{ char pname[32]; |
018a3d1db [POWERPC] powerma... |
1012 |
const struct smu_sdbp_header *part; |
4350147a8 [PATCH] ppc64: SM... |
1013 1014 1015 1016 1017 |
if (!smu) return NULL; sprintf(pname, "sdb-partition-%02x", id); |
183d02025 [PATCH] ppc64: SM... |
1018 |
|
1beb6a7d6 [PATCH] powerpc: ... |
1019 1020 |
DPRINTK("smu_get_sdb_partition(%02x) ", id); |
183d02025 [PATCH] ppc64: SM... |
1021 1022 |
if (interruptible) { int rc; |
14cc3e2b6 [PATCH] sem2mutex... |
1023 |
rc = mutex_lock_interruptible(&smu_part_access); |
183d02025 [PATCH] ppc64: SM... |
1024 1025 1026 |
if (rc) return ERR_PTR(rc); } else |
14cc3e2b6 [PATCH] sem2mutex... |
1027 |
mutex_lock(&smu_part_access); |
183d02025 [PATCH] ppc64: SM... |
1028 |
|
01b2726dd [POWERPC] Rename ... |
1029 |
part = of_get_property(smu->of_node, pname, size); |
183d02025 [PATCH] ppc64: SM... |
1030 |
if (part == NULL) { |
1beb6a7d6 [PATCH] powerpc: ... |
1031 1032 |
DPRINTK("trying to extract from SMU ... "); |
183d02025 [PATCH] ppc64: SM... |
1033 1034 1035 1036 |
part = smu_create_sdb_partition(id); if (part != NULL && size) *size = part->len << 2; } |
14cc3e2b6 [PATCH] sem2mutex... |
1037 |
mutex_unlock(&smu_part_access); |
183d02025 [PATCH] ppc64: SM... |
1038 1039 |
return part; } |
018a3d1db [POWERPC] powerma... |
1040 |
const struct smu_sdbp_header *smu_get_sdb_partition(int id, unsigned int *size) |
183d02025 [PATCH] ppc64: SM... |
1041 1042 |
{ return __smu_get_sdb_partition(id, size, 0); |
4350147a8 [PATCH] ppc64: SM... |
1043 1044 |
} EXPORT_SYMBOL(smu_get_sdb_partition); |
0365ba7fb [PATCH] ppc64: SM... |
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 |
/* * 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; |
dd00cc486 some kmalloc/mems... |
1077 |
pp = kzalloc(sizeof(struct smu_private), GFP_KERNEL); |
0365ba7fb [PATCH] ppc64: SM... |
1078 1079 |
if (pp == 0) return -ENOMEM; |
0365ba7fb [PATCH] ppc64: SM... |
1080 1081 1082 |
spin_lock_init(&pp->lock); pp->mode = smu_file_commands; init_waitqueue_head(&pp->wait); |
d851b6e04 mac: autoconvert ... |
1083 |
mutex_lock(&smu_mutex); |
0365ba7fb [PATCH] ppc64: SM... |
1084 1085 1086 1087 |
spin_lock_irqsave(&smu_clist_lock, flags); list_add(&pp->list, &smu_clist); spin_unlock_irqrestore(&smu_clist_lock, flags); file->private_data = pp; |
d851b6e04 mac: autoconvert ... |
1088 |
mutex_unlock(&smu_mutex); |
0365ba7fb [PATCH] ppc64: SM... |
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 |
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; |
183d02025 [PATCH] ppc64: SM... |
1117 |
} else if (hdr.cmdtype == SMU_CMDTYPE_GET_PARTITION) { |
018a3d1db [POWERPC] powerma... |
1118 |
const struct smu_sdbp_header *part; |
183d02025 [PATCH] ppc64: SM... |
1119 1120 1121 1122 1123 1124 |
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; |
0365ba7fb [PATCH] ppc64: SM... |
1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 |
} 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) { |
86e4754ac powerpc/pmac: Add... |
1174 1175 |
if (file->f_flags & O_NONBLOCK) { spin_unlock_irqrestore(&pp->lock, flags); |
0365ba7fb [PATCH] ppc64: SM... |
1176 |
return -EAGAIN; |
86e4754ac powerpc/pmac: Add... |
1177 |
} |
0365ba7fb [PATCH] ppc64: SM... |
1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
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; } static unsigned int smu_fpoll(struct file *file, poll_table *wait) { struct smu_private *pp = file->private_data; unsigned int mask = 0; 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) mask |= POLLIN; spin_unlock_irqrestore(&pp->lock, flags); } if (pp->mode == smu_file_events) { /* 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; |
0365ba7fb [PATCH] ppc64: SM... |
1285 |
spin_unlock_irqrestore(&pp->lock, flags); |
94256dd68 drivers/macintosh... |
1286 1287 |
schedule(); spin_lock_irqsave(&pp->lock, flags); |
0365ba7fb [PATCH] ppc64: SM... |
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 |
} 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; } |
fa027c2a0 [PATCH] mark stru... |
1301 |
static const struct file_operations smu_device_fops = { |
0365ba7fb [PATCH] ppc64: SM... |
1302 1303 1304 1305 1306 1307 1308 |
.llseek = no_llseek, .read = smu_read, .write = smu_write, .poll = smu_fpoll, .open = smu_open, .release = smu_release, }; |
6b67f62cf [PATCH] ppc64 g5:... |
1309 |
static struct miscdevice pmu_device = { |
0365ba7fb [PATCH] ppc64: SM... |
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 |
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. "); return 0; } device_initcall(smu_device_init); |