Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 274242
b: refs/heads/master
c: 6ca6ca5
h: refs/heads/master
v: v3
  • Loading branch information
Fabio Baltieri authored and Kumar Gala committed Nov 3, 2011
1 parent 4087749 commit 7bc1dc5
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 43a327b79c3945049ccf675452d2d519084c9bc6
refs/heads/master: 6ca6ca5d813845533bcaaaeb2ca59d0805a028ca
58 changes: 57 additions & 1 deletion trunk/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/slab.h>
#include <linux/kthread.h>
#include <linux/reboot.h>
#include <asm/prom.h>
#include <asm/machdep.h>

Expand All @@ -30,6 +32,7 @@
*/
#define MCU_REG_CTRL 0x20
#define MCU_CTRL_POFF 0x40
#define MCU_CTRL_BTN 0x80

#define MCU_NUM_GPIO 2

Expand All @@ -42,13 +45,55 @@ struct mcu {

static struct mcu *glob_mcu;

struct task_struct *shutdown_thread;
static int shutdown_thread_fn(void *data)
{
int ret;
struct mcu *mcu = glob_mcu;

while (!kthread_should_stop()) {
ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL);
if (ret < 0)
pr_err("MCU status reg read failed.\n");
mcu->reg_ctrl = ret;


if (mcu->reg_ctrl & MCU_CTRL_BTN) {
i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL,
mcu->reg_ctrl & ~MCU_CTRL_BTN);

ctrl_alt_del();
}

set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ);
}

return 0;
}

static ssize_t show_status(struct device *d,
struct device_attribute *attr, char *buf)
{
int ret;
struct mcu *mcu = glob_mcu;

ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL);
if (ret < 0)
return -ENODEV;
mcu->reg_ctrl = ret;

return sprintf(buf, "%02x\n", ret);
}
static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);

static void mcu_power_off(void)
{
struct mcu *mcu = glob_mcu;

pr_info("Sending power-off request to the MCU...\n");
mutex_lock(&mcu->lock);
i2c_smbus_write_byte_data(glob_mcu->client, MCU_REG_CTRL,
i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL,
mcu->reg_ctrl | MCU_CTRL_POFF);
mutex_unlock(&mcu->lock);
}
Expand Down Expand Up @@ -130,6 +175,13 @@ static int __devinit mcu_probe(struct i2c_client *client,
dev_info(&client->dev, "will provide power-off service\n");
}

if (device_create_file(&client->dev, &dev_attr_status))
dev_err(&client->dev,
"couldn't create device file for status\n");

shutdown_thread = kthread_run(shutdown_thread_fn, NULL,
"mcu-i2c-shdn");

return 0;
err:
kfree(mcu);
Expand All @@ -141,6 +193,10 @@ static int __devexit mcu_remove(struct i2c_client *client)
struct mcu *mcu = i2c_get_clientdata(client);
int ret;

kthread_stop(shutdown_thread);

device_remove_file(&client->dev, &dev_attr_status);

if (glob_mcu == mcu) {
ppc_md.power_off = NULL;
glob_mcu = NULL;
Expand Down
2 changes: 1 addition & 1 deletion trunk/arch/powerpc/platforms/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ config SIMPLE_GPIO
on-board peripherals.

config MCU_MPC8349EMITX
tristate "MPC8349E-mITX MCU driver"
bool "MPC8349E-mITX MCU driver"
depends on I2C && PPC_83xx
select GENERIC_GPIO
select ARCH_REQUIRE_GPIOLIB
Expand Down

0 comments on commit 7bc1dc5

Please sign in to comment.