From 0a9c478fa8df39e89e0da142e4d78d082298133e Mon Sep 17 00:00:00 2001 From: Pallav Joshi Date: Thu, 10 May 2012 18:24:14 +0530 Subject: [PATCH] Xilinx: ARM: I2C: SI570: driver update Abstracted sysfs function hooks, created new wrapper functions and exported them so they can be called from elsehwere in the kernel. Used by xylon framebuffer driver. Signed-off-by: Davor Joja --- drivers/misc/si570.c | 59 ++++++++++++++++++++++++++++++++++++++++++----- include/linux/i2c/si570.h | 5 ++++ 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/drivers/misc/si570.c b/drivers/misc/si570.c index ffac0dfd5fa..9627da0aef3 100644 --- a/drivers/misc/si570.c +++ b/drivers/misc/si570.c @@ -76,6 +76,10 @@ struct si570_data { u64 frequency; }; + +static struct i2c_client *client_i2c; + + static int si570_get_defaults(struct i2c_client *client) { struct si570_data *data = i2c_get_clientdata(client); @@ -266,7 +270,7 @@ static int si570_reset(struct i2c_client *client, struct si570_data *data) return si570_set_frequency(client, data, data->frequency); } -static ssize_t show_frequency(struct device *dev, +static ssize_t show_frequency_attr(struct device *dev, struct device_attribute *devattr, char *buf) { @@ -276,7 +280,22 @@ static ssize_t show_frequency(struct device *dev, return sprintf(buf, "%llu\n", data->frequency); } -static ssize_t set_frequency(struct device *dev, +int get_frequency_si570(struct device *dev, unsigned long *freq) +{ + int err; + char buf[10+1]; + + show_frequency_attr(dev, NULL, buf); + + err = strict_strtoul(buf, 10, freq); + if (err) + return err; + + return 0; +} +EXPORT_SYMBOL(get_frequency_si570); + +static ssize_t set_frequency_attr(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -315,14 +334,25 @@ static ssize_t set_frequency(struct device *dev, return count; } -static ssize_t show_reset(struct device *dev, + +int set_frequency_si570(struct device *dev, unsigned long freq) +{ + char buf[10+1]; + + sprintf(buf, "%lu", freq); + + return set_frequency_attr(dev, NULL, buf, 0); +} +EXPORT_SYMBOL(set_frequency_si570); + +static ssize_t show_reset_attr(struct device *dev, struct device_attribute *devattr, char *buf) { return sprintf(buf, "%d\n", 0); } -static ssize_t set_reset(struct device *dev, +static ssize_t set_reset_attr(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { @@ -346,8 +376,23 @@ done: return count; } -static DEVICE_ATTR(frequency, S_IWUSR | S_IRUGO, show_frequency, set_frequency); -static DEVICE_ATTR(reset, S_IWUSR | S_IRUGO, show_reset, set_reset); +void reset_si570(struct device *dev, int id) +{ + char buf[4]; + + sprintf(buf, "%lu", (unsigned long)id); + set_reset_attr(dev, NULL, buf, 0); +} +EXPORT_SYMBOL(reset_si570); + +struct i2c_client *get_i2c_client_si570(void) +{ + return client_i2c; +} +EXPORT_SYMBOL(get_i2c_client_si570); + +static DEVICE_ATTR(frequency, S_IWUSR | S_IRUGO, show_frequency_attr, set_frequency_attr); +static DEVICE_ATTR(reset, S_IWUSR | S_IRUGO, show_reset_attr, set_reset_attr); static struct attribute *si570_attr[] = { &dev_attr_frequency.attr, @@ -437,6 +482,8 @@ static int si570_probe(struct i2c_client *client, pdata->initial_fout); } + client_i2c = client; + return 0; exit_free: diff --git a/include/linux/i2c/si570.h b/include/linux/i2c/si570.h index 5a7602ebeb1..3f957381d13 100644 --- a/include/linux/i2c/si570.h +++ b/include/linux/i2c/si570.h @@ -21,4 +21,9 @@ struct si570_platform_data { unsigned long initial_fout; /* Requested initial frequency */ }; +int get_frequency_si570(struct device *dev, unsigned long *freq); +int set_frequency_si570(struct device *dev, unsigned long freq); +void reset_si570(struct device *dev, int id); +struct i2c_client *get_i2c_client_si570(void); + #endif /* __LINUX_SI570_H */ -- 2.11.4.GIT