aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/char/hvc_iucv.c420
-rw-r--r--drivers/leds/Kconfig15
-rw-r--r--drivers/leds/Makefile2
-rw-r--r--drivers/leds/led-class.c24
-rw-r--r--drivers/leds/leds-alix2.c181
-rw-r--r--drivers/leds/leds-ams-delta.c33
-rw-r--r--drivers/leds/leds-clevo-mail.c21
-rw-r--r--drivers/leds/leds-fsg.c37
-rw-r--r--drivers/leds/leds-gpio.c36
-rw-r--r--drivers/leds/leds-hp-disk.c20
-rw-r--r--drivers/leds/leds-hp6xx.c22
-rw-r--r--drivers/leds/leds-net48xx.c21
-rw-r--r--drivers/leds/leds-pca9532.c77
-rw-r--r--drivers/leds/leds-s3c24xx.c25
-rw-r--r--drivers/leds/leds-wm8350.c311
-rw-r--r--drivers/leds/leds-wrap.c27
-rw-r--r--drivers/leds/ledtrig-timer.c5
-rw-r--r--drivers/mfd/wm8350-core.c3
-rw-r--r--drivers/oprofile/buffer_sync.c188
-rw-r--r--drivers/oprofile/cpu_buffer.c316
-rw-r--r--drivers/oprofile/cpu_buffer.h89
-rw-r--r--drivers/oprofile/event_buffer.c4
-rw-r--r--drivers/oprofile/oprof.c4
-rw-r--r--drivers/oprofile/oprof.h8
-rw-r--r--drivers/oprofile/oprofile_files.c27
-rw-r--r--drivers/regulator/wm8350-regulator.c91
-rw-r--r--drivers/s390/block/dasd.c21
-rw-r--r--drivers/s390/block/dasd_devmap.c48
-rw-r--r--drivers/s390/block/dasd_diag.c3
-rw-r--r--drivers/s390/block/dasd_eckd.c3
-rw-r--r--drivers/s390/block/dasd_fba.c3
-rw-r--r--drivers/s390/char/Kconfig2
-rw-r--r--drivers/s390/cio/qdio_debug.c2
-rw-r--r--drivers/video/backlight/Kconfig15
-rw-r--r--drivers/video/backlight/Makefile2
-rw-r--r--drivers/video/backlight/backlight.c73
-rw-r--r--drivers/video/backlight/corgi_bl.c169
-rw-r--r--drivers/video/backlight/cr_bllcd.c18
-rw-r--r--drivers/video/backlight/generic_bl.c147
-rw-r--r--drivers/video/backlight/hp680_bl.c20
-rw-r--r--drivers/video/backlight/mbp_nvidia_bl.c1
-rw-r--r--drivers/video/backlight/progear_bl.c20
-rw-r--r--drivers/video/backlight/tdo24m.c94
-rw-r--r--drivers/video/backlight/tosa_lcd.c27
-rw-r--r--drivers/video/backlight/vgg2432a4.c2
45 files changed, 1735 insertions, 942 deletions
diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c
index 5ea7d7713fca..a53496828b76 100644
--- a/drivers/char/hvc_iucv.c
+++ b/drivers/char/hvc_iucv.c
@@ -1,26 +1,30 @@
1/* 1/*
2 * hvc_iucv.c - z/VM IUCV back-end for the Hypervisor Console (HVC) 2 * hvc_iucv.c - z/VM IUCV hypervisor console (HVC) device driver
3 * 3 *
4 * This back-end for HVC provides terminal access via 4 * This HVC device driver provides terminal access using
5 * z/VM IUCV communication paths. 5 * z/VM IUCV communication paths.
6 * 6 *
7 * Copyright IBM Corp. 2008. 7 * Copyright IBM Corp. 2008
8 * 8 *
9 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com> 9 * Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
10 */ 10 */
11#define KMSG_COMPONENT "hvc_iucv" 11#define KMSG_COMPONENT "hvc_iucv"
12#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 13
13#include <linux/types.h> 14#include <linux/types.h>
14#include <asm/ebcdic.h> 15#include <asm/ebcdic.h>
16#include <linux/delay.h>
17#include <linux/init.h>
15#include <linux/mempool.h> 18#include <linux/mempool.h>
16#include <linux/module.h> 19#include <linux/module.h>
17#include <linux/tty.h> 20#include <linux/tty.h>
21#include <linux/wait.h>
18#include <net/iucv/iucv.h> 22#include <net/iucv/iucv.h>
19 23
20#include "hvc_console.h" 24#include "hvc_console.h"
21 25
22 26
23/* HVC backend for z/VM IUCV */ 27/* General device driver settings */
24#define HVC_IUCV_MAGIC 0xc9e4c3e5 28#define HVC_IUCV_MAGIC 0xc9e4c3e5
25#define MAX_HVC_IUCV_LINES HVC_ALLOC_TTY_ADAPTERS 29#define MAX_HVC_IUCV_LINES HVC_ALLOC_TTY_ADAPTERS
26#define MEMPOOL_MIN_NR (PAGE_SIZE / sizeof(struct iucv_tty_buffer)/4) 30#define MEMPOOL_MIN_NR (PAGE_SIZE / sizeof(struct iucv_tty_buffer)/4)
@@ -33,14 +37,14 @@
33#define MSG_TYPE_WINSIZE 0x08 /* Terminal window size update */ 37#define MSG_TYPE_WINSIZE 0x08 /* Terminal window size update */
34#define MSG_TYPE_DATA 0x10 /* Terminal data */ 38#define MSG_TYPE_DATA 0x10 /* Terminal data */
35 39
36#define MSG_SIZE(s) ((s) + offsetof(struct iucv_tty_msg, data))
37struct iucv_tty_msg { 40struct iucv_tty_msg {
38 u8 version; /* Message version */ 41 u8 version; /* Message version */
39 u8 type; /* Message type */ 42 u8 type; /* Message type */
40#define MSG_MAX_DATALEN (~(u16)0) 43#define MSG_MAX_DATALEN ((u16)(~0))
41 u16 datalen; /* Payload length */ 44 u16 datalen; /* Payload length */
42 u8 data[]; /* Payload buffer */ 45 u8 data[]; /* Payload buffer */
43} __attribute__((packed)); 46} __attribute__((packed));
47#define MSG_SIZE(s) ((s) + offsetof(struct iucv_tty_msg, data))
44 48
45enum iucv_state_t { 49enum iucv_state_t {
46 IUCV_DISCONN = 0, 50 IUCV_DISCONN = 0,
@@ -54,19 +58,26 @@ enum tty_state_t {
54}; 58};
55 59
56struct hvc_iucv_private { 60struct hvc_iucv_private {
57 struct hvc_struct *hvc; /* HVC console struct reference */ 61 struct hvc_struct *hvc; /* HVC struct reference */
58 u8 srv_name[8]; /* IUCV service name (ebcdic) */ 62 u8 srv_name[8]; /* IUCV service name (ebcdic) */
63 unsigned char is_console; /* Linux console usage flag */
59 enum iucv_state_t iucv_state; /* IUCV connection status */ 64 enum iucv_state_t iucv_state; /* IUCV connection status */
60 enum tty_state_t tty_state; /* TTY status */ 65 enum tty_state_t tty_state; /* TTY status */
61 struct iucv_path *path; /* IUCV path pointer */ 66 struct iucv_path *path; /* IUCV path pointer */
62 spinlock_t lock; /* hvc_iucv_private lock */ 67 spinlock_t lock; /* hvc_iucv_private lock */
68#define SNDBUF_SIZE (PAGE_SIZE) /* must be < MSG_MAX_DATALEN */
69 void *sndbuf; /* send buffer */
70 size_t sndbuf_len; /* length of send buffer */
71#define QUEUE_SNDBUF_DELAY (HZ / 25)
72 struct delayed_work sndbuf_work; /* work: send iucv msg(s) */
73 wait_queue_head_t sndbuf_waitq; /* wait for send completion */
63 struct list_head tty_outqueue; /* outgoing IUCV messages */ 74 struct list_head tty_outqueue; /* outgoing IUCV messages */
64 struct list_head tty_inqueue; /* incoming IUCV messages */ 75 struct list_head tty_inqueue; /* incoming IUCV messages */
65}; 76};
66 77
67struct iucv_tty_buffer { 78struct iucv_tty_buffer {
68 struct list_head list; /* list pointer */ 79 struct list_head list; /* list pointer */
69 struct iucv_message msg; /* store an incoming IUCV message */ 80 struct iucv_message msg; /* store an IUCV message */
70 size_t offset; /* data buffer offset */ 81 size_t offset; /* data buffer offset */
71 struct iucv_tty_msg *mbuf; /* buffer to store input/output data */ 82 struct iucv_tty_msg *mbuf; /* buffer to store input/output data */
72}; 83};
@@ -78,11 +89,12 @@ static void hvc_iucv_msg_pending(struct iucv_path *, struct iucv_message *);
78static void hvc_iucv_msg_complete(struct iucv_path *, struct iucv_message *); 89static void hvc_iucv_msg_complete(struct iucv_path *, struct iucv_message *);
79 90
80 91
81/* Kernel module parameters */ 92/* Kernel module parameter: use one terminal device as default */
82static unsigned long hvc_iucv_devices; 93static unsigned long hvc_iucv_devices = 1;
83 94
84/* Array of allocated hvc iucv tty lines... */ 95/* Array of allocated hvc iucv tty lines... */
85static struct hvc_iucv_private *hvc_iucv_table[MAX_HVC_IUCV_LINES]; 96static struct hvc_iucv_private *hvc_iucv_table[MAX_HVC_IUCV_LINES];
97#define IUCV_HVC_CON_IDX (0)
86 98
87/* Kmem cache and mempool for iucv_tty_buffer elements */ 99/* Kmem cache and mempool for iucv_tty_buffer elements */
88static struct kmem_cache *hvc_iucv_buffer_cache; 100static struct kmem_cache *hvc_iucv_buffer_cache;
@@ -112,7 +124,7 @@ struct hvc_iucv_private *hvc_iucv_get_private(uint32_t num)
112} 124}
113 125
114/** 126/**
115 * alloc_tty_buffer() - Returns a new struct iucv_tty_buffer element. 127 * alloc_tty_buffer() - Return a new struct iucv_tty_buffer element.
116 * @size: Size of the internal buffer used to store data. 128 * @size: Size of the internal buffer used to store data.
117 * @flags: Memory allocation flags passed to mempool. 129 * @flags: Memory allocation flags passed to mempool.
118 * 130 *
@@ -120,7 +132,6 @@ struct hvc_iucv_private *hvc_iucv_get_private(uint32_t num)
120 * allocates an internal data buffer with the specified size @size. 132 * allocates an internal data buffer with the specified size @size.
121 * Note: The total message size arises from the internal buffer size and the 133 * Note: The total message size arises from the internal buffer size and the
122 * members of the iucv_tty_msg structure. 134 * members of the iucv_tty_msg structure.
123 *
124 * The function returns NULL if memory allocation has failed. 135 * The function returns NULL if memory allocation has failed.
125 */ 136 */
126static struct iucv_tty_buffer *alloc_tty_buffer(size_t size, gfp_t flags) 137static struct iucv_tty_buffer *alloc_tty_buffer(size_t size, gfp_t flags)
@@ -130,7 +141,7 @@ static struct iucv_tty_buffer *alloc_tty_buffer(size_t size, gfp_t flags)
130 bufp = mempool_alloc(hvc_iucv_mempool, flags); 141 bufp = mempool_alloc(hvc_iucv_mempool, flags);
131 if (!bufp) 142 if (!bufp)
132 return NULL; 143 return NULL;
133 memset(bufp, 0, sizeof(struct iucv_tty_buffer)); 144 memset(bufp, 0, sizeof(*bufp));
134 145
135 if (size > 0) { 146 if (size > 0) {
136 bufp->msg.length = MSG_SIZE(size); 147 bufp->msg.length = MSG_SIZE(size);
@@ -149,9 +160,6 @@ static struct iucv_tty_buffer *alloc_tty_buffer(size_t size, gfp_t flags)
149/** 160/**
150 * destroy_tty_buffer() - destroy struct iucv_tty_buffer element. 161 * destroy_tty_buffer() - destroy struct iucv_tty_buffer element.
151 * @bufp: Pointer to a struct iucv_tty_buffer element, SHALL NOT be NULL. 162 * @bufp: Pointer to a struct iucv_tty_buffer element, SHALL NOT be NULL.
152 *
153 * The destroy_tty_buffer() function frees the internal data buffer and returns
154 * the struct iucv_tty_buffer element back to the mempool for freeing.
155 */ 163 */
156static void destroy_tty_buffer(struct iucv_tty_buffer *bufp) 164static void destroy_tty_buffer(struct iucv_tty_buffer *bufp)
157{ 165{
@@ -161,11 +169,7 @@ static void destroy_tty_buffer(struct iucv_tty_buffer *bufp)
161 169
162/** 170/**
163 * destroy_tty_buffer_list() - call destroy_tty_buffer() for each list element. 171 * destroy_tty_buffer_list() - call destroy_tty_buffer() for each list element.
164 * @list: List head pointer to a list containing struct iucv_tty_buffer 172 * @list: List containing struct iucv_tty_buffer elements.
165 * elements.
166 *
167 * Calls destroy_tty_buffer() for each struct iucv_tty_buffer element in the
168 * list @list.
169 */ 173 */
170static void destroy_tty_buffer_list(struct list_head *list) 174static void destroy_tty_buffer_list(struct list_head *list)
171{ 175{
@@ -178,24 +182,24 @@ static void destroy_tty_buffer_list(struct list_head *list)
178} 182}
179 183
180/** 184/**
181 * hvc_iucv_write() - Receive IUCV message write data to HVC console buffer. 185 * hvc_iucv_write() - Receive IUCV message & write data to HVC buffer.
182 * @priv: Pointer to hvc_iucv_private structure. 186 * @priv: Pointer to struct hvc_iucv_private
183 * @buf: HVC console buffer for writing received terminal data. 187 * @buf: HVC buffer for writing received terminal data.
184 * @count: HVC console buffer size. 188 * @count: HVC buffer size.
185 * @has_more_data: Pointer to an int variable. 189 * @has_more_data: Pointer to an int variable.
186 * 190 *
187 * The function picks up pending messages from the input queue and receives 191 * The function picks up pending messages from the input queue and receives
188 * the message data that is then written to the specified buffer @buf. 192 * the message data that is then written to the specified buffer @buf.
189 * If the buffer size @count is less than the data message size, then the 193 * If the buffer size @count is less than the data message size, the
190 * message is kept on the input queue and @has_more_data is set to 1. 194 * message is kept on the input queue and @has_more_data is set to 1.
191 * If the message data has been entirely written, the message is removed from 195 * If all message data has been written, the message is removed from
192 * the input queue. 196 * the input queue.
193 * 197 *
194 * The function returns the number of bytes written to the terminal, zero if 198 * The function returns the number of bytes written to the terminal, zero if
195 * there are no pending data messages available or if there is no established 199 * there are no pending data messages available or if there is no established
196 * IUCV path. 200 * IUCV path.
197 * If the IUCV path has been severed, then -EPIPE is returned to cause a 201 * If the IUCV path has been severed, then -EPIPE is returned to cause a
198 * hang up (that is issued by the HVC console layer). 202 * hang up (that is issued by the HVC layer).
199 */ 203 */
200static int hvc_iucv_write(struct hvc_iucv_private *priv, 204static int hvc_iucv_write(struct hvc_iucv_private *priv,
201 char *buf, int count, int *has_more_data) 205 char *buf, int count, int *has_more_data)
@@ -204,12 +208,12 @@ static int hvc_iucv_write(struct hvc_iucv_private *priv,
204 int written; 208 int written;
205 int rc; 209 int rc;
206 210
207 /* Immediately return if there is no IUCV connection */ 211 /* immediately return if there is no IUCV connection */
208 if (priv->iucv_state == IUCV_DISCONN) 212 if (priv->iucv_state == IUCV_DISCONN)
209 return 0; 213 return 0;
210 214
211 /* If the IUCV path has been severed, return -EPIPE to inform the 215 /* if the IUCV path has been severed, return -EPIPE to inform the
212 * hvc console layer to hang up the tty device. */ 216 * HVC layer to hang up the tty device. */
213 if (priv->iucv_state == IUCV_SEVERED) 217 if (priv->iucv_state == IUCV_SEVERED)
214 return -EPIPE; 218 return -EPIPE;
215 219
@@ -217,7 +221,7 @@ static int hvc_iucv_write(struct hvc_iucv_private *priv,
217 if (list_empty(&priv->tty_inqueue)) 221 if (list_empty(&priv->tty_inqueue))
218 return 0; 222 return 0;
219 223
220 /* receive a iucv message and flip data to the tty (ldisc) */ 224 /* receive an iucv message and flip data to the tty (ldisc) */
221 rb = list_first_entry(&priv->tty_inqueue, struct iucv_tty_buffer, list); 225 rb = list_first_entry(&priv->tty_inqueue, struct iucv_tty_buffer, list);
222 226
223 written = 0; 227 written = 0;
@@ -260,7 +264,7 @@ static int hvc_iucv_write(struct hvc_iucv_private *priv,
260 case MSG_TYPE_WINSIZE: 264 case MSG_TYPE_WINSIZE:
261 if (rb->mbuf->datalen != sizeof(struct winsize)) 265 if (rb->mbuf->datalen != sizeof(struct winsize))
262 break; 266 break;
263 hvc_resize(priv->hvc, *((struct winsize *)rb->mbuf->data)); 267 hvc_resize(priv->hvc, *((struct winsize *) rb->mbuf->data));
264 break; 268 break;
265 269
266 case MSG_TYPE_ERROR: /* ignored ... */ 270 case MSG_TYPE_ERROR: /* ignored ... */
@@ -284,10 +288,9 @@ out_written:
284 * @buf: Pointer to a buffer to store data 288 * @buf: Pointer to a buffer to store data
285 * @count: Size of buffer available for writing 289 * @count: Size of buffer available for writing
286 * 290 *
287 * The hvc_console thread calls this method to read characters from 291 * The HVC thread calls this method to read characters from the back-end.
288 * the terminal backend. If an IUCV communication path has been established, 292 * If an IUCV communication path has been established, pending IUCV messages
289 * pending IUCV messages are received and data is copied into buffer @buf 293 * are received and data is copied into buffer @buf up to @count bytes.
290 * up to @count bytes.
291 * 294 *
292 * Locking: The routine gets called under an irqsave() spinlock; and 295 * Locking: The routine gets called under an irqsave() spinlock; and
293 * the routine locks the struct hvc_iucv_private->lock to call 296 * the routine locks the struct hvc_iucv_private->lock to call
@@ -318,66 +321,122 @@ static int hvc_iucv_get_chars(uint32_t vtermno, char *buf, int count)
318} 321}
319 322
320/** 323/**
321 * hvc_iucv_send() - Send an IUCV message containing terminal data. 324 * hvc_iucv_queue() - Buffer terminal data for sending.
322 * @priv: Pointer to struct hvc_iucv_private instance. 325 * @priv: Pointer to struct hvc_iucv_private instance.
323 * @buf: Buffer containing data to send. 326 * @buf: Buffer containing data to send.
324 * @size: Size of buffer and amount of data to send. 327 * @count: Size of buffer and amount of data to send.
328 *
329 * The function queues data for sending. To actually send the buffered data,
330 * a work queue function is scheduled (with QUEUE_SNDBUF_DELAY).
331 * The function returns the number of data bytes that has been buffered.
325 * 332 *
326 * If an IUCV communication path is established, the function copies the buffer 333 * If the device is not connected, data is ignored and the function returns
327 * data to a newly allocated struct iucv_tty_buffer element, sends the data and 334 * @count.
328 * puts the element to the outqueue. 335 * If the buffer is full, the function returns 0.
336 * If an existing IUCV communicaton path has been severed, -EPIPE is returned
337 * (that can be passed to HVC layer to cause a tty hangup).
338 */
339static int hvc_iucv_queue(struct hvc_iucv_private *priv, const char *buf,
340 int count)
341{
342 size_t len;
343
344 if (priv->iucv_state == IUCV_DISCONN)
345 return count; /* ignore data */
346
347 if (priv->iucv_state == IUCV_SEVERED)
348 return -EPIPE;
349
350 len = min_t(size_t, count, SNDBUF_SIZE - priv->sndbuf_len);
351 if (!len)
352 return 0;
353
354 memcpy(priv->sndbuf + priv->sndbuf_len, buf, len);
355 priv->sndbuf_len += len;
356
357 if (priv->iucv_state == IUCV_CONNECTED)
358 schedule_delayed_work(&priv->sndbuf_work, QUEUE_SNDBUF_DELAY);
359
360 return len;
361}
362
363/**
364 * hvc_iucv_send() - Send an IUCV message containing terminal data.
365 * @priv: Pointer to struct hvc_iucv_private instance.
329 * 366 *
330 * If there is no IUCV communication path established, the function returns 0. 367 * If an IUCV communication path has been established, the buffered output data
331 * If an existing IUCV communicaton path has been severed, the function returns 368 * is sent via an IUCV message and the number of bytes sent is returned.
332 * -EPIPE (can be passed to HVC layer to cause a tty hangup). 369 * Returns 0 if there is no established IUCV communication path or
370 * -EPIPE if an existing IUCV communicaton path has been severed.
333 */ 371 */
334static int hvc_iucv_send(struct hvc_iucv_private *priv, const char *buf, 372static int hvc_iucv_send(struct hvc_iucv_private *priv)
335 int count)
336{ 373{
337 struct iucv_tty_buffer *sb; 374 struct iucv_tty_buffer *sb;
338 int rc; 375 int rc, len;
339 u16 len;
340 376
341 if (priv->iucv_state == IUCV_SEVERED) 377 if (priv->iucv_state == IUCV_SEVERED)
342 return -EPIPE; 378 return -EPIPE;
343 379
344 if (priv->iucv_state == IUCV_DISCONN) 380 if (priv->iucv_state == IUCV_DISCONN)
345 return 0; 381 return -EIO;
346 382
347 len = min_t(u16, MSG_MAX_DATALEN, count); 383 if (!priv->sndbuf_len)
384 return 0;
348 385
349 /* allocate internal buffer to store msg data and also compute total 386 /* allocate internal buffer to store msg data and also compute total
350 * message length */ 387 * message length */
351 sb = alloc_tty_buffer(len, GFP_ATOMIC); 388 sb = alloc_tty_buffer(priv->sndbuf_len, GFP_ATOMIC);
352 if (!sb) 389 if (!sb)
353 return -ENOMEM; 390 return -ENOMEM;
354 391
355 sb->mbuf->datalen = len; 392 memcpy(sb->mbuf->data, priv->sndbuf, priv->sndbuf_len);
356 memcpy(sb->mbuf->data, buf, len); 393 sb->mbuf->datalen = (u16) priv->sndbuf_len;
394 sb->msg.length = MSG_SIZE(sb->mbuf->datalen);
357 395
358 list_add_tail(&sb->list, &priv->tty_outqueue); 396 list_add_tail(&sb->list, &priv->tty_outqueue);
359 397
360 rc = __iucv_message_send(priv->path, &sb->msg, 0, 0, 398 rc = __iucv_message_send(priv->path, &sb->msg, 0, 0,
361 (void *) sb->mbuf, sb->msg.length); 399 (void *) sb->mbuf, sb->msg.length);
362 if (rc) { 400 if (rc) {
401 /* drop the message here; however we might want to handle
402 * 0x03 (msg limit reached) by trying again... */
363 list_del(&sb->list); 403 list_del(&sb->list);
364 destroy_tty_buffer(sb); 404 destroy_tty_buffer(sb);
365 len = 0;
366 } 405 }
406 len = priv->sndbuf_len;
407 priv->sndbuf_len = 0;
367 408
368 return len; 409 return len;
369} 410}
370 411
371/** 412/**
413 * hvc_iucv_sndbuf_work() - Send buffered data over IUCV
414 * @work: Work structure.
415 *
416 * This work queue function sends buffered output data over IUCV and,
417 * if not all buffered data could be sent, reschedules itself.
418 */
419static void hvc_iucv_sndbuf_work(struct work_struct *work)
420{
421 struct hvc_iucv_private *priv;
422
423 priv = container_of(work, struct hvc_iucv_private, sndbuf_work.work);
424 if (!priv)
425 return;
426
427 spin_lock_bh(&priv->lock);
428 hvc_iucv_send(priv);
429 spin_unlock_bh(&priv->lock);
430}
431
432/**
372 * hvc_iucv_put_chars() - HVC put_chars operation. 433 * hvc_iucv_put_chars() - HVC put_chars operation.
373 * @vtermno: HVC virtual terminal number. 434 * @vtermno: HVC virtual terminal number.
374 * @buf: Pointer to an buffer to read data from 435 * @buf: Pointer to an buffer to read data from
375 * @count: Size of buffer available for reading 436 * @count: Size of buffer available for reading
376 * 437 *
377 * The hvc_console thread calls this method to write characters from 438 * The HVC thread calls this method to write characters to the back-end.
378 * to the terminal backend. 439 * The function calls hvc_iucv_queue() to queue terminal data for sending.
379 * The function calls hvc_iucv_send() under the lock of the
380 * struct hvc_iucv_private instance that corresponds to the tty @vtermno.
381 * 440 *
382 * Locking: The method gets called under an irqsave() spinlock; and 441 * Locking: The method gets called under an irqsave() spinlock; and
383 * locks struct hvc_iucv_private->lock. 442 * locks struct hvc_iucv_private->lock.
@@ -385,7 +444,7 @@ static int hvc_iucv_send(struct hvc_iucv_private *priv, const char *buf,
385static int hvc_iucv_put_chars(uint32_t vtermno, const char *buf, int count) 444static int hvc_iucv_put_chars(uint32_t vtermno, const char *buf, int count)
386{ 445{
387 struct hvc_iucv_private *priv = hvc_iucv_get_private(vtermno); 446 struct hvc_iucv_private *priv = hvc_iucv_get_private(vtermno);
388 int sent; 447 int queued;
389 448
390 if (count <= 0) 449 if (count <= 0)
391 return 0; 450 return 0;
@@ -394,10 +453,10 @@ static int hvc_iucv_put_chars(uint32_t vtermno, const char *buf, int count)
394 return -ENODEV; 453 return -ENODEV;
395 454
396 spin_lock(&priv->lock); 455 spin_lock(&priv->lock);
397 sent = hvc_iucv_send(priv, buf, count); 456 queued = hvc_iucv_queue(priv, buf, count);
398 spin_unlock(&priv->lock); 457 spin_unlock(&priv->lock);
399 458
400 return sent; 459 return queued;
401} 460}
402 461
403/** 462/**
@@ -406,7 +465,7 @@ static int hvc_iucv_put_chars(uint32_t vtermno, const char *buf, int count)
406 * @id: Additional data (originally passed to hvc_alloc): the index of an struct 465 * @id: Additional data (originally passed to hvc_alloc): the index of an struct
407 * hvc_iucv_private instance. 466 * hvc_iucv_private instance.
408 * 467 *
409 * The function sets the tty state to TTY_OPEN for the struct hvc_iucv_private 468 * The function sets the tty state to TTY_OPENED for the struct hvc_iucv_private
410 * instance that is derived from @id. Always returns 0. 469 * instance that is derived from @id. Always returns 0.
411 * 470 *
412 * Locking: struct hvc_iucv_private->lock, spin_lock_bh 471 * Locking: struct hvc_iucv_private->lock, spin_lock_bh
@@ -427,12 +486,8 @@ static int hvc_iucv_notifier_add(struct hvc_struct *hp, int id)
427} 486}
428 487
429/** 488/**
430 * hvc_iucv_cleanup() - Clean up function if the tty portion is finally closed. 489 * hvc_iucv_cleanup() - Clean up and reset a z/VM IUCV HVC instance.
431 * @priv: Pointer to the struct hvc_iucv_private instance. 490 * @priv: Pointer to the struct hvc_iucv_private instance.
432 *
433 * The functions severs the established IUCV communication path (if any), and
434 * destroy struct iucv_tty_buffer elements from the in- and outqueue. Finally,
435 * the functions resets the states to TTY_CLOSED and IUCV_DISCONN.
436 */ 491 */
437static void hvc_iucv_cleanup(struct hvc_iucv_private *priv) 492static void hvc_iucv_cleanup(struct hvc_iucv_private *priv)
438{ 493{
@@ -441,25 +496,62 @@ static void hvc_iucv_cleanup(struct hvc_iucv_private *priv)
441 496
442 priv->tty_state = TTY_CLOSED; 497 priv->tty_state = TTY_CLOSED;
443 priv->iucv_state = IUCV_DISCONN; 498 priv->iucv_state = IUCV_DISCONN;
499
500 priv->sndbuf_len = 0;
444} 501}
445 502
446/** 503/**
447 * hvc_iucv_notifier_hangup() - HVC notifier for tty hangups. 504 * tty_outqueue_empty() - Test if the tty outq is empty
448 * @hp: Pointer to the HVC device (struct hvc_struct) 505 * @priv: Pointer to struct hvc_iucv_private instance.
449 * @id: Additional data (originally passed to hvc_alloc): the index of an struct 506 */
450 * hvc_iucv_private instance. 507static inline int tty_outqueue_empty(struct hvc_iucv_private *priv)
508{
509 int rc;
510
511 spin_lock_bh(&priv->lock);
512 rc = list_empty(&priv->tty_outqueue);
513 spin_unlock_bh(&priv->lock);
514
515 return rc;
516}
517
518/**
519 * flush_sndbuf_sync() - Flush send buffer and wait for completion
520 * @priv: Pointer to struct hvc_iucv_private instance.
451 * 521 *
452 * This routine notifies the HVC backend that a tty hangup (carrier loss, 522 * The routine cancels a pending sndbuf work, calls hvc_iucv_send()
453 * virtual or otherwise) has occured. 523 * to flush any buffered terminal output data and waits for completion.
524 */
525static void flush_sndbuf_sync(struct hvc_iucv_private *priv)
526{
527 int sync_wait;
528
529 cancel_delayed_work_sync(&priv->sndbuf_work);
530
531 spin_lock_bh(&priv->lock);
532 hvc_iucv_send(priv); /* force sending buffered data */
533 sync_wait = !list_empty(&priv->tty_outqueue); /* anything queued ? */
534 spin_unlock_bh(&priv->lock);
535
536 if (sync_wait)
537 wait_event_timeout(priv->sndbuf_waitq,
538 tty_outqueue_empty(priv), HZ);
539}
540
541/**
542 * hvc_iucv_notifier_hangup() - HVC notifier for TTY hangups.
543 * @hp: Pointer to the HVC device (struct hvc_struct)
544 * @id: Additional data (originally passed to hvc_alloc):
545 * the index of an struct hvc_iucv_private instance.
454 * 546 *
455 * The HVC backend for z/VM IUCV ignores virtual hangups (vhangup()), to keep 547 * This routine notifies the HVC back-end that a tty hangup (carrier loss,
456 * an existing IUCV communication path established. 548 * virtual or otherwise) has occured.
549 * The z/VM IUCV HVC device driver ignores virtual hangups (vhangup())
550 * to keep an existing IUCV communication path established.
457 * (Background: vhangup() is called from user space (by getty or login) to 551 * (Background: vhangup() is called from user space (by getty or login) to
458 * disable writing to the tty by other applications). 552 * disable writing to the tty by other applications).
459 * 553 * If the tty has been opened and an established IUCV path has been severed
460 * If the tty has been opened (e.g. getty) and an established IUCV path has been 554 * (we caused the tty hangup), the function calls hvc_iucv_cleanup().
461 * severed (we caused the tty hangup in that case), then the functions invokes
462 * hvc_iucv_cleanup() to clean up.
463 * 555 *
464 * Locking: struct hvc_iucv_private->lock 556 * Locking: struct hvc_iucv_private->lock
465 */ 557 */
@@ -471,12 +563,12 @@ static void hvc_iucv_notifier_hangup(struct hvc_struct *hp, int id)
471 if (!priv) 563 if (!priv)
472 return; 564 return;
473 565
566 flush_sndbuf_sync(priv);
567
474 spin_lock_bh(&priv->lock); 568 spin_lock_bh(&priv->lock);
475 /* NOTE: If the hangup was scheduled by ourself (from the iucv 569 /* NOTE: If the hangup was scheduled by ourself (from the iucv
476 * path_servered callback [IUCV_SEVERED]), then we have to 570 * path_servered callback [IUCV_SEVERED]), we have to clean up
477 * finally clean up the tty backend structure and set state to 571 * our structure and to set state to TTY_CLOSED.
478 * TTY_CLOSED.
479 *
480 * If the tty was hung up otherwise (e.g. vhangup()), then we 572 * If the tty was hung up otherwise (e.g. vhangup()), then we
481 * ignore this hangup and keep an established IUCV path open... 573 * ignore this hangup and keep an established IUCV path open...
482 * (...the reason is that we are not able to connect back to the 574 * (...the reason is that we are not able to connect back to the
@@ -494,10 +586,9 @@ static void hvc_iucv_notifier_hangup(struct hvc_struct *hp, int id)
494 * @id: Additional data (originally passed to hvc_alloc): 586 * @id: Additional data (originally passed to hvc_alloc):
495 * the index of an struct hvc_iucv_private instance. 587 * the index of an struct hvc_iucv_private instance.
496 * 588 *
497 * This routine notifies the HVC backend that the last tty device file 589 * This routine notifies the HVC back-end that the last tty device fd has been
498 * descriptor has been closed. 590 * closed. The function calls hvc_iucv_cleanup() to clean up the struct
499 * The function calls hvc_iucv_cleanup() to clean up the struct hvc_iucv_private 591 * hvc_iucv_private instance.
500 * instance.
501 * 592 *
502 * Locking: struct hvc_iucv_private->lock 593 * Locking: struct hvc_iucv_private->lock
503 */ 594 */
@@ -510,6 +601,8 @@ static void hvc_iucv_notifier_del(struct hvc_struct *hp, int id)
510 if (!priv) 601 if (!priv)
511 return; 602 return;
512 603
604 flush_sndbuf_sync(priv);
605
513 spin_lock_bh(&priv->lock); 606 spin_lock_bh(&priv->lock);
514 path = priv->path; /* save reference to IUCV path */ 607 path = priv->path; /* save reference to IUCV path */
515 priv->path = NULL; 608 priv->path = NULL;
@@ -527,20 +620,18 @@ static void hvc_iucv_notifier_del(struct hvc_struct *hp, int id)
527/** 620/**
528 * hvc_iucv_path_pending() - IUCV handler to process a connection request. 621 * hvc_iucv_path_pending() - IUCV handler to process a connection request.
529 * @path: Pending path (struct iucv_path) 622 * @path: Pending path (struct iucv_path)
530 * @ipvmid: Originator z/VM system identifier 623 * @ipvmid: z/VM system identifier of originator
531 * @ipuser: User specified data for this path 624 * @ipuser: User specified data for this path
532 * (AF_IUCV: port/service name and originator port) 625 * (AF_IUCV: port/service name and originator port)
533 * 626 *
534 * The function uses the @ipuser data to check to determine if the pending 627 * The function uses the @ipuser data to determine if the pending path belongs
535 * path belongs to a terminal managed by this HVC backend. 628 * to a terminal managed by this device driver.
536 * If the check is successful, then an additional check is done to ensure 629 * If the path belongs to this driver, ensure that the terminal is not accessed
537 * that a terminal cannot be accessed multiple times (only one connection 630 * multiple times (only one connection to a terminal is allowed).
538 * to a terminal is allowed). In that particular case, the pending path is 631 * If the terminal is not yet connected, the pending path is accepted and is
539 * severed. If it is the first connection, the pending path is accepted and 632 * associated to the appropriate struct hvc_iucv_private instance.
540 * associated to the struct hvc_iucv_private. The iucv state is updated to
541 * reflect that a communication path has been established.
542 * 633 *
543 * Returns 0 if the path belongs to a terminal managed by the this HVC backend; 634 * Returns 0 if @path belongs to a terminal managed by the this device driver;
544 * otherwise returns -ENODEV in order to dispatch this path to other handlers. 635 * otherwise returns -ENODEV in order to dispatch this path to other handlers.
545 * 636 *
546 * Locking: struct hvc_iucv_private->lock 637 * Locking: struct hvc_iucv_private->lock
@@ -559,7 +650,6 @@ static int hvc_iucv_path_pending(struct iucv_path *path,
559 priv = hvc_iucv_table[i]; 650 priv = hvc_iucv_table[i];
560 break; 651 break;
561 } 652 }
562
563 if (!priv) 653 if (!priv)
564 return -ENODEV; 654 return -ENODEV;
565 655
@@ -588,6 +678,9 @@ static int hvc_iucv_path_pending(struct iucv_path *path,
588 priv->path = path; 678 priv->path = path;
589 priv->iucv_state = IUCV_CONNECTED; 679 priv->iucv_state = IUCV_CONNECTED;
590 680
681 /* flush buffered output data... */
682 schedule_delayed_work(&priv->sndbuf_work, 5);
683
591out_path_handled: 684out_path_handled:
592 spin_unlock(&priv->lock); 685 spin_unlock(&priv->lock);
593 return 0; 686 return 0;
@@ -603,8 +696,7 @@ out_path_handled:
603 * sets the iucv state to IUCV_SEVERED for the associated struct 696 * sets the iucv state to IUCV_SEVERED for the associated struct
604 * hvc_iucv_private instance. Later, the IUCV_SEVERED state triggers a tty 697 * hvc_iucv_private instance. Later, the IUCV_SEVERED state triggers a tty
605 * hangup (hvc_iucv_get_chars() / hvc_iucv_write()). 698 * hangup (hvc_iucv_get_chars() / hvc_iucv_write()).
606 * 699 * If tty portion of the HVC is closed, clean up the outqueue.
607 * If tty portion of the HVC is closed then clean up the outqueue in addition.
608 * 700 *
609 * Locking: struct hvc_iucv_private->lock 701 * Locking: struct hvc_iucv_private->lock
610 */ 702 */
@@ -615,15 +707,25 @@ static void hvc_iucv_path_severed(struct iucv_path *path, u8 ipuser[16])
615 spin_lock(&priv->lock); 707 spin_lock(&priv->lock);
616 priv->iucv_state = IUCV_SEVERED; 708 priv->iucv_state = IUCV_SEVERED;
617 709
618 /* NOTE: If the tty has not yet been opened by a getty program 710 /* If the tty has not yet been opened, clean up the hvc_iucv_private
619 * (e.g. to see console messages), then cleanup the 711 * structure to allow re-connects.
620 * hvc_iucv_private structure to allow re-connects. 712 * This is also done for our console device because console hangups
713 * are handled specially and no notifier is called by HVC.
714 * The tty session is active (TTY_OPEN) and ready for re-connects...
621 * 715 *
622 * If the tty has been opened, the get_chars() callback returns 716 * If it has been opened, let get_chars() return -EPIPE to signal the
623 * -EPIPE to signal the hvc console layer to hang up the tty. */ 717 * HVC layer to hang up the tty.
718 * If so, we need to wake up the HVC thread to call get_chars()...
719 */
624 priv->path = NULL; 720 priv->path = NULL;
625 if (priv->tty_state == TTY_CLOSED) 721 if (priv->tty_state == TTY_CLOSED)
626 hvc_iucv_cleanup(priv); 722 hvc_iucv_cleanup(priv);
723 else
724 if (priv->is_console) {
725 hvc_iucv_cleanup(priv);
726 priv->tty_state = TTY_OPENED;
727 } else
728 hvc_kick();
627 spin_unlock(&priv->lock); 729 spin_unlock(&priv->lock);
628 730
629 /* finally sever path (outside of priv->lock due to lock ordering) */ 731 /* finally sever path (outside of priv->lock due to lock ordering) */
@@ -636,9 +738,9 @@ static void hvc_iucv_path_severed(struct iucv_path *path, u8 ipuser[16])
636 * @path: Pending path (struct iucv_path) 738 * @path: Pending path (struct iucv_path)
637 * @msg: Pointer to the IUCV message 739 * @msg: Pointer to the IUCV message
638 * 740 *
639 * The function stores an incoming message on the input queue for later 741 * The function puts an incoming message on the input queue for later
640 * processing (by hvc_iucv_get_chars() / hvc_iucv_write()). 742 * processing (by hvc_iucv_get_chars() / hvc_iucv_write()).
641 * However, if the tty has not yet been opened, the message is rejected. 743 * If the tty has not yet been opened, the message is rejected.
642 * 744 *
643 * Locking: struct hvc_iucv_private->lock 745 * Locking: struct hvc_iucv_private->lock
644 */ 746 */
@@ -648,6 +750,12 @@ static void hvc_iucv_msg_pending(struct iucv_path *path,
648 struct hvc_iucv_private *priv = path->private; 750 struct hvc_iucv_private *priv = path->private;
649 struct iucv_tty_buffer *rb; 751 struct iucv_tty_buffer *rb;
650 752
753 /* reject messages that exceed max size of iucv_tty_msg->datalen */
754 if (msg->length > MSG_SIZE(MSG_MAX_DATALEN)) {
755 iucv_message_reject(path, msg);
756 return;
757 }
758
651 spin_lock(&priv->lock); 759 spin_lock(&priv->lock);
652 760
653 /* reject messages if tty has not yet been opened */ 761 /* reject messages if tty has not yet been opened */
@@ -656,7 +764,7 @@ static void hvc_iucv_msg_pending(struct iucv_path *path,
656 goto unlock_return; 764 goto unlock_return;
657 } 765 }
658 766
659 /* allocate buffer an empty buffer element */ 767 /* allocate tty buffer to save iucv msg only */
660 rb = alloc_tty_buffer(0, GFP_ATOMIC); 768 rb = alloc_tty_buffer(0, GFP_ATOMIC);
661 if (!rb) { 769 if (!rb) {
662 iucv_message_reject(path, msg); 770 iucv_message_reject(path, msg);
@@ -666,7 +774,7 @@ static void hvc_iucv_msg_pending(struct iucv_path *path,
666 774
667 list_add_tail(&rb->list, &priv->tty_inqueue); 775 list_add_tail(&rb->list, &priv->tty_inqueue);
668 776
669 hvc_kick(); /* wakup hvc console thread */ 777 hvc_kick(); /* wake up hvc thread */
670 778
671unlock_return: 779unlock_return:
672 spin_unlock(&priv->lock); 780 spin_unlock(&priv->lock);
@@ -677,10 +785,10 @@ unlock_return:
677 * @path: Pending path (struct iucv_path) 785 * @path: Pending path (struct iucv_path)
678 * @msg: Pointer to the IUCV message 786 * @msg: Pointer to the IUCV message
679 * 787 *
680 * The function is called upon completion of message delivery and the 788 * The function is called upon completion of message delivery to remove the
681 * message is removed from the outqueue. Additional delivery information 789 * message from the outqueue. Additional delivery information can be found
682 * can be found in msg->audit: rejected messages (0x040000 (IPADRJCT)) and 790 * msg->audit: rejected messages (0x040000 (IPADRJCT)), and
683 * purged messages (0x010000 (IPADPGNR)). 791 * purged messages (0x010000 (IPADPGNR)).
684 * 792 *
685 * Locking: struct hvc_iucv_private->lock 793 * Locking: struct hvc_iucv_private->lock
686 */ 794 */
@@ -697,6 +805,7 @@ static void hvc_iucv_msg_complete(struct iucv_path *path,
697 list_move(&ent->list, &list_remove); 805 list_move(&ent->list, &list_remove);
698 break; 806 break;
699 } 807 }
808 wake_up(&priv->sndbuf_waitq);
700 spin_unlock(&priv->lock); 809 spin_unlock(&priv->lock);
701 destroy_tty_buffer_list(&list_remove); 810 destroy_tty_buffer_list(&list_remove);
702} 811}
@@ -713,13 +822,14 @@ static struct hv_ops hvc_iucv_ops = {
713 822
714/** 823/**
715 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance 824 * hvc_iucv_alloc() - Allocates a new struct hvc_iucv_private instance
716 * @id: hvc_iucv_table index 825 * @id: hvc_iucv_table index
826 * @is_console: Flag if the instance is used as Linux console
717 * 827 *
718 * This function allocates a new hvc_iucv_private struct and put the 828 * This function allocates a new hvc_iucv_private structure and stores
719 * instance into hvc_iucv_table at index @id. 829 * the instance in hvc_iucv_table at index @id.
720 * Returns 0 on success; otherwise non-zero. 830 * Returns 0 on success; otherwise non-zero.
721 */ 831 */
722static int __init hvc_iucv_alloc(int id) 832static int __init hvc_iucv_alloc(int id, unsigned int is_console)
723{ 833{
724 struct hvc_iucv_private *priv; 834 struct hvc_iucv_private *priv;
725 char name[9]; 835 char name[9];
@@ -732,18 +842,33 @@ static int __init hvc_iucv_alloc(int id)
732 spin_lock_init(&priv->lock); 842 spin_lock_init(&priv->lock);
733 INIT_LIST_HEAD(&priv->tty_outqueue); 843 INIT_LIST_HEAD(&priv->tty_outqueue);
734 INIT_LIST_HEAD(&priv->tty_inqueue); 844 INIT_LIST_HEAD(&priv->tty_inqueue);
845 INIT_DELAYED_WORK(&priv->sndbuf_work, hvc_iucv_sndbuf_work);
846 init_waitqueue_head(&priv->sndbuf_waitq);
847
848 priv->sndbuf = (void *) get_zeroed_page(GFP_KERNEL);
849 if (!priv->sndbuf) {
850 kfree(priv);
851 return -ENOMEM;
852 }
853
854 /* set console flag */
855 priv->is_console = is_console;
735 856
736 /* Finally allocate hvc */ 857 /* finally allocate hvc */
737 priv->hvc = hvc_alloc(HVC_IUCV_MAGIC + id, 858 priv->hvc = hvc_alloc(HVC_IUCV_MAGIC + id, /* PAGE_SIZE */
738 HVC_IUCV_MAGIC + id, &hvc_iucv_ops, PAGE_SIZE); 859 HVC_IUCV_MAGIC + id, &hvc_iucv_ops, 256);
739 if (IS_ERR(priv->hvc)) { 860 if (IS_ERR(priv->hvc)) {
740 rc = PTR_ERR(priv->hvc); 861 rc = PTR_ERR(priv->hvc);
862 free_page((unsigned long) priv->sndbuf);
741 kfree(priv); 863 kfree(priv);
742 return rc; 864 return rc;
743 } 865 }
744 866
867 /* notify HVC thread instead of using polling */
868 priv->hvc->irq_requested = 1;
869
745 /* setup iucv related information */ 870 /* setup iucv related information */
746 snprintf(name, 9, "ihvc%-4d", id); 871 snprintf(name, 9, "lnxhvc%-2d", id);
747 memcpy(priv->srv_name, name, 8); 872 memcpy(priv->srv_name, name, 8);
748 ASCEBC(priv->srv_name, 8); 873 ASCEBC(priv->srv_name, 8);
749 874
@@ -752,15 +877,16 @@ static int __init hvc_iucv_alloc(int id)
752} 877}
753 878
754/** 879/**
755 * hvc_iucv_init() - Initialization of HVC backend for z/VM IUCV 880 * hvc_iucv_init() - z/VM IUCV HVC device driver initialization
756 */ 881 */
757static int __init hvc_iucv_init(void) 882static int __init hvc_iucv_init(void)
758{ 883{
759 int rc, i; 884 int rc;
885 unsigned int i;
760 886
761 if (!MACHINE_IS_VM) { 887 if (!MACHINE_IS_VM) {
762 pr_warning("The z/VM IUCV Hypervisor console cannot be " 888 pr_info("The z/VM IUCV HVC device driver cannot "
763 "used without z/VM.\n"); 889 "be used without z/VM\n");
764 return -ENODEV; 890 return -ENODEV;
765 } 891 }
766 892
@@ -774,26 +900,33 @@ static int __init hvc_iucv_init(void)
774 sizeof(struct iucv_tty_buffer), 900 sizeof(struct iucv_tty_buffer),
775 0, 0, NULL); 901 0, 0, NULL);
776 if (!hvc_iucv_buffer_cache) { 902 if (!hvc_iucv_buffer_cache) {
777 pr_err("Not enough memory for driver initialization " 903 pr_err("Allocating memory failed with reason code=%d\n", 1);
778 "(rs=%d).\n", 1);
779 return -ENOMEM; 904 return -ENOMEM;
780 } 905 }
781 906
782 hvc_iucv_mempool = mempool_create_slab_pool(MEMPOOL_MIN_NR, 907 hvc_iucv_mempool = mempool_create_slab_pool(MEMPOOL_MIN_NR,
783 hvc_iucv_buffer_cache); 908 hvc_iucv_buffer_cache);
784 if (!hvc_iucv_mempool) { 909 if (!hvc_iucv_mempool) {
785 pr_err("Not enough memory for driver initialization " 910 pr_err("Allocating memory failed with reason code=%d\n", 2);
786 "(rs=%d).\n", 2);
787 kmem_cache_destroy(hvc_iucv_buffer_cache); 911 kmem_cache_destroy(hvc_iucv_buffer_cache);
788 return -ENOMEM; 912 return -ENOMEM;
789 } 913 }
790 914
915 /* register the first terminal device as console
916 * (must be done before allocating hvc terminal devices) */
917 rc = hvc_instantiate(HVC_IUCV_MAGIC, IUCV_HVC_CON_IDX, &hvc_iucv_ops);
918 if (rc) {
919 pr_err("Registering HVC terminal device as "
920 "Linux console failed\n");
921 goto out_error_memory;
922 }
923
791 /* allocate hvc_iucv_private structs */ 924 /* allocate hvc_iucv_private structs */
792 for (i = 0; i < hvc_iucv_devices; i++) { 925 for (i = 0; i < hvc_iucv_devices; i++) {
793 rc = hvc_iucv_alloc(i); 926 rc = hvc_iucv_alloc(i, (i == IUCV_HVC_CON_IDX) ? 1 : 0);
794 if (rc) { 927 if (rc) {
795 pr_err("Could not create new z/VM IUCV HVC backend " 928 pr_err("Creating a new HVC terminal device "
796 "rc=%d.\n", rc); 929 "failed with error code=%d\n", rc);
797 goto out_error_hvc; 930 goto out_error_hvc;
798 } 931 }
799 } 932 }
@@ -801,7 +934,8 @@ static int __init hvc_iucv_init(void)
801 /* register IUCV callback handler */ 934 /* register IUCV callback handler */
802 rc = iucv_register(&hvc_iucv_handler, 0); 935 rc = iucv_register(&hvc_iucv_handler, 0);
803 if (rc) { 936 if (rc) {
804 pr_err("Could not register iucv handler (rc=%d).\n", rc); 937 pr_err("Registering IUCV handlers failed with error code=%d\n",
938 rc);
805 goto out_error_iucv; 939 goto out_error_iucv;
806 } 940 }
807 941
@@ -816,22 +950,13 @@ out_error_hvc:
816 hvc_remove(hvc_iucv_table[i]->hvc); 950 hvc_remove(hvc_iucv_table[i]->hvc);
817 kfree(hvc_iucv_table[i]); 951 kfree(hvc_iucv_table[i]);
818 } 952 }
953out_error_memory:
819 mempool_destroy(hvc_iucv_mempool); 954 mempool_destroy(hvc_iucv_mempool);
820 kmem_cache_destroy(hvc_iucv_buffer_cache); 955 kmem_cache_destroy(hvc_iucv_buffer_cache);
821 return rc; 956 return rc;
822} 957}
823 958
824/** 959/**
825 * hvc_iucv_console_init() - Early console initialization
826 */
827static int __init hvc_iucv_console_init(void)
828{
829 if (!MACHINE_IS_VM || !hvc_iucv_devices)
830 return -ENODEV;
831 return hvc_instantiate(HVC_IUCV_MAGIC, 0, &hvc_iucv_ops);
832}
833
834/**
835 * hvc_iucv_config() - Parsing of hvc_iucv= kernel command line parameter 960 * hvc_iucv_config() - Parsing of hvc_iucv= kernel command line parameter
836 * @val: Parameter value (numeric) 961 * @val: Parameter value (numeric)
837 */ 962 */
@@ -841,10 +966,5 @@ static int __init hvc_iucv_config(char *val)
841} 966}
842 967
843 968
844module_init(hvc_iucv_init); 969device_initcall(hvc_iucv_init);
845console_initcall(hvc_iucv_console_init);
846__setup("hvc_iucv=", hvc_iucv_config); 970__setup("hvc_iucv=", hvc_iucv_config);
847
848MODULE_LICENSE("GPL");
849MODULE_DESCRIPTION("HVC back-end for z/VM IUCV.");
850MODULE_AUTHOR("Hendrik Brueckner <brueckner@linux.vnet.ibm.com>");
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index e7fb7d2fcbfc..a4a1ae214630 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -63,6 +63,12 @@ config LEDS_WRAP
63 help 63 help
64 This option enables support for the PCEngines WRAP programmable LEDs. 64 This option enables support for the PCEngines WRAP programmable LEDs.
65 65
66config LEDS_ALIX2
67 tristate "LED Support for ALIX.2 and ALIX.3 series"
68 depends on LEDS_CLASS && X86 && EXPERIMENTAL
69 help
70 This option enables support for the PCEngines ALIX.2 and ALIX.3 LEDs.
71
66config LEDS_H1940 72config LEDS_H1940
67 tristate "LED Support for iPAQ H1940 device" 73 tristate "LED Support for iPAQ H1940 device"
68 depends on LEDS_CLASS && ARCH_H1940 74 depends on LEDS_CLASS && ARCH_H1940
@@ -77,7 +83,7 @@ config LEDS_COBALT_QUBE
77 83
78config LEDS_COBALT_RAQ 84config LEDS_COBALT_RAQ
79 bool "LED Support for the Cobalt Raq series" 85 bool "LED Support for the Cobalt Raq series"
80 depends on LEDS_CLASS && MIPS_COBALT 86 depends on LEDS_CLASS=y && MIPS_COBALT
81 select LEDS_TRIGGERS 87 select LEDS_TRIGGERS
82 help 88 help
83 This option enables support for the Cobalt Raq series LEDs. 89 This option enables support for the Cobalt Raq series LEDs.
@@ -158,6 +164,13 @@ config LEDS_PCA955X
158 LED driver chips accessed via the I2C bus. Supported 164 LED driver chips accessed via the I2C bus. Supported
159 devices include PCA9550, PCA9551, PCA9552, and PCA9553. 165 devices include PCA9550, PCA9551, PCA9552, and PCA9553.
160 166
167config LEDS_WM8350
168 tristate "LED Support for WM8350 AudioPlus PMIC"
169 depends on LEDS_CLASS && MFD_WM8350
170 help
171 This option enables support for LEDs driven by the Wolfson
172 Microelectronics WM8350 AudioPlus PMIC.
173
161config LEDS_DA903X 174config LEDS_DA903X
162 tristate "LED Support for DA9030/DA9034 PMIC" 175 tristate "LED Support for DA9030/DA9034 PMIC"
163 depends on LEDS_CLASS && PMIC_DA903X 176 depends on LEDS_CLASS && PMIC_DA903X
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index e1967a29850e..bc247cb02e82 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_LEDS_S3C24XX) += leds-s3c24xx.o
11obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o 11obj-$(CONFIG_LEDS_AMS_DELTA) += leds-ams-delta.o
12obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o 12obj-$(CONFIG_LEDS_NET48XX) += leds-net48xx.o
13obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o 13obj-$(CONFIG_LEDS_WRAP) += leds-wrap.o
14obj-$(CONFIG_LEDS_ALIX2) += leds-alix2.o
14obj-$(CONFIG_LEDS_H1940) += leds-h1940.o 15obj-$(CONFIG_LEDS_H1940) += leds-h1940.o
15obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o 16obj-$(CONFIG_LEDS_COBALT_QUBE) += leds-cobalt-qube.o
16obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o 17obj-$(CONFIG_LEDS_COBALT_RAQ) += leds-cobalt-raq.o
@@ -23,6 +24,7 @@ obj-$(CONFIG_LEDS_FSG) += leds-fsg.o
23obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o 24obj-$(CONFIG_LEDS_PCA955X) += leds-pca955x.o
24obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o 25obj-$(CONFIG_LEDS_DA903X) += leds-da903x.o
25obj-$(CONFIG_LEDS_HP_DISK) += leds-hp-disk.o 26obj-$(CONFIG_LEDS_HP_DISK) += leds-hp-disk.o
27obj-$(CONFIG_LEDS_WM8350) += leds-wm8350.o
26 28
27# LED Triggers 29# LED Triggers
28obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o 30obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
diff --git a/drivers/leds/led-class.c b/drivers/leds/led-class.c
index 6c4a326176d7..52f82e3ea13a 100644
--- a/drivers/leds/led-class.c
+++ b/drivers/leds/led-class.c
@@ -91,9 +91,29 @@ void led_classdev_resume(struct led_classdev *led_cdev)
91} 91}
92EXPORT_SYMBOL_GPL(led_classdev_resume); 92EXPORT_SYMBOL_GPL(led_classdev_resume);
93 93
94static int led_suspend(struct device *dev, pm_message_t state)
95{
96 struct led_classdev *led_cdev = dev_get_drvdata(dev);
97
98 if (led_cdev->flags & LED_CORE_SUSPENDRESUME)
99 led_classdev_suspend(led_cdev);
100
101 return 0;
102}
103
104static int led_resume(struct device *dev)
105{
106 struct led_classdev *led_cdev = dev_get_drvdata(dev);
107
108 if (led_cdev->flags & LED_CORE_SUSPENDRESUME)
109 led_classdev_resume(led_cdev);
110
111 return 0;
112}
113
94/** 114/**
95 * led_classdev_register - register a new object of led_classdev class. 115 * led_classdev_register - register a new object of led_classdev class.
96 * @dev: The device to register. 116 * @parent: The device to register.
97 * @led_cdev: the led_classdev structure for this device. 117 * @led_cdev: the led_classdev structure for this device.
98 */ 118 */
99int led_classdev_register(struct device *parent, struct led_classdev *led_cdev) 119int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
@@ -174,6 +194,8 @@ static int __init leds_init(void)
174 leds_class = class_create(THIS_MODULE, "leds"); 194 leds_class = class_create(THIS_MODULE, "leds");
175 if (IS_ERR(leds_class)) 195 if (IS_ERR(leds_class))
176 return PTR_ERR(leds_class); 196 return PTR_ERR(leds_class);
197 leds_class->suspend = led_suspend;
198 leds_class->resume = led_resume;
177 return 0; 199 return 0;
178} 200}
179 201
diff --git a/drivers/leds/leds-alix2.c b/drivers/leds/leds-alix2.c
new file mode 100644
index 000000000000..ddbd7730dfc8
--- /dev/null
+++ b/drivers/leds/leds-alix2.c
@@ -0,0 +1,181 @@
1/*
2 * LEDs driver for PCEngines ALIX.2 and ALIX.3
3 *
4 * Copyright (C) 2008 Constantin Baranov <const@mimas.ru>
5 */
6
7#include <linux/err.h>
8#include <linux/io.h>
9#include <linux/kernel.h>
10#include <linux/leds.h>
11#include <linux/module.h>
12#include <linux/platform_device.h>
13#include <linux/string.h>
14
15static int force = 0;
16module_param(force, bool, 0444);
17MODULE_PARM_DESC(force, "Assume system has ALIX.2 style LEDs");
18
19struct alix_led {
20 struct led_classdev cdev;
21 unsigned short port;
22 unsigned int on_value;
23 unsigned int off_value;
24};
25
26static void alix_led_set(struct led_classdev *led_cdev,
27 enum led_brightness brightness)
28{
29 struct alix_led *led_dev =
30 container_of(led_cdev, struct alix_led, cdev);
31
32 if (brightness)
33 outl(led_dev->on_value, led_dev->port);
34 else
35 outl(led_dev->off_value, led_dev->port);
36}
37
38static struct alix_led alix_leds[] = {
39 {
40 .cdev = {
41 .name = "alix:1",
42 .brightness_set = alix_led_set,
43 },
44 .port = 0x6100,
45 .on_value = 1 << 22,
46 .off_value = 1 << 6,
47 },
48 {
49 .cdev = {
50 .name = "alix:2",
51 .brightness_set = alix_led_set,
52 },
53 .port = 0x6180,
54 .on_value = 1 << 25,
55 .off_value = 1 << 9,
56 },
57 {
58 .cdev = {
59 .name = "alix:3",
60 .brightness_set = alix_led_set,
61 },
62 .port = 0x6180,
63 .on_value = 1 << 27,
64 .off_value = 1 << 11,
65 },
66};
67
68static int __init alix_led_probe(struct platform_device *pdev)
69{
70 int i;
71 int ret;
72
73 for (i = 0; i < ARRAY_SIZE(alix_leds); i++) {
74 alix_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
75 ret = led_classdev_register(&pdev->dev, &alix_leds[i].cdev);
76 if (ret < 0)
77 goto fail;
78 }
79 return 0;
80
81fail:
82 while (--i >= 0)
83 led_classdev_unregister(&alix_leds[i].cdev);
84 return ret;
85}
86
87static int alix_led_remove(struct platform_device *pdev)
88{
89 int i;
90
91 for (i = 0; i < ARRAY_SIZE(alix_leds); i++)
92 led_classdev_unregister(&alix_leds[i].cdev);
93 return 0;
94}
95
96static struct platform_driver alix_led_driver = {
97 .remove = alix_led_remove,
98 .driver = {
99 .name = KBUILD_MODNAME,
100 .owner = THIS_MODULE,
101 },
102};
103
104static int __init alix_present(void)
105{
106 const unsigned long bios_phys = 0x000f0000;
107 const size_t bios_len = 0x00010000;
108 const char alix_sig[] = "PC Engines ALIX.";
109 const size_t alix_sig_len = sizeof(alix_sig) - 1;
110
111 const char *bios_virt;
112 const char *scan_end;
113 const char *p;
114 int ret = 0;
115
116 if (force) {
117 printk(KERN_NOTICE "%s: forced to skip BIOS test, "
118 "assume system has ALIX.2 style LEDs\n",
119 KBUILD_MODNAME);
120 ret = 1;
121 goto out;
122 }
123
124 bios_virt = phys_to_virt(bios_phys);
125 scan_end = bios_virt + bios_len - (alix_sig_len + 2);
126 for (p = bios_virt; p < scan_end; p++) {
127 const char *tail;
128
129 if (memcmp(p, alix_sig, alix_sig_len) != 0) {
130 continue;
131 }
132
133 tail = p + alix_sig_len;
134 if ((tail[0] == '2' || tail[0] == '3') && tail[1] == '\0') {
135 printk(KERN_INFO
136 "%s: system is recognized as \"%s\"\n",
137 KBUILD_MODNAME, p);
138 ret = 1;
139 break;
140 }
141 }
142
143out:
144 return ret;
145}
146
147static struct platform_device *pdev;
148
149static int __init alix_led_init(void)
150{
151 int ret;
152
153 if (!alix_present()) {
154 ret = -ENODEV;
155 goto out;
156 }
157
158 pdev = platform_device_register_simple(KBUILD_MODNAME, -1, NULL, 0);
159 if (!IS_ERR(pdev)) {
160 ret = platform_driver_probe(&alix_led_driver, alix_led_probe);
161 if (ret)
162 platform_device_unregister(pdev);
163 } else
164 ret = PTR_ERR(pdev);
165
166out:
167 return ret;
168}
169
170static void __exit alix_led_exit(void)
171{
172 platform_device_unregister(pdev);
173 platform_driver_unregister(&alix_led_driver);
174}
175
176module_init(alix_led_init);
177module_exit(alix_led_exit);
178
179MODULE_AUTHOR("Constantin Baranov <const@mimas.ru>");
180MODULE_DESCRIPTION("PCEngines ALIX.2 and ALIX.3 LED driver");
181MODULE_LICENSE("GPL");
diff --git a/drivers/leds/leds-ams-delta.c b/drivers/leds/leds-ams-delta.c
index 1bd590bb3a6e..446050759b4d 100644
--- a/drivers/leds/leds-ams-delta.c
+++ b/drivers/leds/leds-ams-delta.c
@@ -79,37 +79,12 @@ static struct ams_delta_led ams_delta_leds[] = {
79 }, 79 },
80}; 80};
81 81
82#ifdef CONFIG_PM
83static int ams_delta_led_suspend(struct platform_device *dev,
84 pm_message_t state)
85{
86 int i;
87
88 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
89 led_classdev_suspend(&ams_delta_leds[i].cdev);
90
91 return 0;
92}
93
94static int ams_delta_led_resume(struct platform_device *dev)
95{
96 int i;
97
98 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
99 led_classdev_resume(&ams_delta_leds[i].cdev);
100
101 return 0;
102}
103#else
104#define ams_delta_led_suspend NULL
105#define ams_delta_led_resume NULL
106#endif
107
108static int ams_delta_led_probe(struct platform_device *pdev) 82static int ams_delta_led_probe(struct platform_device *pdev)
109{ 83{
110 int i, ret; 84 int i, ret;
111 85
112 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) { 86 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++) {
87 ams_delta_leds[i].cdev.flags |= LED_CORE_SUSPENDRESUME;
113 ret = led_classdev_register(&pdev->dev, 88 ret = led_classdev_register(&pdev->dev,
114 &ams_delta_leds[i].cdev); 89 &ams_delta_leds[i].cdev);
115 if (ret < 0) 90 if (ret < 0)
@@ -127,7 +102,7 @@ static int ams_delta_led_remove(struct platform_device *pdev)
127{ 102{
128 int i; 103 int i;
129 104
130 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i--) 105 for (i = 0; i < ARRAY_SIZE(ams_delta_leds); i++)
131 led_classdev_unregister(&ams_delta_leds[i].cdev); 106 led_classdev_unregister(&ams_delta_leds[i].cdev);
132 107
133 return 0; 108 return 0;
@@ -136,8 +111,6 @@ static int ams_delta_led_remove(struct platform_device *pdev)
136static struct platform_driver ams_delta_led_driver = { 111static struct platform_driver ams_delta_led_driver = {
137 .probe = ams_delta_led_probe, 112 .probe = ams_delta_led_probe,
138 .remove = ams_delta_led_remove, 113 .remove = ams_delta_led_remove,
139 .suspend = ams_delta_led_suspend,
140 .resume = ams_delta_led_resume,
141 .driver = { 114 .driver = {
142 .name = "ams-delta-led", 115 .name = "ams-delta-led",
143 .owner = THIS_MODULE, 116 .owner = THIS_MODULE,
@@ -151,7 +124,7 @@ static int __init ams_delta_led_init(void)
151 124
152static void __exit ams_delta_led_exit(void) 125static void __exit ams_delta_led_exit(void)
153{ 126{
154 return platform_driver_unregister(&ams_delta_led_driver); 127 platform_driver_unregister(&ams_delta_led_driver);
155} 128}
156 129
157module_init(ams_delta_led_init); 130module_init(ams_delta_led_init);
diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
index eb3415e88f43..1813c84ea5fc 100644
--- a/drivers/leds/leds-clevo-mail.c
+++ b/drivers/leds/leds-clevo-mail.c
@@ -142,6 +142,7 @@ static struct led_classdev clevo_mail_led = {
142 .name = "clevo::mail", 142 .name = "clevo::mail",
143 .brightness_set = clevo_mail_led_set, 143 .brightness_set = clevo_mail_led_set,
144 .blink_set = clevo_mail_led_blink, 144 .blink_set = clevo_mail_led_blink,
145 .flags = LED_CORE_SUSPENDRESUME,
145}; 146};
146 147
147static int __init clevo_mail_led_probe(struct platform_device *pdev) 148static int __init clevo_mail_led_probe(struct platform_device *pdev)
@@ -155,29 +156,9 @@ static int clevo_mail_led_remove(struct platform_device *pdev)
155 return 0; 156 return 0;
156} 157}
157 158
158#ifdef CONFIG_PM
159static int clevo_mail_led_suspend(struct platform_device *dev,
160 pm_message_t state)
161{
162 led_classdev_suspend(&clevo_mail_led);
163 return 0;
164}
165
166static int clevo_mail_led_resume(struct platform_device *dev)
167{
168 led_classdev_resume(&clevo_mail_led);
169 return 0;
170}
171#else
172#define clevo_mail_led_suspend NULL
173#define clevo_mail_led_resume NULL
174#endif
175
176static struct platform_driver clevo_mail_led_driver = { 159static struct platform_driver clevo_mail_led_driver = {
177 .probe = clevo_mail_led_probe, 160 .probe = clevo_mail_led_probe,
178 .remove = clevo_mail_led_remove, 161 .remove = clevo_mail_led_remove,
179 .suspend = clevo_mail_led_suspend,
180 .resume = clevo_mail_led_resume,
181 .driver = { 162 .driver = {
182 .name = KBUILD_MODNAME, 163 .name = KBUILD_MODNAME,
183 .owner = THIS_MODULE, 164 .owner = THIS_MODULE,
diff --git a/drivers/leds/leds-fsg.c b/drivers/leds/leds-fsg.c
index 34935155c1c0..5f7c9c5c09b1 100644
--- a/drivers/leds/leds-fsg.c
+++ b/drivers/leds/leds-fsg.c
@@ -99,64 +99,43 @@ static void fsg_led_ring_set(struct led_classdev *led_cdev,
99} 99}
100 100
101 101
102
103static struct led_classdev fsg_wlan_led = { 102static struct led_classdev fsg_wlan_led = {
104 .name = "fsg:blue:wlan", 103 .name = "fsg:blue:wlan",
105 .brightness_set = fsg_led_wlan_set, 104 .brightness_set = fsg_led_wlan_set,
105 .flags = LED_CORE_SUSPENDRESUME,
106}; 106};
107 107
108static struct led_classdev fsg_wan_led = { 108static struct led_classdev fsg_wan_led = {
109 .name = "fsg:blue:wan", 109 .name = "fsg:blue:wan",
110 .brightness_set = fsg_led_wan_set, 110 .brightness_set = fsg_led_wan_set,
111 .flags = LED_CORE_SUSPENDRESUME,
111}; 112};
112 113
113static struct led_classdev fsg_sata_led = { 114static struct led_classdev fsg_sata_led = {
114 .name = "fsg:blue:sata", 115 .name = "fsg:blue:sata",
115 .brightness_set = fsg_led_sata_set, 116 .brightness_set = fsg_led_sata_set,
117 .flags = LED_CORE_SUSPENDRESUME,
116}; 118};
117 119
118static struct led_classdev fsg_usb_led = { 120static struct led_classdev fsg_usb_led = {
119 .name = "fsg:blue:usb", 121 .name = "fsg:blue:usb",
120 .brightness_set = fsg_led_usb_set, 122 .brightness_set = fsg_led_usb_set,
123 .flags = LED_CORE_SUSPENDRESUME,
121}; 124};
122 125
123static struct led_classdev fsg_sync_led = { 126static struct led_classdev fsg_sync_led = {
124 .name = "fsg:blue:sync", 127 .name = "fsg:blue:sync",
125 .brightness_set = fsg_led_sync_set, 128 .brightness_set = fsg_led_sync_set,
129 .flags = LED_CORE_SUSPENDRESUME,
126}; 130};
127 131
128static struct led_classdev fsg_ring_led = { 132static struct led_classdev fsg_ring_led = {
129 .name = "fsg:blue:ring", 133 .name = "fsg:blue:ring",
130 .brightness_set = fsg_led_ring_set, 134 .brightness_set = fsg_led_ring_set,
135 .flags = LED_CORE_SUSPENDRESUME,
131}; 136};
132 137
133 138
134
135#ifdef CONFIG_PM
136static int fsg_led_suspend(struct platform_device *dev, pm_message_t state)
137{
138 led_classdev_suspend(&fsg_wlan_led);
139 led_classdev_suspend(&fsg_wan_led);
140 led_classdev_suspend(&fsg_sata_led);
141 led_classdev_suspend(&fsg_usb_led);
142 led_classdev_suspend(&fsg_sync_led);
143 led_classdev_suspend(&fsg_ring_led);
144 return 0;
145}
146
147static int fsg_led_resume(struct platform_device *dev)
148{
149 led_classdev_resume(&fsg_wlan_led);
150 led_classdev_resume(&fsg_wan_led);
151 led_classdev_resume(&fsg_sata_led);
152 led_classdev_resume(&fsg_usb_led);
153 led_classdev_resume(&fsg_sync_led);
154 led_classdev_resume(&fsg_ring_led);
155 return 0;
156}
157#endif
158
159
160static int fsg_led_probe(struct platform_device *pdev) 139static int fsg_led_probe(struct platform_device *pdev)
161{ 140{
162 int ret; 141 int ret;
@@ -232,10 +211,6 @@ static int fsg_led_remove(struct platform_device *pdev)
232static struct platform_driver fsg_led_driver = { 211static struct platform_driver fsg_led_driver = {
233 .probe = fsg_led_probe, 212 .probe = fsg_led_probe,
234 .remove = fsg_led_remove, 213 .remove = fsg_led_remove,
235#ifdef CONFIG_PM
236 .suspend = fsg_led_suspend,
237 .resume = fsg_led_resume,
238#endif
239 .driver = { 214 .driver = {
240 .name = "fsg-led", 215 .name = "fsg-led",
241 }, 216 },
diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index b13bd2950e95..2e3df08b649b 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -105,6 +105,7 @@ static int gpio_led_probe(struct platform_device *pdev)
105 } 105 }
106 led_dat->cdev.brightness_set = gpio_led_set; 106 led_dat->cdev.brightness_set = gpio_led_set;
107 led_dat->cdev.brightness = LED_OFF; 107 led_dat->cdev.brightness = LED_OFF;
108 led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
108 109
109 gpio_direction_output(led_dat->gpio, led_dat->active_low); 110 gpio_direction_output(led_dat->gpio, led_dat->active_low);
110 111
@@ -154,44 +155,9 @@ static int __devexit gpio_led_remove(struct platform_device *pdev)
154 return 0; 155 return 0;
155} 156}
156 157
157#ifdef CONFIG_PM
158static int gpio_led_suspend(struct platform_device *pdev, pm_message_t state)
159{
160 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
161 struct gpio_led_data *leds_data;
162 int i;
163
164 leds_data = platform_get_drvdata(pdev);
165
166 for (i = 0; i < pdata->num_leds; i++)
167 led_classdev_suspend(&leds_data[i].cdev);
168
169 return 0;
170}
171
172static int gpio_led_resume(struct platform_device *pdev)
173{
174 struct gpio_led_platform_data *pdata = pdev->dev.platform_data;
175 struct gpio_led_data *leds_data;
176 int i;
177
178 leds_data = platform_get_drvdata(pdev);
179
180 for (i = 0; i < pdata->num_leds; i++)
181 led_classdev_resume(&leds_data[i].cdev);
182
183 return 0;
184}
185#else
186#define gpio_led_suspend NULL
187#define gpio_led_resume NULL
188#endif
189
190static struct platform_driver gpio_led_driver = { 158static struct platform_driver gpio_led_driver = {
191 .probe = gpio_led_probe, 159 .probe = gpio_led_probe,
192 .remove = __devexit_p(gpio_led_remove), 160 .remove = __devexit_p(gpio_led_remove),
193 .suspend = gpio_led_suspend,
194 .resume = gpio_led_resume,
195 .driver = { 161 .driver = {
196 .name = "leds-gpio", 162 .name = "leds-gpio",
197 .owner = THIS_MODULE, 163 .owner = THIS_MODULE,
diff --git a/drivers/leds/leds-hp-disk.c b/drivers/leds/leds-hp-disk.c
index 44fa757d8254..d786adc8c5e3 100644
--- a/drivers/leds/leds-hp-disk.c
+++ b/drivers/leds/leds-hp-disk.c
@@ -68,25 +68,9 @@ static struct led_classdev hpled_led = {
68 .name = "hp:red:hddprotection", 68 .name = "hp:red:hddprotection",
69 .default_trigger = "heartbeat", 69 .default_trigger = "heartbeat",
70 .brightness_set = hpled_set, 70 .brightness_set = hpled_set,
71 .flags = LED_CORE_SUSPENDRESUME,
71}; 72};
72 73
73#ifdef CONFIG_PM
74static int hpled_suspend(struct acpi_device *dev, pm_message_t state)
75{
76 led_classdev_suspend(&hpled_led);
77 return 0;
78}
79
80static int hpled_resume(struct acpi_device *dev)
81{
82 led_classdev_resume(&hpled_led);
83 return 0;
84}
85#else
86#define hpled_suspend NULL
87#define hpled_resume NULL
88#endif
89
90static int hpled_add(struct acpi_device *device) 74static int hpled_add(struct acpi_device *device)
91{ 75{
92 int ret; 76 int ret;
@@ -121,8 +105,6 @@ static struct acpi_driver leds_hp_driver = {
121 .ops = { 105 .ops = {
122 .add = hpled_add, 106 .add = hpled_add,
123 .remove = hpled_remove, 107 .remove = hpled_remove,
124 .suspend = hpled_suspend,
125 .resume = hpled_resume,
126 } 108 }
127}; 109};
128 110
diff --git a/drivers/leds/leds-hp6xx.c b/drivers/leds/leds-hp6xx.c
index e8fb1baf8a50..e4ce1fd46338 100644
--- a/drivers/leds/leds-hp6xx.c
+++ b/drivers/leds/leds-hp6xx.c
@@ -45,30 +45,16 @@ static struct led_classdev hp6xx_red_led = {
45 .name = "hp6xx:red", 45 .name = "hp6xx:red",
46 .default_trigger = "hp6xx-charge", 46 .default_trigger = "hp6xx-charge",
47 .brightness_set = hp6xxled_red_set, 47 .brightness_set = hp6xxled_red_set,
48 .flags = LED_CORE_SUSPENDRESUME,
48}; 49};
49 50
50static struct led_classdev hp6xx_green_led = { 51static struct led_classdev hp6xx_green_led = {
51 .name = "hp6xx:green", 52 .name = "hp6xx:green",
52 .default_trigger = "ide-disk", 53 .default_trigger = "ide-disk",
53 .brightness_set = hp6xxled_green_set, 54 .brightness_set = hp6xxled_green_set,
55 .flags = LED_CORE_SUSPENDRESUME,
54}; 56};
55 57
56#ifdef CONFIG_PM
57static int hp6xxled_suspend(struct platform_device *dev, pm_message_t state)
58{
59 led_classdev_suspend(&hp6xx_red_led);
60 led_classdev_suspend(&hp6xx_green_led);
61 return 0;
62}
63
64static int hp6xxled_resume(struct platform_device *dev)
65{
66 led_classdev_resume(&hp6xx_red_led);
67 led_classdev_resume(&hp6xx_green_led);
68 return 0;
69}
70#endif
71
72static int hp6xxled_probe(struct platform_device *pdev) 58static int hp6xxled_probe(struct platform_device *pdev)
73{ 59{
74 int ret; 60 int ret;
@@ -98,10 +84,6 @@ MODULE_ALIAS("platform:hp6xx-led");
98static struct platform_driver hp6xxled_driver = { 84static struct platform_driver hp6xxled_driver = {
99 .probe = hp6xxled_probe, 85 .probe = hp6xxled_probe,
100 .remove = hp6xxled_remove, 86 .remove = hp6xxled_remove,
101#ifdef CONFIG_PM
102 .suspend = hp6xxled_suspend,
103 .resume = hp6xxled_resume,
104#endif
105 .driver = { 87 .driver = {
106 .name = "hp6xx-led", 88 .name = "hp6xx-led",
107 .owner = THIS_MODULE, 89 .owner = THIS_MODULE,
diff --git a/drivers/leds/leds-net48xx.c b/drivers/leds/leds-net48xx.c
index 054360473c94..93987a12da49 100644
--- a/drivers/leds/leds-net48xx.c
+++ b/drivers/leds/leds-net48xx.c
@@ -33,26 +33,9 @@ static void net48xx_error_led_set(struct led_classdev *led_cdev,
33static struct led_classdev net48xx_error_led = { 33static struct led_classdev net48xx_error_led = {
34 .name = "net48xx::error", 34 .name = "net48xx::error",
35 .brightness_set = net48xx_error_led_set, 35 .brightness_set = net48xx_error_led_set,
36 .flags = LED_CORE_SUSPENDRESUME,
36}; 37};
37 38
38#ifdef CONFIG_PM
39static int net48xx_led_suspend(struct platform_device *dev,
40 pm_message_t state)
41{
42 led_classdev_suspend(&net48xx_error_led);
43 return 0;
44}
45
46static int net48xx_led_resume(struct platform_device *dev)
47{
48 led_classdev_resume(&net48xx_error_led);
49 return 0;
50}
51#else
52#define net48xx_led_suspend NULL
53#define net48xx_led_resume NULL
54#endif
55
56static int net48xx_led_probe(struct platform_device *pdev) 39static int net48xx_led_probe(struct platform_device *pdev)
57{ 40{
58 return led_classdev_register(&pdev->dev, &net48xx_error_led); 41 return led_classdev_register(&pdev->dev, &net48xx_error_led);
@@ -67,8 +50,6 @@ static int net48xx_led_remove(struct platform_device *pdev)
67static struct platform_driver net48xx_led_driver = { 50static struct platform_driver net48xx_led_driver = {
68 .probe = net48xx_led_probe, 51 .probe = net48xx_led_probe,
69 .remove = net48xx_led_remove, 52 .remove = net48xx_led_remove,
70 .suspend = net48xx_led_suspend,
71 .resume = net48xx_led_resume,
72 .driver = { 53 .driver = {
73 .name = DRVNAME, 54 .name = DRVNAME,
74 .owner = THIS_MODULE, 55 .owner = THIS_MODULE,
diff --git a/drivers/leds/leds-pca9532.c b/drivers/leds/leds-pca9532.c
index 4064d4f6b33b..76ec7498e2d5 100644
--- a/drivers/leds/leds-pca9532.c
+++ b/drivers/leds/leds-pca9532.c
@@ -16,6 +16,7 @@
16#include <linux/leds.h> 16#include <linux/leds.h>
17#include <linux/input.h> 17#include <linux/input.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19#include <linux/workqueue.h>
19#include <linux/leds-pca9532.h> 20#include <linux/leds-pca9532.h>
20 21
21static const unsigned short normal_i2c[] = { /*0x60,*/ I2C_CLIENT_END}; 22static const unsigned short normal_i2c[] = { /*0x60,*/ I2C_CLIENT_END};
@@ -34,6 +35,7 @@ struct pca9532_data {
34 struct pca9532_led leds[16]; 35 struct pca9532_led leds[16];
35 struct mutex update_lock; 36 struct mutex update_lock;
36 struct input_dev *idev; 37 struct input_dev *idev;
38 struct work_struct work;
37 u8 pwm[2]; 39 u8 pwm[2];
38 u8 psc[2]; 40 u8 psc[2];
39}; 41};
@@ -63,7 +65,7 @@ static struct i2c_driver pca9532_driver = {
63 * as a compromise we average one pwm to the values requested by all 65 * as a compromise we average one pwm to the values requested by all
64 * leds that are not ON/OFF. 66 * leds that are not ON/OFF.
65 * */ 67 * */
66static int pca9532_setpwm(struct i2c_client *client, int pwm, int blink, 68static int pca9532_calcpwm(struct i2c_client *client, int pwm, int blink,
67 enum led_brightness value) 69 enum led_brightness value)
68{ 70{
69 int a = 0, b = 0, i = 0; 71 int a = 0, b = 0, i = 0;
@@ -84,11 +86,17 @@ static int pca9532_setpwm(struct i2c_client *client, int pwm, int blink,
84 b = b/a; 86 b = b/a;
85 if (b > 0xFF) 87 if (b > 0xFF)
86 return -EINVAL; 88 return -EINVAL;
87 mutex_lock(&data->update_lock);
88 data->pwm[pwm] = b; 89 data->pwm[pwm] = b;
90 data->psc[pwm] = blink;
91 return 0;
92}
93
94static int pca9532_setpwm(struct i2c_client *client, int pwm)
95{
96 struct pca9532_data *data = i2c_get_clientdata(client);
97 mutex_lock(&data->update_lock);
89 i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(pwm), 98 i2c_smbus_write_byte_data(client, PCA9532_REG_PWM(pwm),
90 data->pwm[pwm]); 99 data->pwm[pwm]);
91 data->psc[pwm] = blink;
92 i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(pwm), 100 i2c_smbus_write_byte_data(client, PCA9532_REG_PSC(pwm),
93 data->psc[pwm]); 101 data->psc[pwm]);
94 mutex_unlock(&data->update_lock); 102 mutex_unlock(&data->update_lock);
@@ -124,11 +132,11 @@ static void pca9532_set_brightness(struct led_classdev *led_cdev,
124 led->state = PCA9532_ON; 132 led->state = PCA9532_ON;
125 else { 133 else {
126 led->state = PCA9532_PWM0; /* Thecus: hardcode one pwm */ 134 led->state = PCA9532_PWM0; /* Thecus: hardcode one pwm */
127 err = pca9532_setpwm(led->client, 0, 0, value); 135 err = pca9532_calcpwm(led->client, 0, 0, value);
128 if (err) 136 if (err)
129 return; /* XXX: led api doesn't allow error code? */ 137 return; /* XXX: led api doesn't allow error code? */
130 } 138 }
131 pca9532_setled(led); 139 schedule_work(&led->work);
132} 140}
133 141
134static int pca9532_set_blink(struct led_classdev *led_cdev, 142static int pca9532_set_blink(struct led_classdev *led_cdev,
@@ -137,6 +145,7 @@ static int pca9532_set_blink(struct led_classdev *led_cdev,
137 struct pca9532_led *led = ldev_to_led(led_cdev); 145 struct pca9532_led *led = ldev_to_led(led_cdev);
138 struct i2c_client *client = led->client; 146 struct i2c_client *client = led->client;
139 int psc; 147 int psc;
148 int err = 0;
140 149
141 if (*delay_on == 0 && *delay_off == 0) { 150 if (*delay_on == 0 && *delay_off == 0) {
142 /* led subsystem ask us for a blink rate */ 151 /* led subsystem ask us for a blink rate */
@@ -148,11 +157,15 @@ static int pca9532_set_blink(struct led_classdev *led_cdev,
148 157
149 /* Thecus specific: only use PSC/PWM 0 */ 158 /* Thecus specific: only use PSC/PWM 0 */
150 psc = (*delay_on * 152-1)/1000; 159 psc = (*delay_on * 152-1)/1000;
151 return pca9532_setpwm(client, 0, psc, led_cdev->brightness); 160 err = pca9532_calcpwm(client, 0, psc, led_cdev->brightness);
161 if (err)
162 return err;
163 schedule_work(&led->work);
164 return 0;
152} 165}
153 166
154int pca9532_event(struct input_dev *dev, unsigned int type, unsigned int code, 167static int pca9532_event(struct input_dev *dev, unsigned int type,
155 int value) 168 unsigned int code, int value)
156{ 169{
157 struct pca9532_data *data = input_get_drvdata(dev); 170 struct pca9532_data *data = input_get_drvdata(dev);
158 171
@@ -165,13 +178,28 @@ int pca9532_event(struct input_dev *dev, unsigned int type, unsigned int code,
165 else 178 else
166 data->pwm[1] = 0; 179 data->pwm[1] = 0;
167 180
168 dev_info(&dev->dev, "setting beep to %d \n", data->pwm[1]); 181 schedule_work(&data->work);
182
183 return 0;
184}
185
186static void pca9532_input_work(struct work_struct *work)
187{
188 struct pca9532_data *data;
189 data = container_of(work, struct pca9532_data, work);
169 mutex_lock(&data->update_lock); 190 mutex_lock(&data->update_lock);
170 i2c_smbus_write_byte_data(data->client, PCA9532_REG_PWM(1), 191 i2c_smbus_write_byte_data(data->client, PCA9532_REG_PWM(1),
171 data->pwm[1]); 192 data->pwm[1]);
172 mutex_unlock(&data->update_lock); 193 mutex_unlock(&data->update_lock);
194}
173 195
174 return 0; 196static void pca9532_led_work(struct work_struct *work)
197{
198 struct pca9532_led *led;
199 led = container_of(work, struct pca9532_led, work);
200 if (led->state == PCA9532_PWM0)
201 pca9532_setpwm(led->client, 0);
202 pca9532_setled(led);
175} 203}
176 204
177static int pca9532_configure(struct i2c_client *client, 205static int pca9532_configure(struct i2c_client *client,
@@ -204,8 +232,9 @@ static int pca9532_configure(struct i2c_client *client,
204 led->ldev.brightness = LED_OFF; 232 led->ldev.brightness = LED_OFF;
205 led->ldev.brightness_set = pca9532_set_brightness; 233 led->ldev.brightness_set = pca9532_set_brightness;
206 led->ldev.blink_set = pca9532_set_blink; 234 led->ldev.blink_set = pca9532_set_blink;
207 if (led_classdev_register(&client->dev, 235 INIT_WORK(&led->work, pca9532_led_work);
208 &led->ldev) < 0) { 236 err = led_classdev_register(&client->dev, &led->ldev);
237 if (err < 0) {
209 dev_err(&client->dev, 238 dev_err(&client->dev,
210 "couldn't register LED %s\n", 239 "couldn't register LED %s\n",
211 led->name); 240 led->name);
@@ -233,9 +262,11 @@ static int pca9532_configure(struct i2c_client *client,
233 BIT_MASK(SND_TONE); 262 BIT_MASK(SND_TONE);
234 data->idev->event = pca9532_event; 263 data->idev->event = pca9532_event;
235 input_set_drvdata(data->idev, data); 264 input_set_drvdata(data->idev, data);
265 INIT_WORK(&data->work, pca9532_input_work);
236 err = input_register_device(data->idev); 266 err = input_register_device(data->idev);
237 if (err) { 267 if (err) {
238 input_free_device(data->idev); 268 input_free_device(data->idev);
269 cancel_work_sync(&data->work);
239 data->idev = NULL; 270 data->idev = NULL;
240 goto exit; 271 goto exit;
241 } 272 }
@@ -252,18 +283,19 @@ exit:
252 break; 283 break;
253 case PCA9532_TYPE_LED: 284 case PCA9532_TYPE_LED:
254 led_classdev_unregister(&data->leds[i].ldev); 285 led_classdev_unregister(&data->leds[i].ldev);
286 cancel_work_sync(&data->leds[i].work);
255 break; 287 break;
256 case PCA9532_TYPE_N2100_BEEP: 288 case PCA9532_TYPE_N2100_BEEP:
257 if (data->idev != NULL) { 289 if (data->idev != NULL) {
258 input_unregister_device(data->idev); 290 input_unregister_device(data->idev);
259 input_free_device(data->idev); 291 input_free_device(data->idev);
292 cancel_work_sync(&data->work);
260 data->idev = NULL; 293 data->idev = NULL;
261 } 294 }
262 break; 295 break;
263 } 296 }
264 297
265 return err; 298 return err;
266
267} 299}
268 300
269static int pca9532_probe(struct i2c_client *client, 301static int pca9532_probe(struct i2c_client *client,
@@ -271,12 +303,16 @@ static int pca9532_probe(struct i2c_client *client,
271{ 303{
272 struct pca9532_data *data = i2c_get_clientdata(client); 304 struct pca9532_data *data = i2c_get_clientdata(client);
273 struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data; 305 struct pca9532_platform_data *pca9532_pdata = client->dev.platform_data;
306 int err;
307
308 if (!pca9532_pdata)
309 return -EIO;
274 310
275 if (!i2c_check_functionality(client->adapter, 311 if (!i2c_check_functionality(client->adapter,
276 I2C_FUNC_SMBUS_BYTE_DATA)) 312 I2C_FUNC_SMBUS_BYTE_DATA))
277 return -EIO; 313 return -EIO;
278 314
279 data = kzalloc(sizeof(struct pca9532_data), GFP_KERNEL); 315 data = kzalloc(sizeof(*data), GFP_KERNEL);
280 if (!data) 316 if (!data)
281 return -ENOMEM; 317 return -ENOMEM;
282 318
@@ -285,12 +321,13 @@ static int pca9532_probe(struct i2c_client *client,
285 data->client = client; 321 data->client = client;
286 mutex_init(&data->update_lock); 322 mutex_init(&data->update_lock);
287 323
288 if (pca9532_pdata == NULL) 324 err = pca9532_configure(client, data, pca9532_pdata);
289 return -EIO; 325 if (err) {
290 326 kfree(data);
291 pca9532_configure(client, data, pca9532_pdata); 327 i2c_set_clientdata(client, NULL);
292 return 0; 328 }
293 329
330 return err;
294} 331}
295 332
296static int pca9532_remove(struct i2c_client *client) 333static int pca9532_remove(struct i2c_client *client)
@@ -303,11 +340,13 @@ static int pca9532_remove(struct i2c_client *client)
303 break; 340 break;
304 case PCA9532_TYPE_LED: 341 case PCA9532_TYPE_LED:
305 led_classdev_unregister(&data->leds[i].ldev); 342 led_classdev_unregister(&data->leds[i].ldev);
343 cancel_work_sync(&data->leds[i].work);
306 break; 344 break;
307 case PCA9532_TYPE_N2100_BEEP: 345 case PCA9532_TYPE_N2100_BEEP:
308 if (data->idev != NULL) { 346 if (data->idev != NULL) {
309 input_unregister_device(data->idev); 347 input_unregister_device(data->idev);
310 input_free_device(data->idev); 348 input_free_device(data->idev);
349 cancel_work_sync(&data->work);
311 data->idev = NULL; 350 data->idev = NULL;
312 } 351 }
313 break; 352 break;
diff --git a/drivers/leds/leds-s3c24xx.c b/drivers/leds/leds-s3c24xx.c
index 25a07f2643ad..4d81131542ae 100644
--- a/drivers/leds/leds-s3c24xx.c
+++ b/drivers/leds/leds-s3c24xx.c
@@ -82,6 +82,7 @@ static int s3c24xx_led_probe(struct platform_device *dev)
82 led->cdev.brightness_set = s3c24xx_led_set; 82 led->cdev.brightness_set = s3c24xx_led_set;
83 led->cdev.default_trigger = pdata->def_trigger; 83 led->cdev.default_trigger = pdata->def_trigger;
84 led->cdev.name = pdata->name; 84 led->cdev.name = pdata->name;
85 led->cdev.flags |= LED_CORE_SUSPENDRESUME;
85 86
86 led->pdata = pdata; 87 led->pdata = pdata;
87 88
@@ -111,33 +112,9 @@ static int s3c24xx_led_probe(struct platform_device *dev)
111 return ret; 112 return ret;
112} 113}
113 114
114
115#ifdef CONFIG_PM
116static int s3c24xx_led_suspend(struct platform_device *dev, pm_message_t state)
117{
118 struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
119
120 led_classdev_suspend(&led->cdev);
121 return 0;
122}
123
124static int s3c24xx_led_resume(struct platform_device *dev)
125{
126 struct s3c24xx_gpio_led *led = pdev_to_gpio(dev);
127
128 led_classdev_resume(&led->cdev);
129 return 0;
130}
131#else
132#define s3c24xx_led_suspend NULL
133#define s3c24xx_led_resume NULL
134#endif
135
136static struct platform_driver s3c24xx_led_driver = { 115static struct platform_driver s3c24xx_led_driver = {
137 .probe = s3c24xx_led_probe, 116 .probe = s3c24xx_led_probe,
138 .remove = s3c24xx_led_remove, 117 .remove = s3c24xx_led_remove,
139 .suspend = s3c24xx_led_suspend,
140 .resume = s3c24xx_led_resume,
141 .driver = { 118 .driver = {
142 .name = "s3c24xx_led", 119 .name = "s3c24xx_led",
143 .owner = THIS_MODULE, 120 .owner = THIS_MODULE,
diff --git a/drivers/leds/leds-wm8350.c b/drivers/leds/leds-wm8350.c
new file mode 100644
index 000000000000..38c6bcb07e6c
--- /dev/null
+++ b/drivers/leds/leds-wm8350.c
@@ -0,0 +1,311 @@
1/*
2 * LED driver for WM8350 driven LEDS.
3 *
4 * Copyright(C) 2007, 2008 Wolfson Microelectronics PLC.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/leds.h>
16#include <linux/err.h>
17#include <linux/mfd/wm8350/pmic.h>
18#include <linux/regulator/consumer.h>
19
20/* Microamps */
21static const int isink_cur[] = {
22 4,
23 5,
24 6,
25 7,
26 8,
27 10,
28 11,
29 14,
30 16,
31 19,
32 23,
33 27,
34 32,
35 39,
36 46,
37 54,
38 65,
39 77,
40 92,
41 109,
42 130,
43 154,
44 183,
45 218,
46 259,
47 308,
48 367,
49 436,
50 518,
51 616,
52 733,
53 872,
54 1037,
55 1233,
56 1466,
57 1744,
58 2073,
59 2466,
60 2933,
61 3487,
62 4147,
63 4932,
64 5865,
65 6975,
66 8294,
67 9864,
68 11730,
69 13949,
70 16589,
71 19728,
72 23460,
73 27899,
74 33178,
75 39455,
76 46920,
77 55798,
78 66355,
79 78910,
80 93840,
81 111596,
82 132710,
83 157820,
84 187681,
85 223191
86};
87
88#define to_wm8350_led(led_cdev) \
89 container_of(led_cdev, struct wm8350_led, cdev)
90
91static void wm8350_led_enable(struct wm8350_led *led)
92{
93 int ret;
94
95 if (led->enabled)
96 return;
97
98 ret = regulator_enable(led->isink);
99 if (ret != 0) {
100 dev_err(led->cdev.dev, "Failed to enable ISINK: %d\n", ret);
101 return;
102 }
103
104 ret = regulator_enable(led->dcdc);
105 if (ret != 0) {
106 dev_err(led->cdev.dev, "Failed to enable DCDC: %d\n", ret);
107 regulator_disable(led->isink);
108 return;
109 }
110
111 led->enabled = 1;
112}
113
114static void wm8350_led_disable(struct wm8350_led *led)
115{
116 int ret;
117
118 if (!led->enabled)
119 return;
120
121 ret = regulator_disable(led->dcdc);
122 if (ret != 0) {
123 dev_err(led->cdev.dev, "Failed to disable DCDC: %d\n", ret);
124 return;
125 }
126
127 ret = regulator_disable(led->isink);
128 if (ret != 0) {
129 dev_err(led->cdev.dev, "Failed to disable ISINK: %d\n", ret);
130 regulator_enable(led->dcdc);
131 return;
132 }
133
134 led->enabled = 0;
135}
136
137static void led_work(struct work_struct *work)
138{
139 struct wm8350_led *led = container_of(work, struct wm8350_led, work);
140 int ret;
141 int uA;
142 unsigned long flags;
143
144 mutex_lock(&led->mutex);
145
146 spin_lock_irqsave(&led->value_lock, flags);
147
148 if (led->value == LED_OFF) {
149 spin_unlock_irqrestore(&led->value_lock, flags);
150 wm8350_led_disable(led);
151 goto out;
152 }
153
154 /* This scales linearly into the index of valid current
155 * settings which results in a linear scaling of perceived
156 * brightness due to the non-linear current settings provided
157 * by the hardware.
158 */
159 uA = (led->max_uA_index * led->value) / LED_FULL;
160 spin_unlock_irqrestore(&led->value_lock, flags);
161 BUG_ON(uA >= ARRAY_SIZE(isink_cur));
162
163 ret = regulator_set_current_limit(led->isink, isink_cur[uA],
164 isink_cur[uA]);
165 if (ret != 0)
166 dev_err(led->cdev.dev, "Failed to set %duA: %d\n",
167 isink_cur[uA], ret);
168
169 wm8350_led_enable(led);
170
171out:
172 mutex_unlock(&led->mutex);
173}
174
175static void wm8350_led_set(struct led_classdev *led_cdev,
176 enum led_brightness value)
177{
178 struct wm8350_led *led = to_wm8350_led(led_cdev);
179 unsigned long flags;
180
181 spin_lock_irqsave(&led->value_lock, flags);
182 led->value = value;
183 schedule_work(&led->work);
184 spin_unlock_irqrestore(&led->value_lock, flags);
185}
186
187static void wm8350_led_shutdown(struct platform_device *pdev)
188{
189 struct wm8350_led *led = platform_get_drvdata(pdev);
190
191 mutex_lock(&led->mutex);
192 led->value = LED_OFF;
193 wm8350_led_disable(led);
194 mutex_unlock(&led->mutex);
195}
196
197static int wm8350_led_probe(struct platform_device *pdev)
198{
199 struct regulator *isink, *dcdc;
200 struct wm8350_led *led;
201 struct wm8350_led_platform_data *pdata = pdev->dev.platform_data;
202 int ret, i;
203
204 if (pdata == NULL) {
205 dev_err(&pdev->dev, "no platform data\n");
206 return -ENODEV;
207 }
208
209 if (pdata->max_uA < isink_cur[0]) {
210 dev_err(&pdev->dev, "Invalid maximum current %duA\n",
211 pdata->max_uA);
212 return -EINVAL;
213 }
214
215 isink = regulator_get(&pdev->dev, "led_isink");
216 if (IS_ERR(isink)) {
217 printk(KERN_ERR "%s: cant get ISINK\n", __func__);
218 return PTR_ERR(isink);
219 }
220
221 dcdc = regulator_get(&pdev->dev, "led_vcc");
222 if (IS_ERR(dcdc)) {
223 printk(KERN_ERR "%s: cant get DCDC\n", __func__);
224 ret = PTR_ERR(dcdc);
225 goto err_isink;
226 }
227
228 led = kzalloc(sizeof(*led), GFP_KERNEL);
229 if (led == NULL) {
230 ret = -ENOMEM;
231 goto err_dcdc;
232 }
233
234 led->cdev.brightness_set = wm8350_led_set;
235 led->cdev.default_trigger = pdata->default_trigger;
236 led->cdev.name = pdata->name;
237 led->cdev.flags |= LED_CORE_SUSPENDRESUME;
238 led->enabled = regulator_is_enabled(isink);
239 led->isink = isink;
240 led->dcdc = dcdc;
241
242 for (i = 0; i < ARRAY_SIZE(isink_cur) - 1; i++)
243 if (isink_cur[i] >= pdata->max_uA)
244 break;
245 led->max_uA_index = i;
246 if (pdata->max_uA != isink_cur[i])
247 dev_warn(&pdev->dev,
248 "Maximum current %duA is not directly supported,"
249 " check platform data\n",
250 pdata->max_uA);
251
252 spin_lock_init(&led->value_lock);
253 mutex_init(&led->mutex);
254 INIT_WORK(&led->work, led_work);
255 led->value = LED_OFF;
256 platform_set_drvdata(pdev, led);
257
258 ret = led_classdev_register(&pdev->dev, &led->cdev);
259 if (ret < 0)
260 goto err_led;
261
262 return 0;
263
264 err_led:
265 kfree(led);
266 err_dcdc:
267 regulator_put(dcdc);
268 err_isink:
269 regulator_put(isink);
270 return ret;
271}
272
273static int wm8350_led_remove(struct platform_device *pdev)
274{
275 struct wm8350_led *led = platform_get_drvdata(pdev);
276
277 led_classdev_unregister(&led->cdev);
278 flush_scheduled_work();
279 wm8350_led_disable(led);
280 regulator_put(led->dcdc);
281 regulator_put(led->isink);
282 kfree(led);
283 return 0;
284}
285
286static struct platform_driver wm8350_led_driver = {
287 .driver = {
288 .name = "wm8350-led",
289 .owner = THIS_MODULE,
290 },
291 .probe = wm8350_led_probe,
292 .remove = wm8350_led_remove,
293 .shutdown = wm8350_led_shutdown,
294};
295
296static int __devinit wm8350_led_init(void)
297{
298 return platform_driver_register(&wm8350_led_driver);
299}
300module_init(wm8350_led_init);
301
302static void wm8350_led_exit(void)
303{
304 platform_driver_unregister(&wm8350_led_driver);
305}
306module_exit(wm8350_led_exit);
307
308MODULE_AUTHOR("Mark Brown");
309MODULE_DESCRIPTION("WM8350 LED driver");
310MODULE_LICENSE("GPL");
311MODULE_ALIAS("platform:wm8350-led");
diff --git a/drivers/leds/leds-wrap.c b/drivers/leds/leds-wrap.c
index 2f3aa87f2a1f..2982c86ac4cf 100644
--- a/drivers/leds/leds-wrap.c
+++ b/drivers/leds/leds-wrap.c
@@ -56,40 +56,21 @@ static struct led_classdev wrap_power_led = {
56 .name = "wrap::power", 56 .name = "wrap::power",
57 .brightness_set = wrap_power_led_set, 57 .brightness_set = wrap_power_led_set,
58 .default_trigger = "default-on", 58 .default_trigger = "default-on",
59 .flags = LED_CORE_SUSPENDRESUME,
59}; 60};
60 61
61static struct led_classdev wrap_error_led = { 62static struct led_classdev wrap_error_led = {
62 .name = "wrap::error", 63 .name = "wrap::error",
63 .brightness_set = wrap_error_led_set, 64 .brightness_set = wrap_error_led_set,
65 .flags = LED_CORE_SUSPENDRESUME,
64}; 66};
65 67
66static struct led_classdev wrap_extra_led = { 68static struct led_classdev wrap_extra_led = {
67 .name = "wrap::extra", 69 .name = "wrap::extra",
68 .brightness_set = wrap_extra_led_set, 70 .brightness_set = wrap_extra_led_set,
71 .flags = LED_CORE_SUSPENDRESUME,
69}; 72};
70 73
71#ifdef CONFIG_PM
72static int wrap_led_suspend(struct platform_device *dev,
73 pm_message_t state)
74{
75 led_classdev_suspend(&wrap_power_led);
76 led_classdev_suspend(&wrap_error_led);
77 led_classdev_suspend(&wrap_extra_led);
78 return 0;
79}
80
81static int wrap_led_resume(struct platform_device *dev)
82{
83 led_classdev_resume(&wrap_power_led);
84 led_classdev_resume(&wrap_error_led);
85 led_classdev_resume(&wrap_extra_led);
86 return 0;
87}
88#else
89#define wrap_led_suspend NULL
90#define wrap_led_resume NULL
91#endif
92
93static int wrap_led_probe(struct platform_device *pdev) 74static int wrap_led_probe(struct platform_device *pdev)
94{ 75{
95 int ret; 76 int ret;
@@ -127,8 +108,6 @@ static int wrap_led_remove(struct platform_device *pdev)
127static struct platform_driver wrap_led_driver = { 108static struct platform_driver wrap_led_driver = {
128 .probe = wrap_led_probe, 109 .probe = wrap_led_probe,
129 .remove = wrap_led_remove, 110 .remove = wrap_led_remove,
130 .suspend = wrap_led_suspend,
131 .resume = wrap_led_resume,
132 .driver = { 111 .driver = {
133 .name = DRVNAME, 112 .name = DRVNAME,
134 .owner = THIS_MODULE, 113 .owner = THIS_MODULE,
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index db681962d7bb..3d6531396dda 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -199,6 +199,7 @@ err_out:
199static void timer_trig_deactivate(struct led_classdev *led_cdev) 199static void timer_trig_deactivate(struct led_classdev *led_cdev)
200{ 200{
201 struct timer_trig_data *timer_data = led_cdev->trigger_data; 201 struct timer_trig_data *timer_data = led_cdev->trigger_data;
202 unsigned long on = 0, off = 0;
202 203
203 if (timer_data) { 204 if (timer_data) {
204 device_remove_file(led_cdev->dev, &dev_attr_delay_on); 205 device_remove_file(led_cdev->dev, &dev_attr_delay_on);
@@ -206,6 +207,10 @@ static void timer_trig_deactivate(struct led_classdev *led_cdev)
206 del_timer_sync(&timer_data->timer); 207 del_timer_sync(&timer_data->timer);
207 kfree(timer_data); 208 kfree(timer_data);
208 } 209 }
210
211 /* If there is hardware support for blinking, stop it */
212 if (led_cdev->blink_set)
213 led_cdev->blink_set(led_cdev, &on, &off);
209} 214}
210 215
211static struct led_trigger timer_led_trigger = { 216static struct led_trigger timer_led_trigger = {
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
index 3a273ccef3f2..f92595c8f165 100644
--- a/drivers/mfd/wm8350-core.c
+++ b/drivers/mfd/wm8350-core.c
@@ -1453,6 +1453,9 @@ void wm8350_device_exit(struct wm8350 *wm8350)
1453{ 1453{
1454 int i; 1454 int i;
1455 1455
1456 for (i = 0; i < ARRAY_SIZE(wm8350->pmic.led); i++)
1457 platform_device_unregister(wm8350->pmic.led[i].pdev);
1458
1456 for (i = 0; i < ARRAY_SIZE(wm8350->pmic.pdev); i++) 1459 for (i = 0; i < ARRAY_SIZE(wm8350->pmic.pdev); i++)
1457 platform_device_unregister(wm8350->pmic.pdev[i]); 1460 platform_device_unregister(wm8350->pmic.pdev[i]);
1458 1461
diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index 65e8294a9e29..9da5a4b81133 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -1,11 +1,12 @@
1/** 1/**
2 * @file buffer_sync.c 2 * @file buffer_sync.c
3 * 3 *
4 * @remark Copyright 2002 OProfile authors 4 * @remark Copyright 2002-2009 OProfile authors
5 * @remark Read the file COPYING 5 * @remark Read the file COPYING
6 * 6 *
7 * @author John Levon <levon@movementarian.org> 7 * @author John Levon <levon@movementarian.org>
8 * @author Barry Kasindorf 8 * @author Barry Kasindorf
9 * @author Robert Richter <robert.richter@amd.com>
9 * 10 *
10 * This is the core of the buffer management. Each 11 * This is the core of the buffer management. Each
11 * CPU buffer is processed and entered into the 12 * CPU buffer is processed and entered into the
@@ -315,88 +316,73 @@ static void add_trace_begin(void)
315 add_event_entry(TRACE_BEGIN_CODE); 316 add_event_entry(TRACE_BEGIN_CODE);
316} 317}
317 318
318#ifdef CONFIG_OPROFILE_IBS 319static void add_data(struct op_entry *entry, struct mm_struct *mm)
319
320#define IBS_FETCH_CODE_SIZE 2
321#define IBS_OP_CODE_SIZE 5
322
323/*
324 * Add IBS fetch and op entries to event buffer
325 */
326static void add_ibs_begin(int cpu, int code, struct mm_struct *mm)
327{ 320{
328 unsigned long rip; 321 unsigned long code, pc, val;
329 int i, count; 322 unsigned long cookie;
330 unsigned long ibs_cookie = 0;
331 off_t offset; 323 off_t offset;
332 struct op_sample *sample;
333
334 sample = cpu_buffer_read_entry(cpu);
335 if (!sample)
336 goto Error;
337 rip = sample->eip;
338 324
339#ifdef __LP64__ 325 if (!op_cpu_buffer_get_data(entry, &code))
340 rip += sample->event << 32; 326 return;
341#endif 327 if (!op_cpu_buffer_get_data(entry, &pc))
328 return;
329 if (!op_cpu_buffer_get_size(entry))
330 return;
342 331
343 if (mm) { 332 if (mm) {
344 ibs_cookie = lookup_dcookie(mm, rip, &offset); 333 cookie = lookup_dcookie(mm, pc, &offset);
345 334
346 if (ibs_cookie == NO_COOKIE) 335 if (cookie == NO_COOKIE)
347 offset = rip; 336 offset = pc;
348 if (ibs_cookie == INVALID_COOKIE) { 337 if (cookie == INVALID_COOKIE) {
349 atomic_inc(&oprofile_stats.sample_lost_no_mapping); 338 atomic_inc(&oprofile_stats.sample_lost_no_mapping);
350 offset = rip; 339 offset = pc;
351 } 340 }
352 if (ibs_cookie != last_cookie) { 341 if (cookie != last_cookie) {
353 add_cookie_switch(ibs_cookie); 342 add_cookie_switch(cookie);
354 last_cookie = ibs_cookie; 343 last_cookie = cookie;
355 } 344 }
356 } else 345 } else
357 offset = rip; 346 offset = pc;
358 347
359 add_event_entry(ESCAPE_CODE); 348 add_event_entry(ESCAPE_CODE);
360 add_event_entry(code); 349 add_event_entry(code);
361 add_event_entry(offset); /* Offset from Dcookie */ 350 add_event_entry(offset); /* Offset from Dcookie */
362 351
363 /* we send the Dcookie offset, but send the raw Linear Add also*/ 352 while (op_cpu_buffer_get_data(entry, &val))
364 add_event_entry(sample->eip); 353 add_event_entry(val);
365 add_event_entry(sample->event);
366
367 if (code == IBS_FETCH_CODE)
368 count = IBS_FETCH_CODE_SIZE; /*IBS FETCH is 2 int64s*/
369 else
370 count = IBS_OP_CODE_SIZE; /*IBS OP is 5 int64s*/
371
372 for (i = 0; i < count; i++) {
373 sample = cpu_buffer_read_entry(cpu);
374 if (!sample)
375 goto Error;
376 add_event_entry(sample->eip);
377 add_event_entry(sample->event);
378 }
379
380 return;
381
382Error:
383 return;
384} 354}
385 355
386#endif 356static inline void add_sample_entry(unsigned long offset, unsigned long event)
387
388static void add_sample_entry(unsigned long offset, unsigned long event)
389{ 357{
390 add_event_entry(offset); 358 add_event_entry(offset);
391 add_event_entry(event); 359 add_event_entry(event);
392} 360}
393 361
394 362
395static int add_us_sample(struct mm_struct *mm, struct op_sample *s) 363/*
364 * Add a sample to the global event buffer. If possible the
365 * sample is converted into a persistent dentry/offset pair
366 * for later lookup from userspace. Return 0 on failure.
367 */
368static int
369add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
396{ 370{
397 unsigned long cookie; 371 unsigned long cookie;
398 off_t offset; 372 off_t offset;
399 373
374 if (in_kernel) {
375 add_sample_entry(s->eip, s->event);
376 return 1;
377 }
378
379 /* add userspace sample */
380
381 if (!mm) {
382 atomic_inc(&oprofile_stats.sample_lost_no_mm);
383 return 0;
384 }
385
400 cookie = lookup_dcookie(mm, s->eip, &offset); 386 cookie = lookup_dcookie(mm, s->eip, &offset);
401 387
402 if (cookie == INVALID_COOKIE) { 388 if (cookie == INVALID_COOKIE) {
@@ -415,25 +401,6 @@ static int add_us_sample(struct mm_struct *mm, struct op_sample *s)
415} 401}
416 402
417 403
418/* Add a sample to the global event buffer. If possible the
419 * sample is converted into a persistent dentry/offset pair
420 * for later lookup from userspace.
421 */
422static int
423add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
424{
425 if (in_kernel) {
426 add_sample_entry(s->eip, s->event);
427 return 1;
428 } else if (mm) {
429 return add_us_sample(mm, s);
430 } else {
431 atomic_inc(&oprofile_stats.sample_lost_no_mm);
432 }
433 return 0;
434}
435
436
437static void release_mm(struct mm_struct *mm) 404static void release_mm(struct mm_struct *mm)
438{ 405{
439 if (!mm) 406 if (!mm)
@@ -526,66 +493,69 @@ void sync_buffer(int cpu)
526{ 493{
527 struct mm_struct *mm = NULL; 494 struct mm_struct *mm = NULL;
528 struct mm_struct *oldmm; 495 struct mm_struct *oldmm;
496 unsigned long val;
529 struct task_struct *new; 497 struct task_struct *new;
530 unsigned long cookie = 0; 498 unsigned long cookie = 0;
531 int in_kernel = 1; 499 int in_kernel = 1;
532 sync_buffer_state state = sb_buffer_start; 500 sync_buffer_state state = sb_buffer_start;
533 unsigned int i; 501 unsigned int i;
534 unsigned long available; 502 unsigned long available;
503 unsigned long flags;
504 struct op_entry entry;
505 struct op_sample *sample;
535 506
536 mutex_lock(&buffer_mutex); 507 mutex_lock(&buffer_mutex);
537 508
538 add_cpu_switch(cpu); 509 add_cpu_switch(cpu);
539 510
540 cpu_buffer_reset(cpu); 511 op_cpu_buffer_reset(cpu);
541 available = cpu_buffer_entries(cpu); 512 available = op_cpu_buffer_entries(cpu);
542 513
543 for (i = 0; i < available; ++i) { 514 for (i = 0; i < available; ++i) {
544 struct op_sample *s = cpu_buffer_read_entry(cpu); 515 sample = op_cpu_buffer_read_entry(&entry, cpu);
545 if (!s) 516 if (!sample)
546 break; 517 break;
547 518
548 if (is_code(s->eip)) { 519 if (is_code(sample->eip)) {
549 switch (s->event) { 520 flags = sample->event;
550 case 0: 521 if (flags & TRACE_BEGIN) {
551 case CPU_IS_KERNEL: 522 state = sb_bt_start;
523 add_trace_begin();
524 }
525 if (flags & KERNEL_CTX_SWITCH) {
552 /* kernel/userspace switch */ 526 /* kernel/userspace switch */
553 in_kernel = s->event; 527 in_kernel = flags & IS_KERNEL;
554 if (state == sb_buffer_start) 528 if (state == sb_buffer_start)
555 state = sb_sample_start; 529 state = sb_sample_start;
556 add_kernel_ctx_switch(s->event); 530 add_kernel_ctx_switch(flags & IS_KERNEL);
557 break; 531 }
558 case CPU_TRACE_BEGIN: 532 if (flags & USER_CTX_SWITCH
559 state = sb_bt_start; 533 && op_cpu_buffer_get_data(&entry, &val)) {
560 add_trace_begin();
561 break;
562#ifdef CONFIG_OPROFILE_IBS
563 case IBS_FETCH_BEGIN:
564 state = sb_bt_start;
565 add_ibs_begin(cpu, IBS_FETCH_CODE, mm);
566 break;
567 case IBS_OP_BEGIN:
568 state = sb_bt_start;
569 add_ibs_begin(cpu, IBS_OP_CODE, mm);
570 break;
571#endif
572 default:
573 /* userspace context switch */ 534 /* userspace context switch */
535 new = (struct task_struct *)val;
574 oldmm = mm; 536 oldmm = mm;
575 new = (struct task_struct *)s->event;
576 release_mm(oldmm); 537 release_mm(oldmm);
577 mm = take_tasks_mm(new); 538 mm = take_tasks_mm(new);
578 if (mm != oldmm) 539 if (mm != oldmm)
579 cookie = get_exec_dcookie(mm); 540 cookie = get_exec_dcookie(mm);
580 add_user_ctx_switch(new, cookie); 541 add_user_ctx_switch(new, cookie);
581 break;
582 }
583 } else if (state >= sb_bt_start &&
584 !add_sample(mm, s, in_kernel)) {
585 if (state == sb_bt_start) {
586 state = sb_bt_ignore;
587 atomic_inc(&oprofile_stats.bt_lost_no_mapping);
588 } 542 }
543 if (op_cpu_buffer_get_size(&entry))
544 add_data(&entry, mm);
545 continue;
546 }
547
548 if (state < sb_bt_start)
549 /* ignore sample */
550 continue;
551
552 if (add_sample(mm, sample, in_kernel))
553 continue;
554
555 /* ignore backtraces if failed to add a sample */
556 if (state == sb_bt_start) {
557 state = sb_bt_ignore;
558 atomic_inc(&oprofile_stats.bt_lost_no_mapping);
589 } 559 }
590 } 560 }
591 release_mm(mm); 561 release_mm(mm);
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index 61090969158f..2e03b6d796d3 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -1,11 +1,12 @@
1/** 1/**
2 * @file cpu_buffer.c 2 * @file cpu_buffer.c
3 * 3 *
4 * @remark Copyright 2002 OProfile authors 4 * @remark Copyright 2002-2009 OProfile authors
5 * @remark Read the file COPYING 5 * @remark Read the file COPYING
6 * 6 *
7 * @author John Levon <levon@movementarian.org> 7 * @author John Levon <levon@movementarian.org>
8 * @author Barry Kasindorf <barry.kasindorf@amd.com> 8 * @author Barry Kasindorf <barry.kasindorf@amd.com>
9 * @author Robert Richter <robert.richter@amd.com>
9 * 10 *
10 * Each CPU has a local buffer that stores PC value/event 11 * Each CPU has a local buffer that stores PC value/event
11 * pairs. We also log context switches when we notice them. 12 * pairs. We also log context switches when we notice them.
@@ -45,8 +46,8 @@
45 * can be changed to a single buffer solution when the ring buffer 46 * can be changed to a single buffer solution when the ring buffer
46 * access is implemented as non-locking atomic code. 47 * access is implemented as non-locking atomic code.
47 */ 48 */
48struct ring_buffer *op_ring_buffer_read; 49static struct ring_buffer *op_ring_buffer_read;
49struct ring_buffer *op_ring_buffer_write; 50static struct ring_buffer *op_ring_buffer_write;
50DEFINE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); 51DEFINE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
51 52
52static void wq_sync_buffer(struct work_struct *work); 53static void wq_sync_buffer(struct work_struct *work);
@@ -54,19 +55,9 @@ static void wq_sync_buffer(struct work_struct *work);
54#define DEFAULT_TIMER_EXPIRE (HZ / 10) 55#define DEFAULT_TIMER_EXPIRE (HZ / 10)
55static int work_enabled; 56static int work_enabled;
56 57
57void free_cpu_buffers(void)
58{
59 if (op_ring_buffer_read)
60 ring_buffer_free(op_ring_buffer_read);
61 op_ring_buffer_read = NULL;
62 if (op_ring_buffer_write)
63 ring_buffer_free(op_ring_buffer_write);
64 op_ring_buffer_write = NULL;
65}
66
67unsigned long oprofile_get_cpu_buffer_size(void) 58unsigned long oprofile_get_cpu_buffer_size(void)
68{ 59{
69 return fs_cpu_buffer_size; 60 return oprofile_cpu_buffer_size;
70} 61}
71 62
72void oprofile_cpu_buffer_inc_smpl_lost(void) 63void oprofile_cpu_buffer_inc_smpl_lost(void)
@@ -77,11 +68,21 @@ void oprofile_cpu_buffer_inc_smpl_lost(void)
77 cpu_buf->sample_lost_overflow++; 68 cpu_buf->sample_lost_overflow++;
78} 69}
79 70
71void free_cpu_buffers(void)
72{
73 if (op_ring_buffer_read)
74 ring_buffer_free(op_ring_buffer_read);
75 op_ring_buffer_read = NULL;
76 if (op_ring_buffer_write)
77 ring_buffer_free(op_ring_buffer_write);
78 op_ring_buffer_write = NULL;
79}
80
80int alloc_cpu_buffers(void) 81int alloc_cpu_buffers(void)
81{ 82{
82 int i; 83 int i;
83 84
84 unsigned long buffer_size = fs_cpu_buffer_size; 85 unsigned long buffer_size = oprofile_cpu_buffer_size;
85 86
86 op_ring_buffer_read = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS); 87 op_ring_buffer_read = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS);
87 if (!op_ring_buffer_read) 88 if (!op_ring_buffer_read)
@@ -97,8 +98,6 @@ int alloc_cpu_buffers(void)
97 b->last_is_kernel = -1; 98 b->last_is_kernel = -1;
98 b->tracing = 0; 99 b->tracing = 0;
99 b->buffer_size = buffer_size; 100 b->buffer_size = buffer_size;
100 b->tail_pos = 0;
101 b->head_pos = 0;
102 b->sample_received = 0; 101 b->sample_received = 0;
103 b->sample_lost_overflow = 0; 102 b->sample_lost_overflow = 0;
104 b->backtrace_aborted = 0; 103 b->backtrace_aborted = 0;
@@ -145,47 +144,156 @@ void end_cpu_work(void)
145 flush_scheduled_work(); 144 flush_scheduled_work();
146} 145}
147 146
148static inline int 147/*
149add_sample(struct oprofile_cpu_buffer *cpu_buf, 148 * This function prepares the cpu buffer to write a sample.
150 unsigned long pc, unsigned long event) 149 *
150 * Struct op_entry is used during operations on the ring buffer while
151 * struct op_sample contains the data that is stored in the ring
152 * buffer. Struct entry can be uninitialized. The function reserves a
153 * data array that is specified by size. Use
154 * op_cpu_buffer_write_commit() after preparing the sample. In case of
155 * errors a null pointer is returned, otherwise the pointer to the
156 * sample.
157 *
158 */
159struct op_sample
160*op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size)
161{
162 entry->event = ring_buffer_lock_reserve
163 (op_ring_buffer_write, sizeof(struct op_sample) +
164 size * sizeof(entry->sample->data[0]), &entry->irq_flags);
165 if (entry->event)
166 entry->sample = ring_buffer_event_data(entry->event);
167 else
168 entry->sample = NULL;
169
170 if (!entry->sample)
171 return NULL;
172
173 entry->size = size;
174 entry->data = entry->sample->data;
175
176 return entry->sample;
177}
178
179int op_cpu_buffer_write_commit(struct op_entry *entry)
180{
181 return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event,
182 entry->irq_flags);
183}
184
185struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu)
186{
187 struct ring_buffer_event *e;
188 e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
189 if (e)
190 goto event;
191 if (ring_buffer_swap_cpu(op_ring_buffer_read,
192 op_ring_buffer_write,
193 cpu))
194 return NULL;
195 e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
196 if (e)
197 goto event;
198 return NULL;
199
200event:
201 entry->event = e;
202 entry->sample = ring_buffer_event_data(e);
203 entry->size = (ring_buffer_event_length(e) - sizeof(struct op_sample))
204 / sizeof(entry->sample->data[0]);
205 entry->data = entry->sample->data;
206 return entry->sample;
207}
208
209unsigned long op_cpu_buffer_entries(int cpu)
210{
211 return ring_buffer_entries_cpu(op_ring_buffer_read, cpu)
212 + ring_buffer_entries_cpu(op_ring_buffer_write, cpu);
213}
214
215static int
216op_add_code(struct oprofile_cpu_buffer *cpu_buf, unsigned long backtrace,
217 int is_kernel, struct task_struct *task)
151{ 218{
152 struct op_entry entry; 219 struct op_entry entry;
153 int ret; 220 struct op_sample *sample;
221 unsigned long flags;
222 int size;
223
224 flags = 0;
225
226 if (backtrace)
227 flags |= TRACE_BEGIN;
228
229 /* notice a switch from user->kernel or vice versa */
230 is_kernel = !!is_kernel;
231 if (cpu_buf->last_is_kernel != is_kernel) {
232 cpu_buf->last_is_kernel = is_kernel;
233 flags |= KERNEL_CTX_SWITCH;
234 if (is_kernel)
235 flags |= IS_KERNEL;
236 }
237
238 /* notice a task switch */
239 if (cpu_buf->last_task != task) {
240 cpu_buf->last_task = task;
241 flags |= USER_CTX_SWITCH;
242 }
243
244 if (!flags)
245 /* nothing to do */
246 return 0;
247
248 if (flags & USER_CTX_SWITCH)
249 size = 1;
250 else
251 size = 0;
252
253 sample = op_cpu_buffer_write_reserve(&entry, size);
254 if (!sample)
255 return -ENOMEM;
154 256
155 ret = cpu_buffer_write_entry(&entry); 257 sample->eip = ESCAPE_CODE;
156 if (ret) 258 sample->event = flags;
157 return ret;
158 259
159 entry.sample->eip = pc; 260 if (size)
160 entry.sample->event = event; 261 op_cpu_buffer_add_data(&entry, (unsigned long)task);
161 262
162 ret = cpu_buffer_write_commit(&entry); 263 op_cpu_buffer_write_commit(&entry);
163 if (ret)
164 return ret;
165 264
166 return 0; 265 return 0;
167} 266}
168 267
169static inline int 268static inline int
170add_code(struct oprofile_cpu_buffer *buffer, unsigned long value) 269op_add_sample(struct oprofile_cpu_buffer *cpu_buf,
270 unsigned long pc, unsigned long event)
171{ 271{
172 return add_sample(buffer, ESCAPE_CODE, value); 272 struct op_entry entry;
273 struct op_sample *sample;
274
275 sample = op_cpu_buffer_write_reserve(&entry, 0);
276 if (!sample)
277 return -ENOMEM;
278
279 sample->eip = pc;
280 sample->event = event;
281
282 return op_cpu_buffer_write_commit(&entry);
173} 283}
174 284
175/* This must be safe from any context. It's safe writing here 285/*
176 * because of the head/tail separation of the writer and reader 286 * This must be safe from any context.
177 * of the CPU buffer.
178 * 287 *
179 * is_kernel is needed because on some architectures you cannot 288 * is_kernel is needed because on some architectures you cannot
180 * tell if you are in kernel or user space simply by looking at 289 * tell if you are in kernel or user space simply by looking at
181 * pc. We tag this in the buffer by generating kernel enter/exit 290 * pc. We tag this in the buffer by generating kernel enter/exit
182 * events whenever is_kernel changes 291 * events whenever is_kernel changes
183 */ 292 */
184static int log_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc, 293static int
185 int is_kernel, unsigned long event) 294log_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc,
295 unsigned long backtrace, int is_kernel, unsigned long event)
186{ 296{
187 struct task_struct *task;
188
189 cpu_buf->sample_received++; 297 cpu_buf->sample_received++;
190 298
191 if (pc == ESCAPE_CODE) { 299 if (pc == ESCAPE_CODE) {
@@ -193,25 +301,10 @@ static int log_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc,
193 return 0; 301 return 0;
194 } 302 }
195 303
196 is_kernel = !!is_kernel; 304 if (op_add_code(cpu_buf, backtrace, is_kernel, current))
197 305 goto fail;
198 task = current;
199
200 /* notice a switch from user->kernel or vice versa */
201 if (cpu_buf->last_is_kernel != is_kernel) {
202 cpu_buf->last_is_kernel = is_kernel;
203 if (add_code(cpu_buf, is_kernel))
204 goto fail;
205 }
206
207 /* notice a task switch */
208 if (cpu_buf->last_task != task) {
209 cpu_buf->last_task = task;
210 if (add_code(cpu_buf, (unsigned long)task))
211 goto fail;
212 }
213 306
214 if (add_sample(cpu_buf, pc, event)) 307 if (op_add_sample(cpu_buf, pc, event))
215 goto fail; 308 goto fail;
216 309
217 return 1; 310 return 1;
@@ -221,109 +314,102 @@ fail:
221 return 0; 314 return 0;
222} 315}
223 316
224static int oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf) 317static inline void oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf)
225{ 318{
226 add_code(cpu_buf, CPU_TRACE_BEGIN);
227 cpu_buf->tracing = 1; 319 cpu_buf->tracing = 1;
228 return 1;
229} 320}
230 321
231static void oprofile_end_trace(struct oprofile_cpu_buffer *cpu_buf) 322static inline void oprofile_end_trace(struct oprofile_cpu_buffer *cpu_buf)
232{ 323{
233 cpu_buf->tracing = 0; 324 cpu_buf->tracing = 0;
234} 325}
235 326
236void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs, 327static inline void
237 unsigned long event, int is_kernel) 328__oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
329 unsigned long event, int is_kernel)
238{ 330{
239 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 331 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
240 332 unsigned long backtrace = oprofile_backtrace_depth;
241 if (!backtrace_depth) {
242 log_sample(cpu_buf, pc, is_kernel, event);
243 return;
244 }
245
246 if (!oprofile_begin_trace(cpu_buf))
247 return;
248 333
249 /* 334 /*
250 * if log_sample() fail we can't backtrace since we lost the 335 * if log_sample() fail we can't backtrace since we lost the
251 * source of this event 336 * source of this event
252 */ 337 */
253 if (log_sample(cpu_buf, pc, is_kernel, event)) 338 if (!log_sample(cpu_buf, pc, backtrace, is_kernel, event))
254 oprofile_ops.backtrace(regs, backtrace_depth); 339 /* failed */
340 return;
341
342 if (!backtrace)
343 return;
344
345 oprofile_begin_trace(cpu_buf);
346 oprofile_ops.backtrace(regs, backtrace);
255 oprofile_end_trace(cpu_buf); 347 oprofile_end_trace(cpu_buf);
256} 348}
257 349
350void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
351 unsigned long event, int is_kernel)
352{
353 __oprofile_add_ext_sample(pc, regs, event, is_kernel);
354}
355
258void oprofile_add_sample(struct pt_regs * const regs, unsigned long event) 356void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
259{ 357{
260 int is_kernel = !user_mode(regs); 358 int is_kernel = !user_mode(regs);
261 unsigned long pc = profile_pc(regs); 359 unsigned long pc = profile_pc(regs);
262 360
263 oprofile_add_ext_sample(pc, regs, event, is_kernel); 361 __oprofile_add_ext_sample(pc, regs, event, is_kernel);
264} 362}
265 363
266#ifdef CONFIG_OPROFILE_IBS 364/*
267 365 * Add samples with data to the ring buffer.
268#define MAX_IBS_SAMPLE_SIZE 14 366 *
269 367 * Use oprofile_add_data(&entry, val) to add data and
270void oprofile_add_ibs_sample(struct pt_regs * const regs, 368 * oprofile_write_commit(&entry) to commit the sample.
271 unsigned int * const ibs_sample, int ibs_code) 369 */
370void
371oprofile_write_reserve(struct op_entry *entry, struct pt_regs * const regs,
372 unsigned long pc, int code, int size)
272{ 373{
374 struct op_sample *sample;
273 int is_kernel = !user_mode(regs); 375 int is_kernel = !user_mode(regs);
274 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 376 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
275 struct task_struct *task;
276 int fail = 0;
277 377
278 cpu_buf->sample_received++; 378 cpu_buf->sample_received++;
279 379
280 /* notice a switch from user->kernel or vice versa */ 380 /* no backtraces for samples with data */
281 if (cpu_buf->last_is_kernel != is_kernel) { 381 if (op_add_code(cpu_buf, 0, is_kernel, current))
282 if (add_code(cpu_buf, is_kernel)) 382 goto fail;
283 goto fail;
284 cpu_buf->last_is_kernel = is_kernel;
285 }
286
287 /* notice a task switch */
288 if (!is_kernel) {
289 task = current;
290 if (cpu_buf->last_task != task) {
291 if (add_code(cpu_buf, (unsigned long)task))
292 goto fail;
293 cpu_buf->last_task = task;
294 }
295 }
296
297 fail = fail || add_code(cpu_buf, ibs_code);
298 fail = fail || add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]);
299 fail = fail || add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]);
300 fail = fail || add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]);
301
302 if (ibs_code == IBS_OP_BEGIN) {
303 fail = fail || add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]);
304 fail = fail || add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]);
305 fail = fail || add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]);
306 }
307 383
308 if (fail) 384 sample = op_cpu_buffer_write_reserve(entry, size + 2);
385 if (!sample)
309 goto fail; 386 goto fail;
387 sample->eip = ESCAPE_CODE;
388 sample->event = 0; /* no flags */
310 389
311 if (backtrace_depth) 390 op_cpu_buffer_add_data(entry, code);
312 oprofile_ops.backtrace(regs, backtrace_depth); 391 op_cpu_buffer_add_data(entry, pc);
313 392
314 return; 393 return;
315 394
316fail: 395fail:
317 cpu_buf->sample_lost_overflow++; 396 cpu_buf->sample_lost_overflow++;
318 return;
319} 397}
320 398
321#endif 399int oprofile_add_data(struct op_entry *entry, unsigned long val)
400{
401 return op_cpu_buffer_add_data(entry, val);
402}
403
404int oprofile_write_commit(struct op_entry *entry)
405{
406 return op_cpu_buffer_write_commit(entry);
407}
322 408
323void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event) 409void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
324{ 410{
325 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer); 411 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
326 log_sample(cpu_buf, pc, is_kernel, event); 412 log_sample(cpu_buf, pc, 0, is_kernel, event);
327} 413}
328 414
329void oprofile_add_trace(unsigned long pc) 415void oprofile_add_trace(unsigned long pc)
@@ -340,7 +426,7 @@ void oprofile_add_trace(unsigned long pc)
340 if (pc == ESCAPE_CODE) 426 if (pc == ESCAPE_CODE)
341 goto fail; 427 goto fail;
342 428
343 if (add_sample(cpu_buf, pc, 0)) 429 if (op_add_sample(cpu_buf, pc, 0))
344 goto fail; 430 goto fail;
345 431
346 return; 432 return;
diff --git a/drivers/oprofile/cpu_buffer.h b/drivers/oprofile/cpu_buffer.h
index aacb0f0bc566..63f81c44846a 100644
--- a/drivers/oprofile/cpu_buffer.h
+++ b/drivers/oprofile/cpu_buffer.h
@@ -1,10 +1,11 @@
1/** 1/**
2 * @file cpu_buffer.h 2 * @file cpu_buffer.h
3 * 3 *
4 * @remark Copyright 2002 OProfile authors 4 * @remark Copyright 2002-2009 OProfile authors
5 * @remark Read the file COPYING 5 * @remark Read the file COPYING
6 * 6 *
7 * @author John Levon <levon@movementarian.org> 7 * @author John Levon <levon@movementarian.org>
8 * @author Robert Richter <robert.richter@amd.com>
8 */ 9 */
9 10
10#ifndef OPROFILE_CPU_BUFFER_H 11#ifndef OPROFILE_CPU_BUFFER_H
@@ -31,17 +32,12 @@ void end_cpu_work(void);
31struct op_sample { 32struct op_sample {
32 unsigned long eip; 33 unsigned long eip;
33 unsigned long event; 34 unsigned long event;
35 unsigned long data[0];
34}; 36};
35 37
36struct op_entry { 38struct op_entry;
37 struct ring_buffer_event *event;
38 struct op_sample *sample;
39 unsigned long irq_flags;
40};
41 39
42struct oprofile_cpu_buffer { 40struct oprofile_cpu_buffer {
43 volatile unsigned long head_pos;
44 volatile unsigned long tail_pos;
45 unsigned long buffer_size; 41 unsigned long buffer_size;
46 struct task_struct *last_task; 42 struct task_struct *last_task;
47 int last_is_kernel; 43 int last_is_kernel;
@@ -54,8 +50,6 @@ struct oprofile_cpu_buffer {
54 struct delayed_work work; 50 struct delayed_work work;
55}; 51};
56 52
57extern struct ring_buffer *op_ring_buffer_read;
58extern struct ring_buffer *op_ring_buffer_write;
59DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer); 53DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
60 54
61/* 55/*
@@ -64,7 +58,7 @@ DECLARE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
64 * reset these to invalid values; the next sample collected will 58 * reset these to invalid values; the next sample collected will
65 * populate the buffer with proper values to initialize the buffer 59 * populate the buffer with proper values to initialize the buffer
66 */ 60 */
67static inline void cpu_buffer_reset(int cpu) 61static inline void op_cpu_buffer_reset(int cpu)
68{ 62{
69 struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu); 63 struct oprofile_cpu_buffer *cpu_buf = &per_cpu(cpu_buffer, cpu);
70 64
@@ -72,55 +66,48 @@ static inline void cpu_buffer_reset(int cpu)
72 cpu_buf->last_task = NULL; 66 cpu_buf->last_task = NULL;
73} 67}
74 68
75static inline int cpu_buffer_write_entry(struct op_entry *entry) 69struct op_sample
76{ 70*op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size);
77 entry->event = ring_buffer_lock_reserve(op_ring_buffer_write, 71int op_cpu_buffer_write_commit(struct op_entry *entry);
78 sizeof(struct op_sample), 72struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu);
79 &entry->irq_flags); 73unsigned long op_cpu_buffer_entries(int cpu);
80 if (entry->event)
81 entry->sample = ring_buffer_event_data(entry->event);
82 else
83 entry->sample = NULL;
84
85 if (!entry->sample)
86 return -ENOMEM;
87
88 return 0;
89}
90 74
91static inline int cpu_buffer_write_commit(struct op_entry *entry) 75/* returns the remaining free size of data in the entry */
76static inline
77int op_cpu_buffer_add_data(struct op_entry *entry, unsigned long val)
92{ 78{
93 return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event, 79 if (!entry->size)
94 entry->irq_flags); 80 return 0;
81 *entry->data = val;
82 entry->size--;
83 entry->data++;
84 return entry->size;
95} 85}
96 86
97static inline struct op_sample *cpu_buffer_read_entry(int cpu) 87/* returns the size of data in the entry */
88static inline
89int op_cpu_buffer_get_size(struct op_entry *entry)
98{ 90{
99 struct ring_buffer_event *e; 91 return entry->size;
100 e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
101 if (e)
102 return ring_buffer_event_data(e);
103 if (ring_buffer_swap_cpu(op_ring_buffer_read,
104 op_ring_buffer_write,
105 cpu))
106 return NULL;
107 e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
108 if (e)
109 return ring_buffer_event_data(e);
110 return NULL;
111} 92}
112 93
113/* "acquire" as many cpu buffer slots as we can */ 94/* returns 0 if empty or the size of data including the current value */
114static inline unsigned long cpu_buffer_entries(int cpu) 95static inline
96int op_cpu_buffer_get_data(struct op_entry *entry, unsigned long *val)
115{ 97{
116 return ring_buffer_entries_cpu(op_ring_buffer_read, cpu) 98 int size = entry->size;
117 + ring_buffer_entries_cpu(op_ring_buffer_write, cpu); 99 if (!size)
100 return 0;
101 *val = *entry->data;
102 entry->size--;
103 entry->data++;
104 return size;
118} 105}
119 106
120/* transient events for the CPU buffer -> event buffer */ 107/* extra data flags */
121#define CPU_IS_KERNEL 1 108#define KERNEL_CTX_SWITCH (1UL << 0)
122#define CPU_TRACE_BEGIN 2 109#define IS_KERNEL (1UL << 1)
123#define IBS_FETCH_BEGIN 3 110#define TRACE_BEGIN (1UL << 2)
124#define IBS_OP_BEGIN 4 111#define USER_CTX_SWITCH (1UL << 3)
125 112
126#endif /* OPROFILE_CPU_BUFFER_H */ 113#endif /* OPROFILE_CPU_BUFFER_H */
diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
index 191a3202cecc..2b7ae366ceb1 100644
--- a/drivers/oprofile/event_buffer.c
+++ b/drivers/oprofile/event_buffer.c
@@ -73,8 +73,8 @@ int alloc_event_buffer(void)
73 unsigned long flags; 73 unsigned long flags;
74 74
75 spin_lock_irqsave(&oprofilefs_lock, flags); 75 spin_lock_irqsave(&oprofilefs_lock, flags);
76 buffer_size = fs_buffer_size; 76 buffer_size = oprofile_buffer_size;
77 buffer_watershed = fs_buffer_watershed; 77 buffer_watershed = oprofile_buffer_watershed;
78 spin_unlock_irqrestore(&oprofilefs_lock, flags); 78 spin_unlock_irqrestore(&oprofilefs_lock, flags);
79 79
80 if (buffer_watershed >= buffer_size) 80 if (buffer_watershed >= buffer_size)
diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
index cd375907f26f..3cffce90f82a 100644
--- a/drivers/oprofile/oprof.c
+++ b/drivers/oprofile/oprof.c
@@ -23,7 +23,7 @@
23struct oprofile_operations oprofile_ops; 23struct oprofile_operations oprofile_ops;
24 24
25unsigned long oprofile_started; 25unsigned long oprofile_started;
26unsigned long backtrace_depth; 26unsigned long oprofile_backtrace_depth;
27static unsigned long is_setup; 27static unsigned long is_setup;
28static DEFINE_MUTEX(start_mutex); 28static DEFINE_MUTEX(start_mutex);
29 29
@@ -172,7 +172,7 @@ int oprofile_set_backtrace(unsigned long val)
172 goto out; 172 goto out;
173 } 173 }
174 174
175 backtrace_depth = val; 175 oprofile_backtrace_depth = val;
176 176
177out: 177out:
178 mutex_unlock(&start_mutex); 178 mutex_unlock(&start_mutex);
diff --git a/drivers/oprofile/oprof.h b/drivers/oprofile/oprof.h
index 5df0c21a608f..c288d3c24b50 100644
--- a/drivers/oprofile/oprof.h
+++ b/drivers/oprofile/oprof.h
@@ -21,12 +21,12 @@ void oprofile_stop(void);
21 21
22struct oprofile_operations; 22struct oprofile_operations;
23 23
24extern unsigned long fs_buffer_size; 24extern unsigned long oprofile_buffer_size;
25extern unsigned long fs_cpu_buffer_size; 25extern unsigned long oprofile_cpu_buffer_size;
26extern unsigned long fs_buffer_watershed; 26extern unsigned long oprofile_buffer_watershed;
27extern struct oprofile_operations oprofile_ops; 27extern struct oprofile_operations oprofile_ops;
28extern unsigned long oprofile_started; 28extern unsigned long oprofile_started;
29extern unsigned long backtrace_depth; 29extern unsigned long oprofile_backtrace_depth;
30 30
31struct super_block; 31struct super_block;
32struct dentry; 32struct dentry;
diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
index d8201998b0b7..5d36ffc30dd5 100644
--- a/drivers/oprofile/oprofile_files.c
+++ b/drivers/oprofile/oprofile_files.c
@@ -14,17 +14,18 @@
14#include "oprofile_stats.h" 14#include "oprofile_stats.h"
15#include "oprof.h" 15#include "oprof.h"
16 16
17#define FS_BUFFER_SIZE_DEFAULT 131072 17#define BUFFER_SIZE_DEFAULT 131072
18#define FS_CPU_BUFFER_SIZE_DEFAULT 8192 18#define CPU_BUFFER_SIZE_DEFAULT 8192
19#define FS_BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */ 19#define BUFFER_WATERSHED_DEFAULT 32768 /* FIXME: tune */
20 20
21unsigned long fs_buffer_size; 21unsigned long oprofile_buffer_size;
22unsigned long fs_cpu_buffer_size; 22unsigned long oprofile_cpu_buffer_size;
23unsigned long fs_buffer_watershed; 23unsigned long oprofile_buffer_watershed;
24 24
25static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset) 25static ssize_t depth_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
26{ 26{
27 return oprofilefs_ulong_to_user(backtrace_depth, buf, count, offset); 27 return oprofilefs_ulong_to_user(oprofile_backtrace_depth, buf, count,
28 offset);
28} 29}
29 30
30 31
@@ -125,16 +126,16 @@ static const struct file_operations dump_fops = {
125void oprofile_create_files(struct super_block *sb, struct dentry *root) 126void oprofile_create_files(struct super_block *sb, struct dentry *root)
126{ 127{
127 /* reinitialize default values */ 128 /* reinitialize default values */
128 fs_buffer_size = FS_BUFFER_SIZE_DEFAULT; 129 oprofile_buffer_size = BUFFER_SIZE_DEFAULT;
129 fs_cpu_buffer_size = FS_CPU_BUFFER_SIZE_DEFAULT; 130 oprofile_cpu_buffer_size = CPU_BUFFER_SIZE_DEFAULT;
130 fs_buffer_watershed = FS_BUFFER_WATERSHED_DEFAULT; 131 oprofile_buffer_watershed = BUFFER_WATERSHED_DEFAULT;
131 132
132 oprofilefs_create_file(sb, root, "enable", &enable_fops); 133 oprofilefs_create_file(sb, root, "enable", &enable_fops);
133 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666); 134 oprofilefs_create_file_perm(sb, root, "dump", &dump_fops, 0666);
134 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops); 135 oprofilefs_create_file(sb, root, "buffer", &event_buffer_fops);
135 oprofilefs_create_ulong(sb, root, "buffer_size", &fs_buffer_size); 136 oprofilefs_create_ulong(sb, root, "buffer_size", &oprofile_buffer_size);
136 oprofilefs_create_ulong(sb, root, "buffer_watershed", &fs_buffer_watershed); 137 oprofilefs_create_ulong(sb, root, "buffer_watershed", &oprofile_buffer_watershed);
137 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &fs_cpu_buffer_size); 138 oprofilefs_create_ulong(sb, root, "cpu_buffer_size", &oprofile_cpu_buffer_size);
138 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops); 139 oprofilefs_create_file(sb, root, "cpu_type", &cpu_type_fops);
139 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops); 140 oprofilefs_create_file(sb, root, "backtrace_depth", &depth_fops);
140 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops); 141 oprofilefs_create_file(sb, root, "pointer_size", &pointer_size_fops);
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
index c68c496b2c49..7aa35248181b 100644
--- a/drivers/regulator/wm8350-regulator.c
+++ b/drivers/regulator/wm8350-regulator.c
@@ -1412,6 +1412,97 @@ int wm8350_register_regulator(struct wm8350 *wm8350, int reg,
1412} 1412}
1413EXPORT_SYMBOL_GPL(wm8350_register_regulator); 1413EXPORT_SYMBOL_GPL(wm8350_register_regulator);
1414 1414
1415/**
1416 * wm8350_register_led - Register a WM8350 LED output
1417 *
1418 * @param wm8350 The WM8350 device to configure.
1419 * @param lednum LED device index to create.
1420 * @param dcdc The DCDC to use for the LED.
1421 * @param isink The ISINK to use for the LED.
1422 * @param pdata Configuration for the LED.
1423 *
1424 * The WM8350 supports the use of an ISINK together with a DCDC to
1425 * provide a power-efficient LED driver. This function registers the
1426 * regulators and instantiates the platform device for a LED. The
1427 * operating modes for the LED regulators must be configured using
1428 * wm8350_isink_set_flash(), wm8350_dcdc25_set_mode() and
1429 * wm8350_dcdc_set_slot() prior to calling this function.
1430 */
1431int wm8350_register_led(struct wm8350 *wm8350, int lednum, int dcdc, int isink,
1432 struct wm8350_led_platform_data *pdata)
1433{
1434 struct wm8350_led *led;
1435 struct platform_device *pdev;
1436 int ret;
1437
1438 if (lednum > ARRAY_SIZE(wm8350->pmic.led) || lednum < 0) {
1439 dev_err(wm8350->dev, "Invalid LED index %d\n", lednum);
1440 return -ENODEV;
1441 }
1442
1443 led = &wm8350->pmic.led[lednum];
1444
1445 if (led->pdev) {
1446 dev_err(wm8350->dev, "LED %d already allocated\n", lednum);
1447 return -EINVAL;
1448 }
1449
1450 pdev = platform_device_alloc("wm8350-led", lednum);
1451 if (pdev == NULL) {
1452 dev_err(wm8350->dev, "Failed to allocate LED %d\n", lednum);
1453 return -ENOMEM;
1454 }
1455
1456 led->isink_consumer.dev = &pdev->dev;
1457 led->isink_consumer.supply = "led_isink";
1458 led->isink_init.num_consumer_supplies = 1;
1459 led->isink_init.consumer_supplies = &led->isink_consumer;
1460 led->isink_init.constraints.min_uA = 0;
1461 led->isink_init.constraints.max_uA = pdata->max_uA;
1462 led->isink_init.constraints.valid_ops_mask = REGULATOR_CHANGE_CURRENT;
1463 led->isink_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
1464 ret = wm8350_register_regulator(wm8350, isink, &led->isink_init);
1465 if (ret != 0) {
1466 platform_device_put(pdev);
1467 return ret;
1468 }
1469
1470 led->dcdc_consumer.dev = &pdev->dev;
1471 led->dcdc_consumer.supply = "led_vcc";
1472 led->dcdc_init.num_consumer_supplies = 1;
1473 led->dcdc_init.consumer_supplies = &led->dcdc_consumer;
1474 led->dcdc_init.constraints.valid_modes_mask = REGULATOR_MODE_NORMAL;
1475 ret = wm8350_register_regulator(wm8350, dcdc, &led->dcdc_init);
1476 if (ret != 0) {
1477 platform_device_put(pdev);
1478 return ret;
1479 }
1480
1481 switch (isink) {
1482 case WM8350_ISINK_A:
1483 wm8350->pmic.isink_A_dcdc = dcdc;
1484 break;
1485 case WM8350_ISINK_B:
1486 wm8350->pmic.isink_B_dcdc = dcdc;
1487 break;
1488 }
1489
1490 pdev->dev.platform_data = pdata;
1491 pdev->dev.parent = wm8350->dev;
1492 ret = platform_device_add(pdev);
1493 if (ret != 0) {
1494 dev_err(wm8350->dev, "Failed to register LED %d: %d\n",
1495 lednum, ret);
1496 platform_device_put(pdev);
1497 return ret;
1498 }
1499
1500 led->pdev = pdev;
1501
1502 return 0;
1503}
1504EXPORT_SYMBOL_GPL(wm8350_register_led);
1505
1415static struct platform_driver wm8350_regulator_driver = { 1506static struct platform_driver wm8350_regulator_driver = {
1416 .probe = wm8350_regulator_probe, 1507 .probe = wm8350_regulator_probe,
1417 .remove = wm8350_regulator_remove, 1508 .remove = wm8350_regulator_remove,
diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c
index 570ae59c1d5e..bd5914994142 100644
--- a/drivers/s390/block/dasd.c
+++ b/drivers/s390/block/dasd.c
@@ -336,6 +336,9 @@ static int
336dasd_state_ready_to_online(struct dasd_device * device) 336dasd_state_ready_to_online(struct dasd_device * device)
337{ 337{
338 int rc; 338 int rc;
339 struct gendisk *disk;
340 struct disk_part_iter piter;
341 struct hd_struct *part;
339 342
340 if (device->discipline->ready_to_online) { 343 if (device->discipline->ready_to_online) {
341 rc = device->discipline->ready_to_online(device); 344 rc = device->discipline->ready_to_online(device);
@@ -343,8 +346,14 @@ dasd_state_ready_to_online(struct dasd_device * device)
343 return rc; 346 return rc;
344 } 347 }
345 device->state = DASD_STATE_ONLINE; 348 device->state = DASD_STATE_ONLINE;
346 if (device->block) 349 if (device->block) {
347 dasd_schedule_block_bh(device->block); 350 dasd_schedule_block_bh(device->block);
351 disk = device->block->bdev->bd_disk;
352 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
353 while ((part = disk_part_iter_next(&piter)))
354 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
355 disk_part_iter_exit(&piter);
356 }
348 return 0; 357 return 0;
349} 358}
350 359
@@ -354,6 +363,9 @@ dasd_state_ready_to_online(struct dasd_device * device)
354static int dasd_state_online_to_ready(struct dasd_device *device) 363static int dasd_state_online_to_ready(struct dasd_device *device)
355{ 364{
356 int rc; 365 int rc;
366 struct gendisk *disk;
367 struct disk_part_iter piter;
368 struct hd_struct *part;
357 369
358 if (device->discipline->online_to_ready) { 370 if (device->discipline->online_to_ready) {
359 rc = device->discipline->online_to_ready(device); 371 rc = device->discipline->online_to_ready(device);
@@ -361,6 +373,13 @@ static int dasd_state_online_to_ready(struct dasd_device *device)
361 return rc; 373 return rc;
362 } 374 }
363 device->state = DASD_STATE_READY; 375 device->state = DASD_STATE_READY;
376 if (device->block) {
377 disk = device->block->bdev->bd_disk;
378 disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
379 while ((part = disk_part_iter_next(&piter)))
380 kobject_uevent(&part_to_dev(part)->kobj, KOBJ_CHANGE);
381 disk_part_iter_exit(&piter);
382 }
364 return 0; 383 return 0;
365} 384}
366 385
diff --git a/drivers/s390/block/dasd_devmap.c b/drivers/s390/block/dasd_devmap.c
index 2ef25731d197..300e28a531f8 100644
--- a/drivers/s390/block/dasd_devmap.c
+++ b/drivers/s390/block/dasd_devmap.c
@@ -206,6 +206,8 @@ dasd_feature_list(char *str, char **endp)
206 features |= DASD_FEATURE_USEDIAG; 206 features |= DASD_FEATURE_USEDIAG;
207 else if (len == 6 && !strncmp(str, "erplog", 6)) 207 else if (len == 6 && !strncmp(str, "erplog", 6))
208 features |= DASD_FEATURE_ERPLOG; 208 features |= DASD_FEATURE_ERPLOG;
209 else if (len == 8 && !strncmp(str, "failfast", 8))
210 features |= DASD_FEATURE_FAILFAST;
209 else { 211 else {
210 MESSAGE(KERN_WARNING, 212 MESSAGE(KERN_WARNING,
211 "unsupported feature: %*s, " 213 "unsupported feature: %*s, "
@@ -667,6 +669,51 @@ dasd_device_from_cdev(struct ccw_device *cdev)
667 */ 669 */
668 670
669/* 671/*
672 * failfast controls the behaviour, if no path is available
673 */
674static ssize_t dasd_ff_show(struct device *dev, struct device_attribute *attr,
675 char *buf)
676{
677 struct dasd_devmap *devmap;
678 int ff_flag;
679
680 devmap = dasd_find_busid(dev->bus_id);
681 if (!IS_ERR(devmap))
682 ff_flag = (devmap->features & DASD_FEATURE_FAILFAST) != 0;
683 else
684 ff_flag = (DASD_FEATURE_DEFAULT & DASD_FEATURE_FAILFAST) != 0;
685 return snprintf(buf, PAGE_SIZE, ff_flag ? "1\n" : "0\n");
686}
687
688static ssize_t dasd_ff_store(struct device *dev, struct device_attribute *attr,
689 const char *buf, size_t count)
690{
691 struct dasd_devmap *devmap;
692 int val;
693 char *endp;
694
695 devmap = dasd_devmap_from_cdev(to_ccwdev(dev));
696 if (IS_ERR(devmap))
697 return PTR_ERR(devmap);
698
699 val = simple_strtoul(buf, &endp, 0);
700 if (((endp + 1) < (buf + count)) || (val > 1))
701 return -EINVAL;
702
703 spin_lock(&dasd_devmap_lock);
704 if (val)
705 devmap->features |= DASD_FEATURE_FAILFAST;
706 else
707 devmap->features &= ~DASD_FEATURE_FAILFAST;
708 if (devmap->device)
709 devmap->device->features = devmap->features;
710 spin_unlock(&dasd_devmap_lock);
711 return count;
712}
713
714static DEVICE_ATTR(failfast, 0644, dasd_ff_show, dasd_ff_store);
715
716/*
670 * readonly controls the readonly status of a dasd 717 * readonly controls the readonly status of a dasd
671 */ 718 */
672static ssize_t 719static ssize_t
@@ -1020,6 +1067,7 @@ static struct attribute * dasd_attrs[] = {
1020 &dev_attr_use_diag.attr, 1067 &dev_attr_use_diag.attr,
1021 &dev_attr_eer_enabled.attr, 1068 &dev_attr_eer_enabled.attr,
1022 &dev_attr_erplog.attr, 1069 &dev_attr_erplog.attr,
1070 &dev_attr_failfast.attr,
1023 NULL, 1071 NULL,
1024}; 1072};
1025 1073
diff --git a/drivers/s390/block/dasd_diag.c b/drivers/s390/block/dasd_diag.c
index 7844461a995b..ef2a56952054 100644
--- a/drivers/s390/block/dasd_diag.c
+++ b/drivers/s390/block/dasd_diag.c
@@ -544,7 +544,8 @@ static struct dasd_ccw_req *dasd_diag_build_cp(struct dasd_device *memdev,
544 } 544 }
545 cqr->retries = DIAG_MAX_RETRIES; 545 cqr->retries = DIAG_MAX_RETRIES;
546 cqr->buildclk = get_clock(); 546 cqr->buildclk = get_clock();
547 if (blk_noretry_request(req)) 547 if (blk_noretry_request(req) ||
548 block->base->features & DASD_FEATURE_FAILFAST)
548 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 549 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
549 cqr->startdev = memdev; 550 cqr->startdev = memdev;
550 cqr->memdev = memdev; 551 cqr->memdev = memdev;
diff --git a/drivers/s390/block/dasd_eckd.c b/drivers/s390/block/dasd_eckd.c
index bd2c52e20762..bdb87998f364 100644
--- a/drivers/s390/block/dasd_eckd.c
+++ b/drivers/s390/block/dasd_eckd.c
@@ -1700,7 +1700,8 @@ static struct dasd_ccw_req *dasd_eckd_build_cp(struct dasd_device *startdev,
1700 recid++; 1700 recid++;
1701 } 1701 }
1702 } 1702 }
1703 if (blk_noretry_request(req)) 1703 if (blk_noretry_request(req) ||
1704 block->base->features & DASD_FEATURE_FAILFAST)
1704 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 1705 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
1705 cqr->startdev = startdev; 1706 cqr->startdev = startdev;
1706 cqr->memdev = startdev; 1707 cqr->memdev = startdev;
diff --git a/drivers/s390/block/dasd_fba.c b/drivers/s390/block/dasd_fba.c
index 7d442aeff3d1..f1d176021694 100644
--- a/drivers/s390/block/dasd_fba.c
+++ b/drivers/s390/block/dasd_fba.c
@@ -355,7 +355,8 @@ static struct dasd_ccw_req *dasd_fba_build_cp(struct dasd_device * memdev,
355 recid++; 355 recid++;
356 } 356 }
357 } 357 }
358 if (blk_noretry_request(req)) 358 if (blk_noretry_request(req) ||
359 block->base->features & DASD_FEATURE_FAILFAST)
359 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags); 360 set_bit(DASD_CQR_FLAGS_FAILFAST, &cqr->flags);
360 cqr->startdev = memdev; 361 cqr->startdev = memdev;
361 cqr->memdev = memdev; 362 cqr->memdev = memdev;
diff --git a/drivers/s390/char/Kconfig b/drivers/s390/char/Kconfig
index 643033890e34..0769ced52dbd 100644
--- a/drivers/s390/char/Kconfig
+++ b/drivers/s390/char/Kconfig
@@ -100,7 +100,7 @@ comment "S/390 tape interface support"
100 100
101config S390_TAPE_BLOCK 101config S390_TAPE_BLOCK
102 bool "Support for tape block devices" 102 bool "Support for tape block devices"
103 depends on S390_TAPE 103 depends on S390_TAPE && BLOCK
104 help 104 help
105 Select this option if you want to access your channel-attached tape 105 Select this option if you want to access your channel-attached tape
106 devices using the block device interface. This interface is similar 106 devices using the block device interface. This interface is similar
diff --git a/drivers/s390/cio/qdio_debug.c b/drivers/s390/cio/qdio_debug.c
index f8a3b6967f69..da7afb04e71f 100644
--- a/drivers/s390/cio/qdio_debug.c
+++ b/drivers/s390/cio/qdio_debug.c
@@ -169,6 +169,8 @@ static void setup_debugfs_entry(struct qdio_q *q, struct ccw_device *cdev)
169 q->nr); 169 q->nr);
170 debugfs_queues[i] = debugfs_create_file(name, S_IFREG | S_IRUGO | S_IWUSR, 170 debugfs_queues[i] = debugfs_create_file(name, S_IFREG | S_IRUGO | S_IWUSR,
171 debugfs_root, q, &debugfs_fops); 171 debugfs_root, q, &debugfs_fops);
172 if (IS_ERR(debugfs_queues[i]))
173 debugfs_queues[i] = NULL;
172} 174}
173 175
174void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev) 176void qdio_setup_debug_entries(struct qdio_irq *irq_ptr, struct ccw_device *cdev)
diff --git a/drivers/video/backlight/Kconfig b/drivers/video/backlight/Kconfig
index 4a4dd9adc328..72facb9eb7db 100644
--- a/drivers/video/backlight/Kconfig
+++ b/drivers/video/backlight/Kconfig
@@ -52,11 +52,11 @@ config LCD_ILI9320
52 then say y to include a power driver for it. 52 then say y to include a power driver for it.
53 53
54config LCD_TDO24M 54config LCD_TDO24M
55 tristate "Toppoly TDO24M LCD Panels support" 55 tristate "Toppoly TDO24M and TDO35S LCD Panels support"
56 depends on LCD_CLASS_DEVICE && SPI_MASTER 56 depends on LCD_CLASS_DEVICE && SPI_MASTER
57 default n 57 default n
58 help 58 help
59 If you have a Toppoly TDO24M series LCD panel, say y here to 59 If you have a Toppoly TDO24M/TDO35S series LCD panel, say y here to
60 include the support for it. 60 include the support for it.
61 61
62config LCD_VGG2432A4 62config LCD_VGG2432A4
@@ -123,17 +123,14 @@ config BACKLIGHT_ATMEL_PWM
123 To compile this driver as a module, choose M here: the module will be 123 To compile this driver as a module, choose M here: the module will be
124 called atmel-pwm-bl. 124 called atmel-pwm-bl.
125 125
126config BACKLIGHT_CORGI 126config BACKLIGHT_GENERIC
127 tristate "Generic (aka Sharp Corgi) Backlight Driver (DEPRECATED)" 127 tristate "Generic (aka Sharp Corgi) Backlight Driver"
128 depends on BACKLIGHT_CLASS_DEVICE 128 depends on BACKLIGHT_CLASS_DEVICE
129 default n 129 default y
130 help 130 help
131 Say y to enable the generic platform backlight driver previously 131 Say y to enable the generic platform backlight driver previously
132 known as the Corgi backlight driver. If you have a Sharp Zaurus 132 known as the Corgi backlight driver. If you have a Sharp Zaurus
133 SL-C7xx, SL-Cxx00 or SL-6000x say y. Most users can say n. 133 SL-C7xx, SL-Cxx00 or SL-6000x say y.
134
135 Note: this driver is marked as deprecated, try enable SPI and
136 use the new corgi_lcd driver with integrated backlight control
137 134
138config BACKLIGHT_LOCOMO 135config BACKLIGHT_LOCOMO
139 tristate "Sharp LOCOMO LCD/Backlight Driver" 136 tristate "Sharp LOCOMO LCD/Backlight Driver"
diff --git a/drivers/video/backlight/Makefile b/drivers/video/backlight/Makefile
index 103427de6703..363b3cb2f01b 100644
--- a/drivers/video/backlight/Makefile
+++ b/drivers/video/backlight/Makefile
@@ -11,7 +11,7 @@ obj-$(CONFIG_LCD_TOSA) += tosa_lcd.o
11 11
12obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o 12obj-$(CONFIG_BACKLIGHT_CLASS_DEVICE) += backlight.o
13obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o 13obj-$(CONFIG_BACKLIGHT_ATMEL_PWM) += atmel-pwm-bl.o
14obj-$(CONFIG_BACKLIGHT_CORGI) += corgi_bl.o 14obj-$(CONFIG_BACKLIGHT_GENERIC) += generic_bl.o
15obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o 15obj-$(CONFIG_BACKLIGHT_HP680) += hp680_bl.o
16obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o 16obj-$(CONFIG_BACKLIGHT_LOCOMO) += locomolcd.o
17obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o 17obj-$(CONFIG_BACKLIGHT_OMAP1) += omap1_bl.o
diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c
index 0664fc032235..157057c79ca3 100644
--- a/drivers/video/backlight/backlight.c
+++ b/drivers/video/backlight/backlight.c
@@ -40,6 +40,10 @@ static int fb_notifier_callback(struct notifier_block *self,
40 if (!bd->ops->check_fb || 40 if (!bd->ops->check_fb ||
41 bd->ops->check_fb(evdata->info)) { 41 bd->ops->check_fb(evdata->info)) {
42 bd->props.fb_blank = *(int *)evdata->data; 42 bd->props.fb_blank = *(int *)evdata->data;
43 if (bd->props.fb_blank == FB_BLANK_UNBLANK)
44 bd->props.state &= ~BL_CORE_FBBLANK;
45 else
46 bd->props.state |= BL_CORE_FBBLANK;
43 backlight_update_status(bd); 47 backlight_update_status(bd);
44 } 48 }
45 mutex_unlock(&bd->ops_lock); 49 mutex_unlock(&bd->ops_lock);
@@ -80,20 +84,18 @@ static ssize_t backlight_show_power(struct device *dev,
80static ssize_t backlight_store_power(struct device *dev, 84static ssize_t backlight_store_power(struct device *dev,
81 struct device_attribute *attr, const char *buf, size_t count) 85 struct device_attribute *attr, const char *buf, size_t count)
82{ 86{
83 int rc = -ENXIO; 87 int rc;
84 char *endp;
85 struct backlight_device *bd = to_backlight_device(dev); 88 struct backlight_device *bd = to_backlight_device(dev);
86 int power = simple_strtoul(buf, &endp, 0); 89 unsigned long power;
87 size_t size = endp - buf;
88 90
89 if (*endp && isspace(*endp)) 91 rc = strict_strtoul(buf, 0, &power);
90 size++; 92 if (rc)
91 if (size != count) 93 return rc;
92 return -EINVAL;
93 94
95 rc = -ENXIO;
94 mutex_lock(&bd->ops_lock); 96 mutex_lock(&bd->ops_lock);
95 if (bd->ops) { 97 if (bd->ops) {
96 pr_debug("backlight: set power to %d\n", power); 98 pr_debug("backlight: set power to %lu\n", power);
97 if (bd->props.power != power) { 99 if (bd->props.power != power) {
98 bd->props.power = power; 100 bd->props.power = power;
99 backlight_update_status(bd); 101 backlight_update_status(bd);
@@ -116,28 +118,25 @@ static ssize_t backlight_show_brightness(struct device *dev,
116static ssize_t backlight_store_brightness(struct device *dev, 118static ssize_t backlight_store_brightness(struct device *dev,
117 struct device_attribute *attr, const char *buf, size_t count) 119 struct device_attribute *attr, const char *buf, size_t count)
118{ 120{
119 int rc = -ENXIO; 121 int rc;
120 char *endp;
121 struct backlight_device *bd = to_backlight_device(dev); 122 struct backlight_device *bd = to_backlight_device(dev);
122 int brightness = simple_strtoul(buf, &endp, 0); 123 unsigned long brightness;
123 size_t size = endp - buf; 124
125 rc = strict_strtoul(buf, 0, &brightness);
126 if (rc)
127 return rc;
124 128
125 if (*endp && isspace(*endp)) 129 rc = -ENXIO;
126 size++;
127 if (size != count)
128 return -EINVAL;
129 130
130 mutex_lock(&bd->ops_lock); 131 mutex_lock(&bd->ops_lock);
131 if (bd->ops) { 132 if (bd->ops) {
132 if (brightness > bd->props.max_brightness) 133 if (brightness > bd->props.max_brightness)
133 rc = -EINVAL; 134 rc = -EINVAL;
134 else { 135 else {
135 pr_debug("backlight: set brightness to %d\n", 136 pr_debug("backlight: set brightness to %lu\n",
136 brightness); 137 brightness);
137 if (bd->props.brightness != brightness) { 138 bd->props.brightness = brightness;
138 bd->props.brightness = brightness; 139 backlight_update_status(bd);
139 backlight_update_status(bd);
140 }
141 rc = count; 140 rc = count;
142 } 141 }
143 } 142 }
@@ -170,6 +169,34 @@ static ssize_t backlight_show_actual_brightness(struct device *dev,
170 169
171static struct class *backlight_class; 170static struct class *backlight_class;
172 171
172static int backlight_suspend(struct device *dev, pm_message_t state)
173{
174 struct backlight_device *bd = to_backlight_device(dev);
175
176 if (bd->ops->options & BL_CORE_SUSPENDRESUME) {
177 mutex_lock(&bd->ops_lock);
178 bd->props.state |= BL_CORE_SUSPENDED;
179 backlight_update_status(bd);
180 mutex_unlock(&bd->ops_lock);
181 }
182
183 return 0;
184}
185
186static int backlight_resume(struct device *dev)
187{
188 struct backlight_device *bd = to_backlight_device(dev);
189
190 if (bd->ops->options & BL_CORE_SUSPENDRESUME) {
191 mutex_lock(&bd->ops_lock);
192 bd->props.state &= ~BL_CORE_SUSPENDED;
193 backlight_update_status(bd);
194 mutex_unlock(&bd->ops_lock);
195 }
196
197 return 0;
198}
199
173static void bl_device_release(struct device *dev) 200static void bl_device_release(struct device *dev)
174{ 201{
175 struct backlight_device *bd = to_backlight_device(dev); 202 struct backlight_device *bd = to_backlight_device(dev);
@@ -286,6 +313,8 @@ static int __init backlight_class_init(void)
286 } 313 }
287 314
288 backlight_class->dev_attrs = bl_device_attributes; 315 backlight_class->dev_attrs = bl_device_attributes;
316 backlight_class->suspend = backlight_suspend;
317 backlight_class->resume = backlight_resume;
289 return 0; 318 return 0;
290} 319}
291 320
diff --git a/drivers/video/backlight/corgi_bl.c b/drivers/video/backlight/corgi_bl.c
deleted file mode 100644
index 4d4d037e3ec9..000000000000
--- a/drivers/video/backlight/corgi_bl.c
+++ /dev/null
@@ -1,169 +0,0 @@
1/*
2 * Backlight Driver for Sharp Zaurus Handhelds (various models)
3 *
4 * Copyright (c) 2004-2006 Richard Purdie
5 *
6 * Based on Sharp's 2.4 Backlight Driver
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 */
13
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/platform_device.h>
18#include <linux/mutex.h>
19#include <linux/fb.h>
20#include <linux/backlight.h>
21
22static int corgibl_intensity;
23static struct backlight_properties corgibl_data;
24static struct backlight_device *corgi_backlight_device;
25static struct generic_bl_info *bl_machinfo;
26
27static unsigned long corgibl_flags;
28#define CORGIBL_SUSPENDED 0x01
29#define CORGIBL_BATTLOW 0x02
30
31static int corgibl_send_intensity(struct backlight_device *bd)
32{
33 int intensity = bd->props.brightness;
34
35 if (bd->props.power != FB_BLANK_UNBLANK)
36 intensity = 0;
37 if (bd->props.fb_blank != FB_BLANK_UNBLANK)
38 intensity = 0;
39 if (corgibl_flags & CORGIBL_SUSPENDED)
40 intensity = 0;
41 if (corgibl_flags & CORGIBL_BATTLOW)
42 intensity &= bl_machinfo->limit_mask;
43
44 bl_machinfo->set_bl_intensity(intensity);
45
46 corgibl_intensity = intensity;
47
48 if (bl_machinfo->kick_battery)
49 bl_machinfo->kick_battery();
50
51 return 0;
52}
53
54#ifdef CONFIG_PM
55static int corgibl_suspend(struct platform_device *pdev, pm_message_t state)
56{
57 struct backlight_device *bd = platform_get_drvdata(pdev);
58
59 corgibl_flags |= CORGIBL_SUSPENDED;
60 backlight_update_status(bd);
61 return 0;
62}
63
64static int corgibl_resume(struct platform_device *pdev)
65{
66 struct backlight_device *bd = platform_get_drvdata(pdev);
67
68 corgibl_flags &= ~CORGIBL_SUSPENDED;
69 backlight_update_status(bd);
70 return 0;
71}
72#else
73#define corgibl_suspend NULL
74#define corgibl_resume NULL
75#endif
76
77static int corgibl_get_intensity(struct backlight_device *bd)
78{
79 return corgibl_intensity;
80}
81
82/*
83 * Called when the battery is low to limit the backlight intensity.
84 * If limit==0 clear any limit, otherwise limit the intensity
85 */
86void corgibl_limit_intensity(int limit)
87{
88 if (limit)
89 corgibl_flags |= CORGIBL_BATTLOW;
90 else
91 corgibl_flags &= ~CORGIBL_BATTLOW;
92 backlight_update_status(corgi_backlight_device);
93}
94EXPORT_SYMBOL(corgibl_limit_intensity);
95
96
97static struct backlight_ops corgibl_ops = {
98 .get_brightness = corgibl_get_intensity,
99 .update_status = corgibl_send_intensity,
100};
101
102static int corgibl_probe(struct platform_device *pdev)
103{
104 struct generic_bl_info *machinfo = pdev->dev.platform_data;
105 const char *name = "generic-bl";
106
107 bl_machinfo = machinfo;
108 if (!machinfo->limit_mask)
109 machinfo->limit_mask = -1;
110
111 if (machinfo->name)
112 name = machinfo->name;
113
114 corgi_backlight_device = backlight_device_register (name,
115 &pdev->dev, NULL, &corgibl_ops);
116 if (IS_ERR (corgi_backlight_device))
117 return PTR_ERR (corgi_backlight_device);
118
119 platform_set_drvdata(pdev, corgi_backlight_device);
120
121 corgi_backlight_device->props.max_brightness = machinfo->max_intensity;
122 corgi_backlight_device->props.power = FB_BLANK_UNBLANK;
123 corgi_backlight_device->props.brightness = machinfo->default_intensity;
124 backlight_update_status(corgi_backlight_device);
125
126 printk("Corgi Backlight Driver Initialized.\n");
127 return 0;
128}
129
130static int corgibl_remove(struct platform_device *pdev)
131{
132 struct backlight_device *bd = platform_get_drvdata(pdev);
133
134 corgibl_data.power = 0;
135 corgibl_data.brightness = 0;
136 backlight_update_status(bd);
137
138 backlight_device_unregister(bd);
139
140 printk("Corgi Backlight Driver Unloaded\n");
141 return 0;
142}
143
144static struct platform_driver corgibl_driver = {
145 .probe = corgibl_probe,
146 .remove = corgibl_remove,
147 .suspend = corgibl_suspend,
148 .resume = corgibl_resume,
149 .driver = {
150 .name = "generic-bl",
151 },
152};
153
154static int __init corgibl_init(void)
155{
156 return platform_driver_register(&corgibl_driver);
157}
158
159static void __exit corgibl_exit(void)
160{
161 platform_driver_unregister(&corgibl_driver);
162}
163
164module_init(corgibl_init);
165module_exit(corgibl_exit);
166
167MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
168MODULE_DESCRIPTION("Corgi Backlight Driver");
169MODULE_LICENSE("GPL");
diff --git a/drivers/video/backlight/cr_bllcd.c b/drivers/video/backlight/cr_bllcd.c
index 26add8898605..b9fe62b475c6 100644
--- a/drivers/video/backlight/cr_bllcd.c
+++ b/drivers/video/backlight/cr_bllcd.c
@@ -259,22 +259,18 @@ static int __init cr_backlight_init(void)
259{ 259{
260 int ret = platform_driver_register(&cr_backlight_driver); 260 int ret = platform_driver_register(&cr_backlight_driver);
261 261
262 if (!ret) { 262 if (ret)
263 crp = platform_device_alloc("cr_backlight", -1); 263 return ret;
264 if (!crp)
265 return -ENOMEM;
266 264
267 ret = platform_device_add(crp); 265 crp = platform_device_register_simple("cr_backlight", -1, NULL, 0);
268 266 if (IS_ERR(crp)) {
269 if (ret) { 267 platform_driver_unregister(&cr_backlight_driver);
270 platform_device_put(crp); 268 return PTR_ERR(crp);
271 platform_driver_unregister(&cr_backlight_driver);
272 }
273 } 269 }
274 270
275 printk("Carillo Ranch Backlight Driver Initialized.\n"); 271 printk("Carillo Ranch Backlight Driver Initialized.\n");
276 272
277 return ret; 273 return 0;
278} 274}
279 275
280static void __exit cr_backlight_exit(void) 276static void __exit cr_backlight_exit(void)
diff --git a/drivers/video/backlight/generic_bl.c b/drivers/video/backlight/generic_bl.c
new file mode 100644
index 000000000000..6d27f62fdcd0
--- /dev/null
+++ b/drivers/video/backlight/generic_bl.c
@@ -0,0 +1,147 @@
1/*
2 * Generic Backlight Driver
3 *
4 * Copyright (c) 2004-2008 Richard Purdie
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/kernel.h>
14#include <linux/init.h>
15#include <linux/platform_device.h>
16#include <linux/mutex.h>
17#include <linux/fb.h>
18#include <linux/backlight.h>
19
20static int genericbl_intensity;
21static struct backlight_device *generic_backlight_device;
22static struct generic_bl_info *bl_machinfo;
23
24/* Flag to signal when the battery is low */
25#define GENERICBL_BATTLOW BL_CORE_DRIVER1
26
27static int genericbl_send_intensity(struct backlight_device *bd)
28{
29 int intensity = bd->props.brightness;
30
31 if (bd->props.power != FB_BLANK_UNBLANK)
32 intensity = 0;
33 if (bd->props.state & BL_CORE_FBBLANK)
34 intensity = 0;
35 if (bd->props.state & BL_CORE_SUSPENDED)
36 intensity = 0;
37 if (bd->props.state & GENERICBL_BATTLOW)
38 intensity &= bl_machinfo->limit_mask;
39
40 bl_machinfo->set_bl_intensity(intensity);
41
42 genericbl_intensity = intensity;
43
44 if (bl_machinfo->kick_battery)
45 bl_machinfo->kick_battery();
46
47 return 0;
48}
49
50static int genericbl_get_intensity(struct backlight_device *bd)
51{
52 return genericbl_intensity;
53}
54
55/*
56 * Called when the battery is low to limit the backlight intensity.
57 * If limit==0 clear any limit, otherwise limit the intensity
58 */
59void corgibl_limit_intensity(int limit)
60{
61 struct backlight_device *bd = generic_backlight_device;
62
63 mutex_lock(&bd->ops_lock);
64 if (limit)
65 bd->props.state |= GENERICBL_BATTLOW;
66 else
67 bd->props.state &= ~GENERICBL_BATTLOW;
68 backlight_update_status(generic_backlight_device);
69 mutex_unlock(&bd->ops_lock);
70}
71EXPORT_SYMBOL(corgibl_limit_intensity);
72
73static struct backlight_ops genericbl_ops = {
74 .options = BL_CORE_SUSPENDRESUME,
75 .get_brightness = genericbl_get_intensity,
76 .update_status = genericbl_send_intensity,
77};
78
79static int genericbl_probe(struct platform_device *pdev)
80{
81 struct generic_bl_info *machinfo = pdev->dev.platform_data;
82 const char *name = "generic-bl";
83 struct backlight_device *bd;
84
85 bl_machinfo = machinfo;
86 if (!machinfo->limit_mask)
87 machinfo->limit_mask = -1;
88
89 if (machinfo->name)
90 name = machinfo->name;
91
92 bd = backlight_device_register (name,
93 &pdev->dev, NULL, &genericbl_ops);
94 if (IS_ERR (bd))
95 return PTR_ERR (bd);
96
97 platform_set_drvdata(pdev, bd);
98
99 bd->props.max_brightness = machinfo->max_intensity;
100 bd->props.power = FB_BLANK_UNBLANK;
101 bd->props.brightness = machinfo->default_intensity;
102 backlight_update_status(bd);
103
104 generic_backlight_device = bd;
105
106 printk("Generic Backlight Driver Initialized.\n");
107 return 0;
108}
109
110static int genericbl_remove(struct platform_device *pdev)
111{
112 struct backlight_device *bd = platform_get_drvdata(pdev);
113
114 bd->props.power = 0;
115 bd->props.brightness = 0;
116 backlight_update_status(bd);
117
118 backlight_device_unregister(bd);
119
120 printk("Generic Backlight Driver Unloaded\n");
121 return 0;
122}
123
124static struct platform_driver genericbl_driver = {
125 .probe = genericbl_probe,
126 .remove = genericbl_remove,
127 .driver = {
128 .name = "generic-bl",
129 },
130};
131
132static int __init genericbl_init(void)
133{
134 return platform_driver_register(&genericbl_driver);
135}
136
137static void __exit genericbl_exit(void)
138{
139 platform_driver_unregister(&genericbl_driver);
140}
141
142module_init(genericbl_init);
143module_exit(genericbl_exit);
144
145MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
146MODULE_DESCRIPTION("Generic Backlight Driver");
147MODULE_LICENSE("GPL");
diff --git a/drivers/video/backlight/hp680_bl.c b/drivers/video/backlight/hp680_bl.c
index d4cfed0b26d5..5be55a20d8c7 100644
--- a/drivers/video/backlight/hp680_bl.c
+++ b/drivers/video/backlight/hp680_bl.c
@@ -151,19 +151,15 @@ static int __init hp680bl_init(void)
151 int ret; 151 int ret;
152 152
153 ret = platform_driver_register(&hp680bl_driver); 153 ret = platform_driver_register(&hp680bl_driver);
154 if (!ret) { 154 if (ret)
155 hp680bl_device = platform_device_alloc("hp680-bl", -1); 155 return ret;
156 if (!hp680bl_device) 156 hp680bl_device = platform_device_register_simple("hp680-bl", -1,
157 return -ENOMEM; 157 NULL, 0);
158 158 if (IS_ERR(hp680bl_device)) {
159 ret = platform_device_add(hp680bl_device); 159 platform_driver_unregister(&hp680bl_driver);
160 160 return PTR_ERR(hp680bl_device);
161 if (ret) {
162 platform_device_put(hp680bl_device);
163 platform_driver_unregister(&hp680bl_driver);
164 }
165 } 161 }
166 return ret; 162 return 0;
167} 163}
168 164
169static void __exit hp680bl_exit(void) 165static void __exit hp680bl_exit(void)
diff --git a/drivers/video/backlight/mbp_nvidia_bl.c b/drivers/video/backlight/mbp_nvidia_bl.c
index 06964af761c6..65864c500455 100644
--- a/drivers/video/backlight/mbp_nvidia_bl.c
+++ b/drivers/video/backlight/mbp_nvidia_bl.c
@@ -70,6 +70,7 @@ static int mbp_get_intensity(struct backlight_device *bd)
70} 70}
71 71
72static struct backlight_ops mbp_ops = { 72static struct backlight_ops mbp_ops = {
73 .options = BL_CORE_SUSPENDRESUME,
73 .get_brightness = mbp_get_intensity, 74 .get_brightness = mbp_get_intensity,
74 .update_status = mbp_send_intensity, 75 .update_status = mbp_send_intensity,
75}; 76};
diff --git a/drivers/video/backlight/progear_bl.c b/drivers/video/backlight/progear_bl.c
index 15fb4d58b5bc..9edaf24fd82d 100644
--- a/drivers/video/backlight/progear_bl.c
+++ b/drivers/video/backlight/progear_bl.c
@@ -119,20 +119,16 @@ static int __init progearbl_init(void)
119{ 119{
120 int ret = platform_driver_register(&progearbl_driver); 120 int ret = platform_driver_register(&progearbl_driver);
121 121
122 if (!ret) { 122 if (ret)
123 progearbl_device = platform_device_alloc("progear-bl", -1); 123 return ret;
124 if (!progearbl_device) 124 progearbl_device = platform_device_register_simple("progear-bl", -1,
125 return -ENOMEM; 125 NULL, 0);
126 126 if (IS_ERR(progearbl_device)) {
127 ret = platform_device_add(progearbl_device); 127 platform_driver_unregister(&progearbl_driver);
128 128 return PTR_ERR(progearbl_device);
129 if (ret) {
130 platform_device_put(progearbl_device);
131 platform_driver_unregister(&progearbl_driver);
132 }
133 } 129 }
134 130
135 return ret; 131 return 0;
136} 132}
137 133
138static void __exit progearbl_exit(void) 134static void __exit progearbl_exit(void)
diff --git a/drivers/video/backlight/tdo24m.c b/drivers/video/backlight/tdo24m.c
index 8427669162ea..1dae7f8f3c6b 100644
--- a/drivers/video/backlight/tdo24m.c
+++ b/drivers/video/backlight/tdo24m.c
@@ -14,6 +14,7 @@
14#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/spi/spi.h> 16#include <linux/spi/spi.h>
17#include <linux/spi/tdo24m.h>
17#include <linux/fb.h> 18#include <linux/fb.h>
18#include <linux/lcd.h> 19#include <linux/lcd.h>
19 20
@@ -31,6 +32,9 @@ struct tdo24m {
31 struct spi_transfer xfer; 32 struct spi_transfer xfer;
32 uint8_t *buf; 33 uint8_t *buf;
33 34
35 int (*adj_mode)(struct tdo24m *lcd, int mode);
36 int color_invert;
37
34 int power; 38 int power;
35 int mode; 39 int mode;
36}; 40};
@@ -66,7 +70,7 @@ static uint32_t lcd_panel_off[] = {
66 CMD_NULL, 70 CMD_NULL,
67}; 71};
68 72
69static uint32_t lcd_vga_pass_through[] = { 73static uint32_t lcd_vga_pass_through_tdo24m[] = {
70 CMD1(0xB0, 0x16), 74 CMD1(0xB0, 0x16),
71 CMD1(0xBC, 0x80), 75 CMD1(0xBC, 0x80),
72 CMD1(0xE1, 0x00), 76 CMD1(0xE1, 0x00),
@@ -75,7 +79,7 @@ static uint32_t lcd_vga_pass_through[] = {
75 CMD_NULL, 79 CMD_NULL,
76}; 80};
77 81
78static uint32_t lcd_qvga_pass_through[] = { 82static uint32_t lcd_qvga_pass_through_tdo24m[] = {
79 CMD1(0xB0, 0x16), 83 CMD1(0xB0, 0x16),
80 CMD1(0xBC, 0x81), 84 CMD1(0xBC, 0x81),
81 CMD1(0xE1, 0x00), 85 CMD1(0xE1, 0x00),
@@ -84,7 +88,7 @@ static uint32_t lcd_qvga_pass_through[] = {
84 CMD_NULL, 88 CMD_NULL,
85}; 89};
86 90
87static uint32_t lcd_vga_transfer[] = { 91static uint32_t lcd_vga_transfer_tdo24m[] = {
88 CMD1(0xcf, 0x02), /* Blanking period control (1) */ 92 CMD1(0xcf, 0x02), /* Blanking period control (1) */
89 CMD2(0xd0, 0x08, 0x04), /* Blanking period control (2) */ 93 CMD2(0xd0, 0x08, 0x04), /* Blanking period control (2) */
90 CMD1(0xd1, 0x01), /* CKV timing control on/off */ 94 CMD1(0xd1, 0x01), /* CKV timing control on/off */
@@ -110,6 +114,35 @@ static uint32_t lcd_qvga_transfer[] = {
110 CMD_NULL, 114 CMD_NULL,
111}; 115};
112 116
117static uint32_t lcd_vga_pass_through_tdo35s[] = {
118 CMD1(0xB0, 0x16),
119 CMD1(0xBC, 0x80),
120 CMD1(0xE1, 0x00),
121 CMD1(0x3B, 0x00),
122 CMD_NULL,
123};
124
125static uint32_t lcd_qvga_pass_through_tdo35s[] = {
126 CMD1(0xB0, 0x16),
127 CMD1(0xBC, 0x81),
128 CMD1(0xE1, 0x00),
129 CMD1(0x3B, 0x22),
130 CMD_NULL,
131};
132
133static uint32_t lcd_vga_transfer_tdo35s[] = {
134 CMD1(0xcf, 0x02), /* Blanking period control (1) */
135 CMD2(0xd0, 0x08, 0x04), /* Blanking period control (2) */
136 CMD1(0xd1, 0x01), /* CKV timing control on/off */
137 CMD2(0xd2, 0x00, 0x1e), /* CKV 1,2 timing control */
138 CMD2(0xd3, 0x14, 0x28), /* OEV timing control */
139 CMD2(0xd4, 0x28, 0x64), /* ASW timing control (1) */
140 CMD1(0xd5, 0x28), /* ASW timing control (2) */
141 CMD0(0x21), /* Invert for normally black display */
142 CMD0(0x29), /* Display on */
143 CMD_NULL,
144};
145
113static uint32_t lcd_panel_config[] = { 146static uint32_t lcd_panel_config[] = {
114 CMD2(0xb8, 0xff, 0xf9), /* Output control */ 147 CMD2(0xb8, 0xff, 0xf9), /* Output control */
115 CMD0(0x11), /* sleep out */ 148 CMD0(0x11), /* sleep out */
@@ -148,6 +181,8 @@ static int tdo24m_writes(struct tdo24m *lcd, uint32_t *array)
148 int nparams, err = 0; 181 int nparams, err = 0;
149 182
150 for (; *p != CMD_NULL; p++) { 183 for (; *p != CMD_NULL; p++) {
184 if (!lcd->color_invert && *p == CMD0(0x21))
185 continue;
151 186
152 nparams = (*p >> 30) & 0x3; 187 nparams = (*p >> 30) & 0x3;
153 188
@@ -184,12 +219,33 @@ static int tdo24m_adj_mode(struct tdo24m *lcd, int mode)
184{ 219{
185 switch (mode) { 220 switch (mode) {
186 case MODE_VGA: 221 case MODE_VGA:
187 tdo24m_writes(lcd, lcd_vga_pass_through); 222 tdo24m_writes(lcd, lcd_vga_pass_through_tdo24m);
188 tdo24m_writes(lcd, lcd_panel_config); 223 tdo24m_writes(lcd, lcd_panel_config);
189 tdo24m_writes(lcd, lcd_vga_transfer); 224 tdo24m_writes(lcd, lcd_vga_transfer_tdo24m);
190 break; 225 break;
191 case MODE_QVGA: 226 case MODE_QVGA:
192 tdo24m_writes(lcd, lcd_qvga_pass_through); 227 tdo24m_writes(lcd, lcd_qvga_pass_through_tdo24m);
228 tdo24m_writes(lcd, lcd_panel_config);
229 tdo24m_writes(lcd, lcd_qvga_transfer);
230 break;
231 default:
232 return -EINVAL;
233 }
234
235 lcd->mode = mode;
236 return 0;
237}
238
239static int tdo35s_adj_mode(struct tdo24m *lcd, int mode)
240{
241 switch (mode) {
242 case MODE_VGA:
243 tdo24m_writes(lcd, lcd_vga_pass_through_tdo35s);
244 tdo24m_writes(lcd, lcd_panel_config);
245 tdo24m_writes(lcd, lcd_vga_transfer_tdo35s);
246 break;
247 case MODE_QVGA:
248 tdo24m_writes(lcd, lcd_qvga_pass_through_tdo35s);
193 tdo24m_writes(lcd, lcd_panel_config); 249 tdo24m_writes(lcd, lcd_panel_config);
194 tdo24m_writes(lcd, lcd_qvga_transfer); 250 tdo24m_writes(lcd, lcd_qvga_transfer);
195 break; 251 break;
@@ -213,7 +269,7 @@ static int tdo24m_power_on(struct tdo24m *lcd)
213 if (err) 269 if (err)
214 goto out; 270 goto out;
215 271
216 err = tdo24m_adj_mode(lcd, lcd->mode); 272 err = lcd->adj_mode(lcd, lcd->mode);
217out: 273out:
218 return err; 274 return err;
219} 275}
@@ -262,7 +318,7 @@ static int tdo24m_set_mode(struct lcd_device *ld, struct fb_videomode *m)
262 if (lcd->mode == mode) 318 if (lcd->mode == mode)
263 return 0; 319 return 0;
264 320
265 return tdo24m_adj_mode(lcd, mode); 321 return lcd->adj_mode(lcd, mode);
266} 322}
267 323
268static struct lcd_ops tdo24m_ops = { 324static struct lcd_ops tdo24m_ops = {
@@ -276,8 +332,16 @@ static int __devinit tdo24m_probe(struct spi_device *spi)
276 struct tdo24m *lcd; 332 struct tdo24m *lcd;
277 struct spi_message *m; 333 struct spi_message *m;
278 struct spi_transfer *x; 334 struct spi_transfer *x;
335 struct tdo24m_platform_data *pdata;
336 enum tdo24m_model model;
279 int err; 337 int err;
280 338
339 pdata = spi->dev.platform_data;
340 if (pdata)
341 model = pdata->model;
342 else
343 model = TDO24M;
344
281 spi->bits_per_word = 8; 345 spi->bits_per_word = 8;
282 spi->mode = SPI_MODE_3; 346 spi->mode = SPI_MODE_3;
283 err = spi_setup(spi); 347 err = spi_setup(spi);
@@ -306,6 +370,20 @@ static int __devinit tdo24m_probe(struct spi_device *spi)
306 x->tx_buf = &lcd->buf[0]; 370 x->tx_buf = &lcd->buf[0];
307 spi_message_add_tail(x, m); 371 spi_message_add_tail(x, m);
308 372
373 switch (model) {
374 case TDO24M:
375 lcd->color_invert = 1;
376 lcd->adj_mode = tdo24m_adj_mode;
377 break;
378 case TDO35S:
379 lcd->adj_mode = tdo35s_adj_mode;
380 lcd->color_invert = 0;
381 break;
382 default:
383 dev_err(&spi->dev, "Unsupported model");
384 goto out_free;
385 }
386
309 lcd->lcd_dev = lcd_device_register("tdo24m", &spi->dev, 387 lcd->lcd_dev = lcd_device_register("tdo24m", &spi->dev,
310 lcd, &tdo24m_ops); 388 lcd, &tdo24m_ops);
311 if (IS_ERR(lcd->lcd_dev)) { 389 if (IS_ERR(lcd->lcd_dev)) {
diff --git a/drivers/video/backlight/tosa_lcd.c b/drivers/video/backlight/tosa_lcd.c
index 57a26649f1a5..b7fbc75a62fc 100644
--- a/drivers/video/backlight/tosa_lcd.c
+++ b/drivers/video/backlight/tosa_lcd.c
@@ -39,6 +39,7 @@ struct tosa_lcd_data {
39 struct i2c_client *i2c; 39 struct i2c_client *i2c;
40 40
41 int lcd_power; 41 int lcd_power;
42 bool is_vga;
42}; 43};
43 44
44static int tosa_tg_send(struct spi_device *spi, int adrs, uint8_t data) 45static int tosa_tg_send(struct spi_device *spi, int adrs, uint8_t data)
@@ -81,8 +82,12 @@ static void tosa_lcd_tg_init(struct tosa_lcd_data *data)
81static void tosa_lcd_tg_on(struct tosa_lcd_data *data) 82static void tosa_lcd_tg_on(struct tosa_lcd_data *data)
82{ 83{
83 struct spi_device *spi = data->spi; 84 struct spi_device *spi = data->spi;
84 const int value = TG_REG0_COLOR | TG_REG0_UD | TG_REG0_LR; 85 int value = TG_REG0_COLOR | TG_REG0_UD | TG_REG0_LR;
85 tosa_tg_send(spi, TG_PNLCTL, value | TG_REG0_VQV); /* this depends on mode */ 86
87 if (data->is_vga)
88 value |= TG_REG0_VQV;
89
90 tosa_tg_send(spi, TG_PNLCTL, value);
86 91
87 /* TG LCD pannel power up */ 92 /* TG LCD pannel power up */
88 tosa_tg_send(spi, TG_PINICTL,0x4); 93 tosa_tg_send(spi, TG_PINICTL,0x4);
@@ -142,9 +147,25 @@ static int tosa_lcd_get_power(struct lcd_device *lcd)
142 return data->lcd_power; 147 return data->lcd_power;
143} 148}
144 149
150static int tosa_lcd_set_mode(struct lcd_device *lcd, struct fb_videomode *mode)
151{
152 struct tosa_lcd_data *data = lcd_get_data(lcd);
153
154 if (mode->xres == 320 || mode->yres == 320)
155 data->is_vga = false;
156 else
157 data->is_vga = true;
158
159 if (POWER_IS_ON(data->lcd_power))
160 tosa_lcd_tg_on(data);
161
162 return 0;
163}
164
145static struct lcd_ops tosa_lcd_ops = { 165static struct lcd_ops tosa_lcd_ops = {
146 .set_power = tosa_lcd_set_power, 166 .set_power = tosa_lcd_set_power,
147 .get_power = tosa_lcd_get_power, 167 .get_power = tosa_lcd_get_power,
168 .set_mode = tosa_lcd_set_mode,
148}; 169};
149 170
150static int __devinit tosa_lcd_probe(struct spi_device *spi) 171static int __devinit tosa_lcd_probe(struct spi_device *spi)
@@ -156,6 +177,8 @@ static int __devinit tosa_lcd_probe(struct spi_device *spi)
156 if (!data) 177 if (!data)
157 return -ENOMEM; 178 return -ENOMEM;
158 179
180 data->is_vga = true; /* defaut to VGA mode */
181
159 /* 182 /*
160 * bits_per_word cannot be configured in platform data 183 * bits_per_word cannot be configured in platform data
161 */ 184 */
diff --git a/drivers/video/backlight/vgg2432a4.c b/drivers/video/backlight/vgg2432a4.c
index 593c7687d54a..8e653b8a6f17 100644
--- a/drivers/video/backlight/vgg2432a4.c
+++ b/drivers/video/backlight/vgg2432a4.c
@@ -137,7 +137,7 @@ static int vgg2432a4_lcd_init(struct ili9320 *lcd,
137 137
138 ili9320_write(lcd, ILI9320_RGB_IF1, cfg->rgb_if1); 138 ili9320_write(lcd, ILI9320_RGB_IF1, cfg->rgb_if1);
139 ili9320_write(lcd, ILI9320_FRAMEMAKER, 0x0); 139 ili9320_write(lcd, ILI9320_FRAMEMAKER, 0x0);
140 ili9320_write(lcd, ILI9320_RGB_IF2, ILI9320_RGBIF2_DPL); 140 ili9320_write(lcd, ILI9320_RGB_IF2, cfg->rgb_if2);
141 141
142 ret = ili9320_write_regs(lcd, vgg_init1, ARRAY_SIZE(vgg_init1)); 142 ret = ili9320_write_regs(lcd, vgg_init1, ARRAY_SIZE(vgg_init1));
143 if (ret != 0) 143 if (ret != 0)