2 * NVEC: NVIDIA compliant embedded controller interface
4 * Copyright (C) 2011 The AC100 Kernel Team <ac100@lists.lauchpad.net>
6 * Authors: Pierre-Hugues Husson <phhusson@free.fr>
7 * Ilya Petrov <ilya.muromec@gmail.com>
8 * Marc Dietrich <marvin24@gmx.de>
9 * Julian Andres Klode <jak@jak-linux.org>
11 * This file is subject to the terms and conditions of the GNU General Public
12 * License. See the file "COPYING" in the main directory of this archive
21 #include <linux/atomic.h>
22 #include <linux/completion.h>
23 #include <linux/interrupt.h>
25 #include <linux/irq.h>
26 #include <linux/slab.h>
27 #include <linux/gpio.h>
28 #include <linux/serio.h>
29 #include <linux/delay.h>
30 #include <linux/input.h>
31 #include <linux/workqueue.h>
32 #include <linux/clk.h>
34 #include <linux/semaphore.h>
35 #include <linux/list.h>
36 #include <linux/notifier.h>
37 #include <linux/platform_device.h>
38 #include <linux/mfd/core.h>
40 #include <mach/iomap.h>
46 #define I2C_CNFG_PACKET_MODE_EN (1<<10)
47 #define I2C_CNFG_NEW_MASTER_SFM (1<<11)
48 #define I2C_CNFG_DEBOUNCE_CNT_SHIFT 12
50 #define I2C_SL_CNFG 0x20
51 #define I2C_SL_NEWL (1<<2)
52 #define I2C_SL_NACK (1<<1)
53 #define I2C_SL_RESP (1<<0)
54 #define I2C_SL_IRQ (1<<3)
55 #define END_TRANS (1<<4)
59 #define I2C_SL_RCVD 0x24
60 #define I2C_SL_STATUS 0x28
61 #define I2C_SL_ADDR1 0x2c
62 #define I2C_SL_ADDR2 0x30
63 #define I2C_SL_DELAY_COUNT 0x3c
66 * enum nvec_msg_category - Message categories for nvec_msg_alloc()
67 * @NVEC_MSG_RX: The message is an incoming message (from EC)
68 * @NVEC_MSG_TX: The message is an outgoing message (to EC)
70 enum nvec_msg_category {
75 static const unsigned char EC_DISABLE_EVENT_REPORTING[3] = "\x04\x00\x00";
76 static const unsigned char EC_ENABLE_EVENT_REPORTING[3] = "\x04\x00\x01";
77 static const unsigned char EC_GET_FIRMWARE_VERSION[2] = "\x07\x15";
79 static struct nvec_chip *nvec_power_handle;
81 static struct mfd_cell nvec_devices[] = {
105 * nvec_register_notifier - Register a notifier with nvec
106 * @nvec: A &struct nvec_chip
107 * @nb: The notifier block to register
109 * Registers a notifier with @nvec. The notifier will be added to an atomic
110 * notifier chain that is called for all received messages except those that
111 * correspond to a request initiated by nvec_write_sync().
113 int nvec_register_notifier(struct nvec_chip *nvec, struct notifier_block *nb,
116 return atomic_notifier_chain_register(&nvec->notifier_list, nb);
118 EXPORT_SYMBOL_GPL(nvec_register_notifier);
121 * nvec_status_notifier - The final notifier
123 * Prints a message about control events not handled in the notifier
126 static int nvec_status_notifier(struct notifier_block *nb,
127 unsigned long event_type, void *data)
129 unsigned char *msg = (unsigned char *)data;
131 if (event_type != NVEC_CNTL)
134 printk(KERN_WARNING "unhandled msg type %ld\n", event_type);
135 print_hex_dump(KERN_WARNING, "payload: ", DUMP_PREFIX_NONE, 16, 1,
136 msg, msg[1] + 2, true);
143 * @nvec: A &struct nvec_chip
144 * @category: Pool category, see &enum nvec_msg_category
146 * Allocate a single &struct nvec_msg object from the message pool of
147 * @nvec. The result shall be passed to nvec_msg_free() if no longer
150 * Outgoing messages are placed in the upper 75% of the pool, keeping the
151 * lower 25% available for RX buffers only. The reason is to prevent a
152 * situation where all buffers are full and a message is thus endlessly
153 * retried because the response could never be processed.
155 static struct nvec_msg *nvec_msg_alloc(struct nvec_chip *nvec,
156 enum nvec_msg_category category)
158 int i = (category == NVEC_MSG_TX) ? (NVEC_POOL_SIZE / 4) : 0;
160 for (; i < NVEC_POOL_SIZE; i++) {
161 if (atomic_xchg(&nvec->msg_pool[i].used, 1) == 0) {
162 dev_vdbg(nvec->dev, "INFO: Allocate %i\n", i);
163 return &nvec->msg_pool[i];
167 dev_err(nvec->dev, "could not allocate %s buffer\n",
168 (category == NVEC_MSG_TX) ? "TX" : "RX");
175 * @nvec: A &struct nvec_chip
176 * @msg: A message (must be allocated by nvec_msg_alloc() and belong to @nvec)
178 * Free the given message
180 inline void nvec_msg_free(struct nvec_chip *nvec, struct nvec_msg *msg)
182 if (msg != &nvec->tx_scratch)
183 dev_vdbg(nvec->dev, "INFO: Free %ti\n", msg - nvec->msg_pool);
184 atomic_set(&msg->used, 0);
186 EXPORT_SYMBOL_GPL(nvec_msg_free);
189 * nvec_msg_is_event - Return %true if @msg is an event
192 static bool nvec_msg_is_event(struct nvec_msg *msg)
194 return msg->data[0] >> 7;
198 * nvec_msg_size - Get the size of a message
199 * @msg: The message to get the size for
201 * This only works for received messages, not for outgoing messages.
203 static size_t nvec_msg_size(struct nvec_msg *msg)
205 bool is_event = nvec_msg_is_event(msg);
206 int event_length = (msg->data[0] & 0x60) >> 5;
208 /* for variable size, payload size in byte 1 + count (1) + cmd (1) */
209 if (!is_event || event_length == NVEC_VAR_SIZE)
210 return (msg->pos || msg->size) ? (msg->data[1] + 2) : 0;
211 else if (event_length == NVEC_2BYTES)
213 else if (event_length == NVEC_3BYTES)
220 * nvec_gpio_set_value - Set the GPIO value
221 * @nvec: A &struct nvec_chip
222 * @value: The value to write (0 or 1)
224 * Like gpio_set_value(), but generating debugging information
226 static void nvec_gpio_set_value(struct nvec_chip *nvec, int value)
228 dev_dbg(nvec->dev, "GPIO changed from %u to %u\n",
229 gpio_get_value(nvec->gpio), value);
230 gpio_set_value(nvec->gpio, value);
234 * nvec_write_async - Asynchronously write a message to NVEC
235 * @nvec: An nvec_chip instance
236 * @data: The message data, starting with the request type
237 * @size: The size of @data
239 * Queue a single message to be transferred to the embedded controller
240 * and return immediately.
242 * Returns: 0 on success, a negative error code on failure. If a failure
243 * occured, the nvec driver may print an error.
245 int nvec_write_async(struct nvec_chip *nvec, const unsigned char *data,
248 struct nvec_msg *msg;
251 msg = nvec_msg_alloc(nvec, NVEC_MSG_TX);
257 memcpy(msg->data + 1, data, size);
258 msg->size = size + 1;
260 spin_lock_irqsave(&nvec->tx_lock, flags);
261 list_add_tail(&msg->node, &nvec->tx_data);
262 spin_unlock_irqrestore(&nvec->tx_lock, flags);
264 queue_work(nvec->wq, &nvec->tx_work);
268 EXPORT_SYMBOL(nvec_write_async);
271 * nvec_write_sync - Write a message to nvec and read the response
272 * @nvec: An &struct nvec_chip
273 * @data: The data to write
274 * @size: The size of @data
276 * This is similar to nvec_write_async(), but waits for the
277 * request to be answered before returning. This function
278 * uses a mutex and can thus not be called from e.g.
279 * interrupt handlers.
281 * Returns: A pointer to the response message on success,
282 * %NULL on failure. Free with nvec_msg_free() once no longer
285 struct nvec_msg *nvec_write_sync(struct nvec_chip *nvec,
286 const unsigned char *data, short size)
288 struct nvec_msg *msg;
290 mutex_lock(&nvec->sync_write_mutex);
292 nvec->sync_write_pending = (data[1] << 8) + data[0];
294 if (nvec_write_async(nvec, data, size) < 0)
297 dev_dbg(nvec->dev, "nvec_sync_write: 0x%04x\n",
298 nvec->sync_write_pending);
299 if (!(wait_for_completion_timeout(&nvec->sync_write,
300 msecs_to_jiffies(2000)))) {
301 dev_warn(nvec->dev, "timeout waiting for sync write to complete\n");
302 mutex_unlock(&nvec->sync_write_mutex);
306 dev_dbg(nvec->dev, "nvec_sync_write: pong!\n");
308 msg = nvec->last_sync_msg;
310 mutex_unlock(&nvec->sync_write_mutex);
314 EXPORT_SYMBOL(nvec_write_sync);
317 * nvec_request_master - Process outgoing messages
318 * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip)
320 * Processes all outgoing requests by sending the request and awaiting the
321 * response, then continuing with the next request. Once a request has a
322 * matching response, it will be freed and removed from the list.
324 static void nvec_request_master(struct work_struct *work)
326 struct nvec_chip *nvec = container_of(work, struct nvec_chip, tx_work);
329 struct nvec_msg *msg;
331 spin_lock_irqsave(&nvec->tx_lock, flags);
332 while (!list_empty(&nvec->tx_data)) {
333 msg = list_first_entry(&nvec->tx_data, struct nvec_msg, node);
334 spin_unlock_irqrestore(&nvec->tx_lock, flags);
335 nvec_gpio_set_value(nvec, 0);
336 err = wait_for_completion_interruptible_timeout(
337 &nvec->ec_transfer, msecs_to_jiffies(5000));
340 dev_warn(nvec->dev, "timeout waiting for ec transfer\n");
341 nvec_gpio_set_value(nvec, 1);
345 spin_lock_irqsave(&nvec->tx_lock, flags);
348 list_del_init(&msg->node);
349 nvec_msg_free(nvec, msg);
352 spin_unlock_irqrestore(&nvec->tx_lock, flags);
356 * parse_msg - Print some information and call the notifiers on an RX message
357 * @nvec: A &struct nvec_chip
358 * @msg: A message received by @nvec
360 * Paarse some pieces of the message and then call the chain of notifiers
361 * registered via nvec_register_notifier.
363 static int parse_msg(struct nvec_chip *nvec, struct nvec_msg *msg)
365 if ((msg->data[0] & 1 << 7) == 0 && msg->data[3]) {
366 dev_err(nvec->dev, "ec responded %02x %02x %02x %02x\n",
367 msg->data[0], msg->data[1], msg->data[2], msg->data[3]);
371 if ((msg->data[0] >> 7) == 1 && (msg->data[0] & 0x0f) == 5)
372 print_hex_dump(KERN_WARNING, "ec system event ",
373 DUMP_PREFIX_NONE, 16, 1, msg->data,
374 msg->data[1] + 2, true);
376 atomic_notifier_call_chain(&nvec->notifier_list, msg->data[0] & 0x8f,
383 * nvec_dispatch - Process messages received from the EC
384 * @work: A &struct work_struct (the tx_worker member of &struct nvec_chip)
386 * Process messages previously received from the EC and put into the RX
387 * queue of the &struct nvec_chip instance associated with @work.
389 static void nvec_dispatch(struct work_struct *work)
391 struct nvec_chip *nvec = container_of(work, struct nvec_chip, rx_work);
393 struct nvec_msg *msg;
395 spin_lock_irqsave(&nvec->rx_lock, flags);
396 while (!list_empty(&nvec->rx_data)) {
397 msg = list_first_entry(&nvec->rx_data, struct nvec_msg, node);
398 list_del_init(&msg->node);
399 spin_unlock_irqrestore(&nvec->rx_lock, flags);
401 if (nvec->sync_write_pending ==
402 (msg->data[2] << 8) + msg->data[0]) {
403 dev_dbg(nvec->dev, "sync write completed!\n");
404 nvec->sync_write_pending = 0;
405 nvec->last_sync_msg = msg;
406 complete(&nvec->sync_write);
408 parse_msg(nvec, msg);
409 nvec_msg_free(nvec, msg);
411 spin_lock_irqsave(&nvec->rx_lock, flags);
413 spin_unlock_irqrestore(&nvec->rx_lock, flags);
417 * nvec_tx_completed - Complete the current transfer
418 * @nvec: A &struct nvec_chip
420 * This is called when we have received an END_TRANS on a TX transfer.
422 static void nvec_tx_completed(struct nvec_chip *nvec)
424 /* We got an END_TRANS, let's skip this, maybe there's an event */
425 if (nvec->tx->pos != nvec->tx->size) {
426 dev_err(nvec->dev, "premature END_TRANS, resending\n");
428 nvec_gpio_set_value(nvec, 0);
435 * nvec_rx_completed - Complete the current transfer
436 * @nvec: A &struct nvec_chip
438 * This is called when we have received an END_TRANS on a RX transfer.
440 static void nvec_rx_completed(struct nvec_chip *nvec)
442 if (nvec->rx->pos != nvec_msg_size(nvec->rx)) {
443 dev_err(nvec->dev, "RX incomplete: Expected %u bytes, got %u\n",
444 (uint) nvec_msg_size(nvec->rx),
445 (uint) nvec->rx->pos);
447 nvec_msg_free(nvec, nvec->rx);
452 spin_lock(&nvec->rx_lock);
454 /* add the received data to the work list
455 and move the ring buffer pointer to the next entry */
456 list_add_tail(&nvec->rx->node, &nvec->rx_data);
458 spin_unlock(&nvec->rx_lock);
462 if (!nvec_msg_is_event(nvec->rx))
463 complete(&nvec->ec_transfer);
465 queue_work(nvec->wq, &nvec->rx_work);
469 * nvec_invalid_flags - Send an error message about invalid flags and jump
470 * @nvec: The nvec device
471 * @status: The status flags
472 * @reset: Whether we shall jump to state 0.
474 static void nvec_invalid_flags(struct nvec_chip *nvec, unsigned int status,
477 dev_err(nvec->dev, "unexpected status flags 0x%02x during state %i\n",
478 status, nvec->state);
484 * nvec_tx_set - Set the message to transfer (nvec->tx)
485 * @nvec: A &struct nvec_chip
487 * Gets the first entry from the tx_data list of @nvec and sets the
488 * tx member to it. If the tx_data list is empty, this uses the
489 * tx_scratch message to send a no operation message.
491 static void nvec_tx_set(struct nvec_chip *nvec)
493 spin_lock(&nvec->tx_lock);
494 if (list_empty(&nvec->tx_data)) {
495 dev_err(nvec->dev, "empty tx - sending no-op\n");
496 memcpy(nvec->tx_scratch.data, "\x02\x07\x02", 3);
497 nvec->tx_scratch.size = 3;
498 nvec->tx_scratch.pos = 0;
499 nvec->tx = &nvec->tx_scratch;
500 list_add_tail(&nvec->tx->node, &nvec->tx_data);
502 nvec->tx = list_first_entry(&nvec->tx_data, struct nvec_msg,
506 spin_unlock(&nvec->tx_lock);
508 dev_dbg(nvec->dev, "Sending message of length %u, command 0x%x\n",
509 (uint)nvec->tx->size, nvec->tx->data[1]);
513 * nvec_interrupt - Interrupt handler
515 * @dev: The nvec device
517 * Interrupt handler that fills our RX buffers and empties our TX
518 * buffers. This uses a finite state machine with ridiculous amounts
519 * of error checking, in order to be fairly reliable.
521 static irqreturn_t nvec_interrupt(int irq, void *dev)
523 unsigned long status;
524 unsigned int received = 0;
525 unsigned char to_send = 0xff;
526 const unsigned long irq_mask = I2C_SL_IRQ | END_TRANS | RCVD | RNW;
527 struct nvec_chip *nvec = dev;
528 unsigned int state = nvec->state;
530 status = readl(nvec->base + I2C_SL_STATUS);
532 /* Filter out some errors */
533 if ((status & irq_mask) == 0 && (status & ~irq_mask) != 0) {
534 dev_err(nvec->dev, "unexpected irq mask %lx\n", status);
537 if ((status & I2C_SL_IRQ) == 0) {
538 dev_err(nvec->dev, "Spurious IRQ\n");
542 /* The EC did not request a read, so it send us something, read it */
543 if ((status & RNW) == 0) {
544 received = readl(nvec->base + I2C_SL_RCVD);
546 writel(0, nvec->base + I2C_SL_RCVD);
549 if (status == (I2C_SL_IRQ | RCVD))
552 switch (nvec->state) {
553 case 0: /* Verify that its a transfer start, the rest later */
554 if (status != (I2C_SL_IRQ | RCVD))
555 nvec_invalid_flags(nvec, status, false);
557 case 1: /* command byte */
558 if (status != I2C_SL_IRQ) {
559 nvec_invalid_flags(nvec, status, true);
561 nvec->rx = nvec_msg_alloc(nvec, NVEC_MSG_RX);
562 /* Should not happen in a normal world */
563 if (unlikely(nvec->rx == NULL)) {
567 nvec->rx->data[0] = received;
572 case 2: /* first byte after command */
573 if (status == (I2C_SL_IRQ | RNW | RCVD)) {
575 if (nvec->rx->data[0] != 0x01) {
577 "Read without prior read command\n");
581 nvec_msg_free(nvec, nvec->rx);
584 BUG_ON(nvec->tx->size < 1);
585 to_send = nvec->tx->data[0];
587 } else if (status == (I2C_SL_IRQ)) {
588 BUG_ON(nvec->rx == NULL);
589 nvec->rx->data[1] = received;
593 nvec_invalid_flags(nvec, status, true);
596 case 3: /* EC does a block read, we transmit data */
597 if (status & END_TRANS) {
598 nvec_tx_completed(nvec);
599 } else if ((status & RNW) == 0 || (status & RCVD)) {
600 nvec_invalid_flags(nvec, status, true);
601 } else if (nvec->tx && nvec->tx->pos < nvec->tx->size) {
602 to_send = nvec->tx->data[nvec->tx->pos++];
604 dev_err(nvec->dev, "tx buffer underflow on %p (%u > %u)\n",
606 (uint) (nvec->tx ? nvec->tx->pos : 0),
607 (uint) (nvec->tx ? nvec->tx->size : 0));
611 case 4: /* EC does some write, we read the data */
612 if ((status & (END_TRANS | RNW)) == END_TRANS)
613 nvec_rx_completed(nvec);
614 else if (status & (RNW | RCVD))
615 nvec_invalid_flags(nvec, status, true);
616 else if (nvec->rx && nvec->rx->pos < NVEC_MSG_SIZE)
617 nvec->rx->data[nvec->rx->pos++] = received;
620 "RX buffer overflow on %p: "
621 "Trying to write byte %u of %u\n",
622 nvec->rx, nvec->rx->pos, NVEC_MSG_SIZE);
628 /* If we are told that a new transfer starts, verify it */
629 if ((status & (RCVD | RNW)) == RCVD) {
630 if (received != nvec->i2c_addr)
632 "received address 0x%02x, expected 0x%02x\n",
633 received, nvec->i2c_addr);
637 /* Send data if requested, but not on end of transmission */
638 if ((status & (RNW | END_TRANS)) == RNW)
639 writel(to_send, nvec->base + I2C_SL_RCVD);
641 /* If we have send the first byte */
642 if (status == (I2C_SL_IRQ | RNW | RCVD))
643 nvec_gpio_set_value(nvec, 1);
646 "Handled: %s 0x%02x, %s 0x%02x in state %u [%s%s%s]\n",
647 (status & RNW) == 0 ? "received" : "R=",
649 (status & (RNW | END_TRANS)) ? "sent" : "S=",
652 status & END_TRANS ? " END_TRANS" : "",
653 status & RCVD ? " RCVD" : "",
654 status & RNW ? " RNW" : "");
659 static void tegra_init_i2c_slave(struct nvec_chip *nvec)
663 clk_enable(nvec->i2c_clk);
665 tegra_periph_reset_assert(nvec->i2c_clk);
667 tegra_periph_reset_deassert(nvec->i2c_clk);
669 val = I2C_CNFG_NEW_MASTER_SFM | I2C_CNFG_PACKET_MODE_EN |
670 (0x2 << I2C_CNFG_DEBOUNCE_CNT_SHIFT);
671 writel(val, nvec->base + I2C_CNFG);
673 clk_set_rate(nvec->i2c_clk, 8 * 80000);
675 writel(I2C_SL_NEWL, nvec->base + I2C_SL_CNFG);
676 writel(0x1E, nvec->base + I2C_SL_DELAY_COUNT);
678 writel(nvec->i2c_addr>>1, nvec->base + I2C_SL_ADDR1);
679 writel(0, nvec->base + I2C_SL_ADDR2);
681 enable_irq(nvec->irq);
683 clk_disable(nvec->i2c_clk);
686 static void nvec_disable_i2c_slave(struct nvec_chip *nvec)
688 disable_irq(nvec->irq);
689 writel(I2C_SL_NEWL | I2C_SL_NACK, nvec->base + I2C_SL_CNFG);
690 clk_disable(nvec->i2c_clk);
693 static void nvec_power_off(void)
695 nvec_write_async(nvec_power_handle, EC_DISABLE_EVENT_REPORTING, 3);
696 nvec_write_async(nvec_power_handle, "\x04\x01", 2);
699 static int __devinit tegra_nvec_probe(struct platform_device *pdev)
703 struct nvec_platform_data *pdata = pdev->dev.platform_data;
704 struct nvec_chip *nvec;
705 struct nvec_msg *msg;
706 struct resource *res;
707 struct resource *iomem;
710 nvec = kzalloc(sizeof(struct nvec_chip), GFP_KERNEL);
712 dev_err(&pdev->dev, "failed to reserve memory\n");
715 platform_set_drvdata(pdev, nvec);
716 nvec->dev = &pdev->dev;
717 nvec->gpio = pdata->gpio;
718 nvec->i2c_addr = pdata->i2c_addr;
720 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
722 dev_err(&pdev->dev, "no mem resource?\n");
726 iomem = request_mem_region(res->start, resource_size(res), pdev->name);
728 dev_err(&pdev->dev, "I2C region already claimed\n");
732 base = ioremap(iomem->start, resource_size(iomem));
734 dev_err(&pdev->dev, "Can't ioremap I2C region\n");
738 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
740 dev_err(&pdev->dev, "no irq resource?\n");
745 i2c_clk = clk_get_sys("tegra-i2c.2", NULL);
746 if (IS_ERR(i2c_clk)) {
747 dev_err(nvec->dev, "failed to get controller clock\n");
752 nvec->irq = res->start;
753 nvec->i2c_clk = i2c_clk;
754 nvec->rx = &nvec->msg_pool[0];
756 /* Set the gpio to low when we've got something to say */
757 err = gpio_request(nvec->gpio, "nvec gpio");
759 dev_err(nvec->dev, "couldn't request gpio\n");
761 ATOMIC_INIT_NOTIFIER_HEAD(&nvec->notifier_list);
763 init_completion(&nvec->sync_write);
764 init_completion(&nvec->ec_transfer);
765 mutex_init(&nvec->sync_write_mutex);
766 spin_lock_init(&nvec->tx_lock);
767 spin_lock_init(&nvec->rx_lock);
768 INIT_LIST_HEAD(&nvec->rx_data);
769 INIT_LIST_HEAD(&nvec->tx_data);
770 INIT_WORK(&nvec->rx_work, nvec_dispatch);
771 INIT_WORK(&nvec->tx_work, nvec_request_master);
772 nvec->wq = alloc_workqueue("nvec", WQ_NON_REENTRANT, 2);
774 err = request_irq(nvec->irq, nvec_interrupt, 0, "nvec", nvec);
776 dev_err(nvec->dev, "couldn't request irq\n");
779 disable_irq(nvec->irq);
781 tegra_init_i2c_slave(nvec);
785 gpio_direction_output(nvec->gpio, 1);
786 gpio_set_value(nvec->gpio, 1);
788 /* enable event reporting */
789 nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING,
790 sizeof(EC_ENABLE_EVENT_REPORTING));
792 nvec->nvec_status_notifier.notifier_call = nvec_status_notifier;
793 nvec_register_notifier(nvec, &nvec->nvec_status_notifier, 0);
795 nvec_power_handle = nvec;
796 pm_power_off = nvec_power_off;
798 /* Get Firmware Version */
799 msg = nvec_write_sync(nvec, EC_GET_FIRMWARE_VERSION,
800 sizeof(EC_GET_FIRMWARE_VERSION));
803 dev_warn(nvec->dev, "ec firmware version %02x.%02x.%02x / %02x\n",
804 msg->data[4], msg->data[5], msg->data[6], msg->data[7]);
806 nvec_msg_free(nvec, msg);
809 ret = mfd_add_devices(nvec->dev, -1, nvec_devices,
810 ARRAY_SIZE(nvec_devices), base, 0);
812 dev_err(nvec->dev, "error adding subdevices\n");
814 /* unmute speakers? */
815 nvec_write_async(nvec, "\x0d\x10\x59\x95", 4);
817 /* enable lid switch event */
818 nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x02\x00", 7);
820 /* enable power button event */
821 nvec_write_async(nvec, "\x01\x01\x01\x00\x00\x80\x00", 7);
832 static int __devexit tegra_nvec_remove(struct platform_device *pdev)
834 struct nvec_chip *nvec = platform_get_drvdata(pdev);
836 nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3);
837 mfd_remove_devices(nvec->dev);
838 free_irq(nvec->irq, &nvec_interrupt);
840 gpio_free(nvec->gpio);
841 destroy_workqueue(nvec->wq);
849 static int tegra_nvec_suspend(struct platform_device *pdev, pm_message_t state)
851 struct nvec_chip *nvec = platform_get_drvdata(pdev);
853 dev_dbg(nvec->dev, "suspending\n");
854 nvec_write_async(nvec, EC_DISABLE_EVENT_REPORTING, 3);
855 nvec_write_async(nvec, "\x04\x02", 2);
856 nvec_disable_i2c_slave(nvec);
861 static int tegra_nvec_resume(struct platform_device *pdev)
863 struct nvec_chip *nvec = platform_get_drvdata(pdev);
865 dev_dbg(nvec->dev, "resuming\n");
866 tegra_init_i2c_slave(nvec);
867 nvec_write_async(nvec, EC_ENABLE_EVENT_REPORTING, 3);
873 #define tegra_nvec_suspend NULL
874 #define tegra_nvec_resume NULL
877 static struct platform_driver nvec_device_driver = {
878 .probe = tegra_nvec_probe,
879 .remove = __devexit_p(tegra_nvec_remove),
880 .suspend = tegra_nvec_suspend,
881 .resume = tegra_nvec_resume,
884 .owner = THIS_MODULE,
888 static int __init tegra_nvec_init(void)
890 return platform_driver_register(&nvec_device_driver);
893 module_init(tegra_nvec_init);
895 MODULE_ALIAS("platform:nvec");
896 MODULE_DESCRIPTION("NVIDIA compliant embedded controller interface");
897 MODULE_AUTHOR("Marc Dietrich <marvin24@gmx.de>");
898 MODULE_LICENSE("GPL");