Release 4.14 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
/*
* Power Management and GPIO expander driver for MPC8349E-mITX-compatible MCU
*
* Copyright (c) 2008 MontaVista Software, Inc.
*
* Author: Anton Vorontsov <avorontsov@ru.mvista.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/device.h>
#include <linux/mutex.h>
#include <linux/i2c.h>
#include <linux/gpio/driver.h>
#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>
/*
* I don't have specifications for the MCU firmware, I found this register
* and bits positions by the trial&error method.
*/
#define MCU_REG_CTRL 0x20
#define MCU_CTRL_POFF 0x40
#define MCU_CTRL_BTN 0x80
#define MCU_NUM_GPIO 2
struct mcu {
struct mutex lock;
struct i2c_client *client;
struct gpio_chip gc;
u8 reg_ctrl;
};
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;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Fabio Baltieri | 98 | 100.00% | 1 | 100.00% |
Total | 98 | 100.00% | 1 | 100.00% |
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);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Fabio Baltieri | 67 | 100.00% | 1 | 100.00% |
Total | 67 | 100.00% | 1 | 100.00% |
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(mcu->client, MCU_REG_CTRL,
mcu->reg_ctrl | MCU_CTRL_POFF);
mutex_unlock(&mcu->lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 50 | 98.04% | 1 | 50.00% |
Fabio Baltieri | 1 | 1.96% | 1 | 50.00% |
Total | 51 | 100.00% | 2 | 100.00% |
static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
{
struct mcu *mcu = gpiochip_get_data(gc);
u8 bit = 1 << (4 + gpio);
mutex_lock(&mcu->lock);
if (val)
mcu->reg_ctrl &= ~bit;
else
mcu->reg_ctrl |= bit;
i2c_smbus_write_byte_data(mcu->client, MCU_REG_CTRL, mcu->reg_ctrl);
mutex_unlock(&mcu->lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 85 | 98.84% | 2 | 66.67% |
Linus Walleij | 1 | 1.16% | 1 | 33.33% |
Total | 86 | 100.00% | 3 | 100.00% |
static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
{
mcu_gpio_set(gc, gpio, val);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 30 | 100.00% | 1 | 100.00% |
Total | 30 | 100.00% | 1 | 100.00% |
static int mcu_gpiochip_add(struct mcu *mcu)
{
struct device_node *np;
struct gpio_chip *gc = &mcu->gc;
np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx");
if (!np)
return -ENODEV;
gc->owner = THIS_MODULE;
gc->label = kasprintf(GFP_KERNEL, "%pOF", np);
gc->can_sleep = 1;
gc->ngpio = MCU_NUM_GPIO;
gc->base = -1;
gc->set = mcu_gpio_set;
gc->direction_output = mcu_gpio_dir_out;
gc->of_node = np;
return gpiochip_add_data(gc, mcu);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 98 | 89.09% | 2 | 40.00% |
Rob Herring | 7 | 6.36% | 1 | 20.00% |
Linus Walleij | 3 | 2.73% | 1 | 20.00% |
Grant C. Likely | 2 | 1.82% | 1 | 20.00% |
Total | 110 | 100.00% | 5 | 100.00% |
static int mcu_gpiochip_remove(struct mcu *mcu)
{
kfree(mcu->gc.label);
gpiochip_remove(&mcu->gc);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 19 | 61.29% | 1 | 33.33% |
Rob Herring | 9 | 29.03% | 1 | 33.33% |
abdoulaye berthe | 3 | 9.68% | 1 | 33.33% |
Total | 31 | 100.00% | 3 | 100.00% |
static int mcu_probe(struct i2c_client *client, const struct i2c_device_id *id)
{
struct mcu *mcu;
int ret;
mcu = kzalloc(sizeof(*mcu), GFP_KERNEL);
if (!mcu)
return -ENOMEM;
mutex_init(&mcu->lock);
mcu->client = client;
i2c_set_clientdata(client, mcu);
ret = i2c_smbus_read_byte_data(mcu->client, MCU_REG_CTRL);
if (ret < 0)
goto err;
mcu->reg_ctrl = ret;
ret = mcu_gpiochip_add(mcu);
if (ret)
goto err;
/* XXX: this is potentially racy, but there is no lock for pm_power_off */
if (!pm_power_off) {
glob_mcu = mcu;
pm_power_off = mcu_power_off;
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);
return ret;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 144 | 79.56% | 1 | 33.33% |
Fabio Baltieri | 34 | 18.78% | 1 | 33.33% |
Alexander Graf | 3 | 1.66% | 1 | 33.33% |
Total | 181 | 100.00% | 3 | 100.00% |
static int 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) {
pm_power_off = NULL;
glob_mcu = NULL;
}
ret = mcu_gpiochip_remove(mcu);
if (ret)
return ret;
kfree(mcu);
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 61 | 78.21% | 1 | 33.33% |
Fabio Baltieri | 16 | 20.51% | 1 | 33.33% |
Alexander Graf | 1 | 1.28% | 1 | 33.33% |
Total | 78 | 100.00% | 3 | 100.00% |
static const struct i2c_device_id mcu_ids[] = {
{ "mcu-mpc8349emitx", },
{},
};
MODULE_DEVICE_TABLE(i2c, mcu_ids);
static const struct of_device_id mcu_of_match_table[] = {
{ .compatible = "fsl,mcu-mpc8349emitx", },
{ },
};
static struct i2c_driver mcu_driver = {
.driver = {
.name = "mcu-mpc8349emitx",
.of_match_table = mcu_of_match_table,
},
.probe = mcu_probe,
.remove = mcu_remove,
.id_table = mcu_ids,
};
module_i2c_driver(mcu_driver);
MODULE_DESCRIPTION("Power Management and GPIO expander driver for "
"MPC8349E-mITX-compatible MCU");
MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
MODULE_LICENSE("GPL");
Overall Contributors
Person | Tokens | Prop | Commits | CommitProp |
Anton Vorontsov | 633 | 67.99% | 2 | 16.67% |
Fabio Baltieri | 243 | 26.10% | 1 | 8.33% |
Grant C. Likely | 22 | 2.36% | 2 | 16.67% |
Rob Herring | 16 | 1.72% | 1 | 8.33% |
Linus Walleij | 5 | 0.54% | 1 | 8.33% |
Alexander Graf | 4 | 0.43% | 1 | 8.33% |
Tejun Heo | 3 | 0.32% | 1 | 8.33% |
abdoulaye berthe | 3 | 0.32% | 1 | 8.33% |
Wei Yongjun | 1 | 0.11% | 1 | 8.33% |
Uwe Kleine-König | 1 | 0.11% | 1 | 8.33% |
Greg Kroah-Hartman | | 0.00% | 0 | 0.00% |
Total | 931 | 100.00% | 12 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.