mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-11-26 02:30:53 +07:00
55827f4aa6
There is simply no reason to be manually setting the private driver data to NULL in the remove/fail to probe cases. This is just extra cruft code that can be removed. A few notes: * Nothing relies on drvdata being set to NULL. * The __device_release_driver() function eventually calls dev_set_drvdata(dev, NULL) anyway, so there's no need to do it twice. * I verified that there were no cases where xxx_get_drvdata() was being called in these drivers and checking for / relying on the NULL return value. This could be cleaned up kernel-wide but for now just take the baby step and remove from the i2c subsystem. Reported-by: Wolfram Sang <wsa@the-dreams.de> Reported-by: Stephen Warren <swarren@wwwdotorg.org> Signed-off-by: Doug Anderson <dianders@chromium.org> Reviewed-by: Jean Delvare <khali@linux-fr.org> Acked-by: Peter Korsgaard <jacmet@sunsite.dk> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Marek Vasut <marex@denx.de> Signed-off-by: Wolfram Sang <wolfram@the-dreams.de>
164 lines
3.6 KiB
C
164 lines
3.6 KiB
C
/*
|
|
* i2c-versatile.c
|
|
*
|
|
* Copyright (C) 2006 ARM Ltd.
|
|
* written by Russell King, Deep Blue Solutions Ltd.
|
|
*
|
|
* 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.
|
|
*/
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/i2c.h>
|
|
#include <linux/i2c-algo-bit.h>
|
|
#include <linux/init.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/io.h>
|
|
#include <linux/of_i2c.h>
|
|
|
|
#define I2C_CONTROL 0x00
|
|
#define I2C_CONTROLS 0x00
|
|
#define I2C_CONTROLC 0x04
|
|
#define SCL (1 << 0)
|
|
#define SDA (1 << 1)
|
|
|
|
struct i2c_versatile {
|
|
struct i2c_adapter adap;
|
|
struct i2c_algo_bit_data algo;
|
|
void __iomem *base;
|
|
};
|
|
|
|
static void i2c_versatile_setsda(void *data, int state)
|
|
{
|
|
struct i2c_versatile *i2c = data;
|
|
|
|
writel(SDA, i2c->base + (state ? I2C_CONTROLS : I2C_CONTROLC));
|
|
}
|
|
|
|
static void i2c_versatile_setscl(void *data, int state)
|
|
{
|
|
struct i2c_versatile *i2c = data;
|
|
|
|
writel(SCL, i2c->base + (state ? I2C_CONTROLS : I2C_CONTROLC));
|
|
}
|
|
|
|
static int i2c_versatile_getsda(void *data)
|
|
{
|
|
struct i2c_versatile *i2c = data;
|
|
return !!(readl(i2c->base + I2C_CONTROL) & SDA);
|
|
}
|
|
|
|
static int i2c_versatile_getscl(void *data)
|
|
{
|
|
struct i2c_versatile *i2c = data;
|
|
return !!(readl(i2c->base + I2C_CONTROL) & SCL);
|
|
}
|
|
|
|
static struct i2c_algo_bit_data i2c_versatile_algo = {
|
|
.setsda = i2c_versatile_setsda,
|
|
.setscl = i2c_versatile_setscl,
|
|
.getsda = i2c_versatile_getsda,
|
|
.getscl = i2c_versatile_getscl,
|
|
.udelay = 30,
|
|
.timeout = HZ,
|
|
};
|
|
|
|
static int i2c_versatile_probe(struct platform_device *dev)
|
|
{
|
|
struct i2c_versatile *i2c;
|
|
struct resource *r;
|
|
int ret;
|
|
|
|
r = platform_get_resource(dev, IORESOURCE_MEM, 0);
|
|
if (!r) {
|
|
ret = -EINVAL;
|
|
goto err_out;
|
|
}
|
|
|
|
if (!request_mem_region(r->start, resource_size(r), "versatile-i2c")) {
|
|
ret = -EBUSY;
|
|
goto err_out;
|
|
}
|
|
|
|
i2c = kzalloc(sizeof(struct i2c_versatile), GFP_KERNEL);
|
|
if (!i2c) {
|
|
ret = -ENOMEM;
|
|
goto err_release;
|
|
}
|
|
|
|
i2c->base = ioremap(r->start, resource_size(r));
|
|
if (!i2c->base) {
|
|
ret = -ENOMEM;
|
|
goto err_free;
|
|
}
|
|
|
|
writel(SCL | SDA, i2c->base + I2C_CONTROLS);
|
|
|
|
i2c->adap.owner = THIS_MODULE;
|
|
strlcpy(i2c->adap.name, "Versatile I2C adapter", sizeof(i2c->adap.name));
|
|
i2c->adap.algo_data = &i2c->algo;
|
|
i2c->adap.dev.parent = &dev->dev;
|
|
i2c->adap.dev.of_node = dev->dev.of_node;
|
|
i2c->algo = i2c_versatile_algo;
|
|
i2c->algo.data = i2c;
|
|
|
|
i2c->adap.nr = dev->id;
|
|
ret = i2c_bit_add_numbered_bus(&i2c->adap);
|
|
if (ret >= 0) {
|
|
platform_set_drvdata(dev, i2c);
|
|
of_i2c_register_devices(&i2c->adap);
|
|
return 0;
|
|
}
|
|
|
|
iounmap(i2c->base);
|
|
err_free:
|
|
kfree(i2c);
|
|
err_release:
|
|
release_mem_region(r->start, resource_size(r));
|
|
err_out:
|
|
return ret;
|
|
}
|
|
|
|
static int i2c_versatile_remove(struct platform_device *dev)
|
|
{
|
|
struct i2c_versatile *i2c = platform_get_drvdata(dev);
|
|
|
|
i2c_del_adapter(&i2c->adap);
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id i2c_versatile_match[] = {
|
|
{ .compatible = "arm,versatile-i2c", },
|
|
{},
|
|
};
|
|
MODULE_DEVICE_TABLE(of, i2c_versatile_match);
|
|
|
|
static struct platform_driver i2c_versatile_driver = {
|
|
.probe = i2c_versatile_probe,
|
|
.remove = i2c_versatile_remove,
|
|
.driver = {
|
|
.name = "versatile-i2c",
|
|
.owner = THIS_MODULE,
|
|
.of_match_table = i2c_versatile_match,
|
|
},
|
|
};
|
|
|
|
static int __init i2c_versatile_init(void)
|
|
{
|
|
return platform_driver_register(&i2c_versatile_driver);
|
|
}
|
|
|
|
static void __exit i2c_versatile_exit(void)
|
|
{
|
|
platform_driver_unregister(&i2c_versatile_driver);
|
|
}
|
|
|
|
subsys_initcall(i2c_versatile_init);
|
|
module_exit(i2c_versatile_exit);
|
|
|
|
MODULE_DESCRIPTION("ARM Versatile I2C bus driver");
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_ALIAS("platform:versatile-i2c");
|