summaryrefslogtreecommitdiffstats
path: root/drivers/message/i2o/i2o_proc.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/message/i2o/i2o_proc.c')
-rw-r--r--drivers/message/i2o/i2o_proc.c97
1 files changed, 22 insertions, 75 deletions
diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
index 8001aa6bfb48..b7d87cd227a9 100644
--- a/drivers/message/i2o/i2o_proc.c
+++ b/drivers/message/i2o/i2o_proc.c
@@ -1599,98 +1599,98 @@ static int i2o_seq_show_sensors(struct seq_file *seq, void *v)
static int i2o_seq_open_hrt(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_hrt, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_hrt, PDE_DATA(inode));
};
static int i2o_seq_open_lct(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_lct, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_lct, PDE_DATA(inode));
};
static int i2o_seq_open_status(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_status, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_status, PDE_DATA(inode));
};
static int i2o_seq_open_hw(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_hw, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_hw, PDE_DATA(inode));
};
static int i2o_seq_open_ddm_table(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_ddm_table, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_ddm_table, PDE_DATA(inode));
};
static int i2o_seq_open_driver_store(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_driver_store, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_driver_store, PDE_DATA(inode));
};
static int i2o_seq_open_drivers_stored(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_drivers_stored, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_drivers_stored, PDE_DATA(inode));
};
static int i2o_seq_open_groups(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_groups, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_groups, PDE_DATA(inode));
};
static int i2o_seq_open_phys_device(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_phys_device, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_phys_device, PDE_DATA(inode));
};
static int i2o_seq_open_claimed(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_claimed, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_claimed, PDE_DATA(inode));
};
static int i2o_seq_open_users(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_users, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_users, PDE_DATA(inode));
};
static int i2o_seq_open_priv_msgs(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_priv_msgs, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_priv_msgs, PDE_DATA(inode));
};
static int i2o_seq_open_authorized_users(struct inode *inode, struct file *file)
{
return single_open(file, i2o_seq_show_authorized_users,
- PDE(inode)->data);
+ PDE_DATA(inode));
};
static int i2o_seq_open_dev_identity(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_dev_identity, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_dev_identity, PDE_DATA(inode));
};
static int i2o_seq_open_ddm_identity(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_ddm_identity, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_ddm_identity, PDE_DATA(inode));
};
static int i2o_seq_open_uinfo(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_uinfo, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_uinfo, PDE_DATA(inode));
};
static int i2o_seq_open_sgl_limits(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_sgl_limits, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_sgl_limits, PDE_DATA(inode));
};
static int i2o_seq_open_sensors(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_sensors, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_sensors, PDE_DATA(inode));
};
static int i2o_seq_open_dev_name(struct inode *inode, struct file *file)
{
- return single_open(file, i2o_seq_show_dev_name, PDE(inode)->data);
+ return single_open(file, i2o_seq_show_dev_name, PDE_DATA(inode));
};
static const struct file_operations i2o_seq_fops_lct = {
@@ -1895,25 +1895,6 @@ static int i2o_proc_create_entries(struct proc_dir_entry *dir,
}
/**
- * i2o_proc_subdir_remove - Remove child entries from a proc entry
- * @dir: proc dir entry from which the childs should be removed
- *
- * Iterate over each i2o proc entry under dir and remove it. If the child
- * also has entries, remove them too.
- */
-static void i2o_proc_subdir_remove(struct proc_dir_entry *dir)
-{
- struct proc_dir_entry *pe, *tmp;
- pe = dir->subdir;
- while (pe) {
- tmp = pe->next;
- i2o_proc_subdir_remove(pe);
- remove_proc_entry(pe->name, dir);
- pe = tmp;
- }
-};
-
-/**
* i2o_proc_device_add - Add an I2O device to the proc dir
* @dir: proc dir entry to which the device should be added
* @dev: I2O device which should be added
@@ -1932,14 +1913,12 @@ static void i2o_proc_device_add(struct proc_dir_entry *dir,
osm_debug("adding device /proc/i2o/%s/%s\n", dev->iop->name, buff);
- devdir = proc_mkdir(buff, dir);
+ devdir = proc_mkdir_data(buff, 0, dir, dev);
if (!devdir) {
osm_warn("Could not allocate procdir!\n");
return;
}
- devdir->data = dev;
-
i2o_proc_create_entries(devdir, generic_dev_entries, dev);
/* Inform core that we want updates about this device's status */
@@ -1973,12 +1952,10 @@ static int i2o_proc_iop_add(struct proc_dir_entry *dir,
osm_debug("adding IOP /proc/i2o/%s\n", c->name);
- iopdir = proc_mkdir(c->name, dir);
+ iopdir = proc_mkdir_data(c->name, 0, dir, c);
if (!iopdir)
return -1;
- iopdir->data = c;
-
i2o_proc_create_entries(iopdir, i2o_proc_generic_iop_entries, c);
list_for_each_entry(dev, &c->devices, list)
@@ -1988,31 +1965,6 @@ static int i2o_proc_iop_add(struct proc_dir_entry *dir,
}
/**
- * i2o_proc_iop_remove - Removes an I2O controller from the i2o proc tree
- * @dir: parent proc dir entry
- * @c: I2O controller which should be removed
- *
- * Iterate over each i2o proc entry and search controller c. If it is found
- * remove it from the tree.
- */
-static void i2o_proc_iop_remove(struct proc_dir_entry *dir,
- struct i2o_controller *c)
-{
- struct proc_dir_entry *pe, *tmp;
-
- pe = dir->subdir;
- while (pe) {
- tmp = pe->next;
- if (pe->data == c) {
- i2o_proc_subdir_remove(pe);
- remove_proc_entry(pe->name, dir);
- }
- osm_debug("removing IOP /proc/i2o/%s\n", c->name);
- pe = tmp;
- }
-}
-
-/**
* i2o_proc_fs_create - Create the i2o proc fs.
*
* Iterate over each I2O controller and create the entries for it.
@@ -2042,12 +1994,7 @@ static int __init i2o_proc_fs_create(void)
*/
static int __exit i2o_proc_fs_destroy(void)
{
- struct i2o_controller *c;
-
- list_for_each_entry(c, &i2o_controllers, list)
- i2o_proc_iop_remove(i2o_proc_dir_root, c);
-
- remove_proc_entry("i2o", NULL);
+ remove_proc_subtree("i2o", NULL);
return 0;
};
ref='#n442'>442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514
/*
 * Driver for ISSI IS31FL32xx family of I2C LED controllers
 *
 * Copyright 2015 Allworx Corp.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * Datasheets:
 *   http://www.issi.com/US/product-analog-fxled-driver.shtml
 *   http://www.si-en.com/product.asp?parentid=890
 */

#include <linux/device.h>
#include <linux/i2c.h>
#include <linux/kernel.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_device.h>

/* Used to indicate a device has no such register */
#define IS31FL32XX_REG_NONE 0xFF

/* Software Shutdown bit in Shutdown Register */
#define IS31FL32XX_SHUTDOWN_SSD_ENABLE  0
#define IS31FL32XX_SHUTDOWN_SSD_DISABLE BIT(0)

/* IS31FL3216 has a number of unique registers */
#define IS31FL3216_CONFIG_REG 0x00
#define IS31FL3216_LIGHTING_EFFECT_REG 0x03
#define IS31FL3216_CHANNEL_CONFIG_REG 0x04

/* Software Shutdown bit in 3216 Config Register */
#define IS31FL3216_CONFIG_SSD_ENABLE  BIT(7)
#define IS31FL3216_CONFIG_SSD_DISABLE 0

struct is31fl32xx_priv;
struct is31fl32xx_led_data {
	struct led_classdev cdev;
	u8 channel; /* 1-based, max priv->cdef->channels */
	struct is31fl32xx_priv *priv;
};

struct is31fl32xx_priv {
	const struct is31fl32xx_chipdef *cdef;
	struct i2c_client *client;
	unsigned int num_leds;
	struct is31fl32xx_led_data leds[0];
};

/**
 * struct is31fl32xx_chipdef - chip-specific attributes
 * @channels            : Number of LED channels
 * @shutdown_reg        : address of Shutdown register (optional)
 * @pwm_update_reg      : address of PWM Update register
 * @global_control_reg  : address of Global Control register (optional)
 * @reset_reg           : address of Reset register (optional)
 * @pwm_register_base   : address of first PWM register
 * @pwm_registers_reversed: : true if PWM registers count down instead of up
 * @led_control_register_base : address of first LED control register (optional)
 * @enable_bits_per_led_control_register: number of LEDs enable bits in each
 * @reset_func:         : pointer to reset function
 *
 * For all optional register addresses, the sentinel value %IS31FL32XX_REG_NONE
 * indicates that this chip has no such register.
 *
 * If non-NULL, @reset_func will be called during probing to set all
 * necessary registers to a known initialization state. This is needed
 * for chips that do not have a @reset_reg.
 *
 * @enable_bits_per_led_control_register must be >=1 if
 * @led_control_register_base != %IS31FL32XX_REG_NONE.
 */
struct is31fl32xx_chipdef {
	u8	channels;
	u8	shutdown_reg;
	u8	pwm_update_reg;
	u8	global_control_reg;
	u8	reset_reg;
	u8	pwm_register_base;
	bool	pwm_registers_reversed;
	u8	led_control_register_base;
	u8	enable_bits_per_led_control_register;
	int (*reset_func)(struct is31fl32xx_priv *priv);
	int (*sw_shutdown_func)(struct is31fl32xx_priv *priv, bool enable);
};

static const struct is31fl32xx_chipdef is31fl3236_cdef = {
	.channels				= 36,
	.shutdown_reg				= 0x00,
	.pwm_update_reg				= 0x25,
	.global_control_reg			= 0x4a,
	.reset_reg				= 0x4f,
	.pwm_register_base			= 0x01,
	.led_control_register_base		= 0x26,
	.enable_bits_per_led_control_register	= 1,
};

static const struct is31fl32xx_chipdef is31fl3235_cdef = {
	.channels				= 28,
	.shutdown_reg				= 0x00,
	.pwm_update_reg				= 0x25,
	.global_control_reg			= 0x4a,
	.reset_reg				= 0x4f,
	.pwm_register_base			= 0x05,
	.led_control_register_base		= 0x2a,
	.enable_bits_per_led_control_register	= 1,
};

static const struct is31fl32xx_chipdef is31fl3218_cdef = {
	.channels				= 18,
	.shutdown_reg				= 0x00,
	.pwm_update_reg				= 0x16,
	.global_control_reg			= IS31FL32XX_REG_NONE,
	.reset_reg				= 0x17,
	.pwm_register_base			= 0x01,
	.led_control_register_base		= 0x13,
	.enable_bits_per_led_control_register	= 6,
};

static int is31fl3216_reset(struct is31fl32xx_priv *priv);
static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv,
					bool enable);
static const struct is31fl32xx_chipdef is31fl3216_cdef = {
	.channels				= 16,
	.shutdown_reg				= IS31FL32XX_REG_NONE,
	.pwm_update_reg				= 0xB0,
	.global_control_reg			= IS31FL32XX_REG_NONE,
	.reset_reg				= IS31FL32XX_REG_NONE,
	.pwm_register_base			= 0x10,
	.pwm_registers_reversed			= true,
	.led_control_register_base		= 0x01,
	.enable_bits_per_led_control_register	= 8,
	.reset_func				= is31fl3216_reset,
	.sw_shutdown_func			= is31fl3216_software_shutdown,
};

static int is31fl32xx_write(struct is31fl32xx_priv *priv, u8 reg, u8 val)
{
	int ret;

	dev_dbg(&priv->client->dev, "writing register 0x%02X=0x%02X", reg, val);

	ret =  i2c_smbus_write_byte_data(priv->client, reg, val);
	if (ret) {
		dev_err(&priv->client->dev,
			"register write to 0x%02X failed (error %d)",
			reg, ret);
	}
	return ret;
}

/*
 * Custom reset function for IS31FL3216 because it does not have a RESET
 * register the way that the other IS31FL32xx chips do. We don't bother
 * writing the GPIO and animation registers, because the registers we
 * do write ensure those will have no effect.
 */
static int is31fl3216_reset(struct is31fl32xx_priv *priv)
{
	unsigned int i;
	int ret;

	ret = is31fl32xx_write(priv, IS31FL3216_CONFIG_REG,
			       IS31FL3216_CONFIG_SSD_ENABLE);
	if (ret)
		return ret;
	for (i = 0; i < priv->cdef->channels; i++) {
		ret = is31fl32xx_write(priv, priv->cdef->pwm_register_base+i,
				       0x00);
		if (ret)
			return ret;
	}
	ret = is31fl32xx_write(priv, priv->cdef->pwm_update_reg, 0);
	if (ret)
		return ret;
	ret = is31fl32xx_write(priv, IS31FL3216_LIGHTING_EFFECT_REG, 0x00);
	if (ret)
		return ret;
	ret = is31fl32xx_write(priv, IS31FL3216_CHANNEL_CONFIG_REG, 0x00);
	if (ret)
		return ret;

	return 0;
}

/*
 * Custom Software-Shutdown function for IS31FL3216 because it does not have
 * a SHUTDOWN register the way that the other IS31FL32xx chips do.
 * We don't bother doing a read/modify/write on the CONFIG register because
 * we only ever use a value of '0' for the other fields in that register.
 */
static int is31fl3216_software_shutdown(struct is31fl32xx_priv *priv,
					bool enable)
{
	u8 value = enable ? IS31FL3216_CONFIG_SSD_ENABLE :
			    IS31FL3216_CONFIG_SSD_DISABLE;

	return is31fl32xx_write(priv, IS31FL3216_CONFIG_REG, value);
}

/*
 * NOTE: A mutex is not needed in this function because:
 * - All referenced data is read-only after probe()
 * - The I2C core has a mutex on to protect the bus
 * - There are no read/modify/write operations
 * - Intervening operations between the write of the PWM register
 *   and the Update register are harmless.
 *
 * Example:
 *	PWM_REG_1 write 16
 *	UPDATE_REG write 0
 *	PWM_REG_2 write 128
 *	UPDATE_REG write 0
 *   vs:
 *	PWM_REG_1 write 16
 *	PWM_REG_2 write 128
 *	UPDATE_REG write 0
 *	UPDATE_REG write 0
 * are equivalent. Poking the Update register merely applies all PWM
 * register writes up to that point.
 */
static int is31fl32xx_brightness_set(struct led_classdev *led_cdev,
				     enum led_brightness brightness)
{
	const struct is31fl32xx_led_data *led_data =
		container_of(led_cdev, struct is31fl32xx_led_data, cdev);
	const struct is31fl32xx_chipdef *cdef = led_data->priv->cdef;
	u8 pwm_register_offset;
	int ret;

	dev_dbg(led_cdev->dev, "%s: %d\n", __func__, brightness);

	/* NOTE: led_data->channel is 1-based */
	if (cdef->pwm_registers_reversed)
		pwm_register_offset = cdef->channels - led_data->channel;
	else
		pwm_register_offset = led_data->channel - 1;

	ret = is31fl32xx_write(led_data->priv,
			       cdef->pwm_register_base + pwm_register_offset,
			       brightness);
	if (ret)
		return ret;

	return is31fl32xx_write(led_data->priv, cdef->pwm_update_reg, 0);
}

static int is31fl32xx_reset_regs(struct is31fl32xx_priv *priv)
{
	const struct is31fl32xx_chipdef *cdef = priv->cdef;
	int ret;

	if (cdef->reset_reg != IS31FL32XX_REG_NONE) {
		ret = is31fl32xx_write(priv, cdef->reset_reg, 0);
		if (ret)
			return ret;
	}

	if (cdef->reset_func)
		return cdef->reset_func(priv);

	return 0;
}

static int is31fl32xx_software_shutdown(struct is31fl32xx_priv *priv,
					bool enable)
{
	const struct is31fl32xx_chipdef *cdef = priv->cdef;
	int ret;

	if (cdef->shutdown_reg != IS31FL32XX_REG_NONE) {
		u8 value = enable ? IS31FL32XX_SHUTDOWN_SSD_ENABLE :
				    IS31FL32XX_SHUTDOWN_SSD_DISABLE;
		ret