Input: ad7879 - convert to use regmap
Dmitry Torokhov
maintainerPATCH 1/3 Input: ad7879 - convert to use regmap
Instead of rolling our own infrastructure to provide uniform access to I2C and SPI buses, let's switch to using regmap.
---
Michael,
I am a bit (actually a lot) confused how this driver was working with SPI and Blackfin, which is, as far as I understand, little-endian, because from my reading of the spec the data on wire is big-endian. If this is not correct we need to change spi regmap config to be:
static const struct regmap_config ad7879_spi_regmap_config = {
.reg_bits = 16,
.val_bits = 16,
.max_register = 15,
.read_flag_mask = AD7879_CMD_MAGIC | AD7879_CMD_READ,
.write_flag_mask = AD7879_CMD_MAGIC,
.reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
.val_format_endian_default = REGMAP_ENDIAN_LITTLE,
};Also, the original ad7879_spi_xfer was funky to tell the least. We allocated n+2 spi_transfer structures, then smashed the beginning of the first one with u16 command, then basically "restored" it???
Anyway, if you could try it out (and fix ;) ), that would be great.
Thanks.
drivers/input/touchscreen/ad7879-i2c.c | 50 ++++----------- drivers/input/touchscreen/ad7879-spi.c | 112 ++++++--------------------------- drivers/input/touchscreen/ad7879.c | 46 +++++++++----- drivers/input/touchscreen/ad7879.h | 12 +--- 4 files changed, 63 insertions(+), 157 deletions(-)
drivers/input/touchscreen/ad7879-i2c.c +12 -38
@@ -12,53 +12,23 @@#include <linux/types.h> #include <linux/of.h> #include <linux/pm.h> +#include <linux/regmap.h> #include "ad7879.h" #define AD7879_DEVID 0x79/* AD7879-1/AD7889-1 */ -/* All registers are word-sized. -* AD7879 uses a high-byte first convention. -*/ -static int ad7879_i2c_read (struct device *dev,u8 reg) -{ -struct i2c_client *client =to_i2c_client (dev); - -return i2c_smbus_read_word_swapped (client, reg); -} - -static int ad7879_i2c_multi_read (struct device *dev, -u8 first_reg,u8 count,u16 *buf) -{ -struct i2c_client *client =to_i2c_client (dev); -u8 idx; - -i2c_smbus_read_i2c_block_data (client, first_reg, count *2 , (u8 *)buf); - -for (idx =0 ; idx < count; ++idx) - buf[idx] =swab16 (buf[idx]); - -return 0 ; -} - -static int ad7879_i2c_write (struct device *dev,u8 reg,u16 val) -{ -struct i2c_client *client =to_i2c_client (dev); - -return i2c_smbus_write_word_swapped (client, reg, val); -} - -static const struct ad7879_bus_ops ad7879_i2c_bus_ops = { - .bustype =BUS_I2C , - .read = ad7879_i2c_read, - .multi_read = ad7879_i2c_multi_read, - .write = ad7879_i2c_write, +static const struct regmap_config ad7879_i2c_regmap_config = { + .reg_bits =8 , + .val_bits =16 , + .max_register =15 , };static int ad7879_i2c_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct ad7879 *ts; +struct regmap *regmap;if (!i2c_check_functionality (client->adapter,I2C_FUNC_SMBUS_WORD_DATA )) {
@@ -66,8 +36,12 @@ static int ad7879_i2c_probe(struct i2c_client *client,return -EIO ; } - ts =ad7879_probe (&client->dev,AD7879_DEVID , client->irq, - &ad7879_i2c_bus_ops); + regmap =devm_regmap_init_i2c (client, &ad7879_i2c_regmap_config); +if (IS_ERR (regmap)) +return PTR_ERR (regmap); + + ts =ad7879_probe (&client->dev, regmap, client->irq, +BUS_I2C ,AD7879_DEVID );if (IS_ERR (ts))return PTR_ERR (ts);
drivers/input/touchscreen/ad7879-spi.c +18 -94
138 lines not on this page · raw message
drivers/input/touchscreen/ad7879.c +30 -16
103 lines not on this page · raw message
drivers/input/touchscreen/ad7879.h +3 -9
@@ -13,18 +13,12 @@struct ad7879 ;struct device ; - -struct ad7879_bus_ops { -u16 bustype; -int (*read)(struct device *dev,u8 reg); -int (*multi_read)(struct device *dev,u8 first_reg,u8 count,u16 *buf); -int (*write)(struct device *dev,u8 reg,u16 val); -}; +struct regmap ;extern const struct dev_pm_ops ad7879_pm_ops; -struct ad7879 *ad7879_probe (struct device *dev,u8 devid,unsigned irq, -const struct ad7879_bus_ops *bops); +struct ad7879 *ad7879_probe (struct device *dev,struct regmap *regmap, +int irq,u16 bustype,u8 devid);void ad7879_remove (struct ad7879 *);#endif
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 2/3 Input: ad7879 - use more devm interfaces
gpiochip_add now has a managed version, and we can remove sysfs attribute group via devm_add_action_or_reset (at least until we have devm version of sysfs_crreate_group). This allows us to get rid of ad7879_remove().
--- drivers/input/touchscreen/ad7879-i2c.c | 12 ------- drivers/input/touchscreen/ad7879-spi.c | 10 ------ drivers/input/touchscreen/ad7879.c | 60 ++++++++++++---------------------- drivers/input/touchscreen/ad7879.h | 1 - 4 files changed, 21 insertions(+), 62 deletions(-)
drivers/input/touchscreen/ad7879-i2c.c +0 -12
@@ -45,17 +45,6 @@ static int ad7879_i2c_probe(struct i2c_client *client,if (IS_ERR (ts))return PTR_ERR (ts); -i2c_set_clientdata (client, ts); - -return 0 ; -} - -static int ad7879_i2c_remove (struct i2c_client *client) -{ -struct ad7879 *ts =i2c_get_clientdata (client); - -ad7879_remove (ts); -return 0 ; }
@@ -81,7 +70,6 @@ static struct i2c_driver ad7879_i2c_driver = { .of_match_table = of_match_ptr(ad7879_i2c_dt_ids), }, .probe = ad7879_i2c_probe, - .remove = ad7879_i2c_remove, .id_table = ad7879_id, };
drivers/input/touchscreen/ad7879-spi.c +0 -10
@@ -62,15 +62,6 @@ static int ad7879_spi_probe(struct spi_device *spi)return 0 ; } -static int ad7879_spi_remove (struct spi_device *spi) -{ -struct ad7879 *ts =spi_get_drvdata (spi); - -ad7879_remove (ts); - -return 0 ; -} -#ifdef CONFIG_OF static const struct of_device_id ad7879_spi_dt_ids[] = { { .compatible = "adi,ad7879", },
@@ -86,7 +77,6 @@ static struct spi_driver ad7879_spi_driver = { .of_match_table = of_match_ptr(ad7879_spi_dt_ids), }, .probe = ad7879_spi_probe, - .remove = ad7879_spi_remove, };module_spi_driver (ad7879_spi_driver);
drivers/input/touchscreen/ad7879.c +21 -39
102 lines not on this page · raw message
drivers/input/touchscreen/ad7879.h +0 -1
@@ -19,6 +19,5 @@ extern const struct dev_pm_ops ad7879_pm_ops;struct ad7879 *ad7879_probe (struct device *dev,struct regmap *regmap,int irq,u16 bustype,u8 devid); -void ad7879_remove (struct ad7879 *);#endif
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Dmitry Torokhov
maintainerPATCH 3/3 Input: ad7879 - allow exporting AUX/VBAT/GPIO pin via device property
In reply to Dmitry TorokhovUp until now only platforms using legacy platform data were able to switch AUX/VBAT/GPIO pin in GPIO mode and use it as regular GPIO line. Let's allow platforms using generic device properties to do the same.
--- .../devicetree/bindings/input/touchscreen/ad7879.txt | 1 + drivers/input/touchscreen/ad7879.c | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/input/touchscreen/ad7879.txt +1 -0
@@ -35,6 +35,7 @@ Optional properties: - adi,conversion-interval: : 0 : convert one time only 1-255: 515us + val * 35us (up to 9.440ms) This property has to be a '/bits/ 8' value +- gpio-controller : Switch AUX/VBAT/GPIO pin to GPIO mode Example:
drivers/input/touchscreen/ad7879.c +13 -2
@@ -454,17 +454,28 @@ static void ad7879_gpio_set_value(struct gpio_chip *chip,static int ad7879_gpio_add (struct ad7879 *ts,const struct ad7879_platform_data *pdata) { +bool gpio_export; +int gpio_base;int ret =0 ; +if (pdata) { + gpio_export = pdata->gpio_export; + gpio_base = pdata->gpio_base; + }else { + gpio_export =device_property_read_bool (ts->dev, +"gpio-controller" ); + gpio_base =-1 ; + } +mutex_init (&ts->mutex); -if (pdata && pdata->gpio_export) { +if (gpio_export) { ts->gc.direction_input = ad7879_gpio_direction_input; ts->gc.direction_output = ad7879_gpio_direction_output; ts->gc.get = ad7879_gpio_get_value; ts->gc.set = ad7879_gpio_set_value; ts->gc.can_sleep =1 ; - ts->gc.base = pdata->gpio_base; + ts->gc.base = gpio_base; ts->gc.ngpio =1 ; ts->gc.label ="AD7879-GPIO" ; ts->gc.owner =THIS_MODULE ;
Signature · 1 line
2.11.0.483.g087da7b7c-goog
Michael Hennerich
maintainerQuoted 23 lines · Dmitry Torokhov
Instead of rolling our own infrastructure to provide uniform access to I2C and SPI buses, let's switch to using regmap.
Signed-off-by Dmitry Torokhov <[email protected]>---
Michael,
I am a bit (actually a lot) confused how this driver was working with SPI and Blackfin, which is, as far as I understand, little-endian, because from my reading of the spec the data on wire is big-endian. If this is not correct we need to change spi regmap config to be:
static const struct regmap_config ad7879_spi_regmap_config = { .reg_bits = 16, .val_bits = 16, .max_register = 15, .read_flag_mask = AD7879_CMD_MAGIC | AD7879_CMD_READ, .write_flag_mask = AD7879_CMD_MAGIC, .reg_format_endian_default = REGMAP_ENDIAN_LITTLE, .val_format_endian_default = REGMAP_ENDIAN_LITTLE, };
Quoted 5 lines
Also, the original
ad7879_spi_xferwas funky to tell the least. We allocated n+2spi_transferstructures, then smashed the beginning of the first one with u16 command, then basically "restored" it???Anyway, if you could try it out (and fix ;) ), that would be great.
Hi Dimitry,
Thanks for doing this.
Overall looks great, but i definitely need to test this. Your right this xfer functions looks awkward. I'll review and get back to you.
Signature · 7 lines
Greetings, Michael -- Analog Devices GmbH Otl-Aicher Strasse 60-64 80807 München Sitz der Gesellschaft München, Registergericht München HRB 40368, Geschäftsführer: Peter Kolberg, Ali Raza Husain, Eileen Wynne