diff options
author | Zhangfei Gao <zhangfei.gao@linaro.org> | 2013-01-16 22:40:15 +0800 |
---|---|---|
committer | Guodong Xu <guodong.xu@linaro.org> | 2013-02-05 07:59:21 +0800 |
commit | d5ef31e8ba0ab03c906d12d1b612a7783082851e (patch) | |
tree | bc7860cb93f0619752f66e8821e9b020ff14cb46 | |
parent | 39d0b6276ba24ed70c9a6bd7a3bc50250aa0462a (diff) |
i2c debugtopic-unit-test-i2c-dma
i2c pin is set to gpio by default.
i2c clk is disabled by default
test with charger
Signed-off-by: Zhangfei Gao <zhangfei.gao@linaro.org>
-rw-r--r-- | arch/arm/boot/dts/hi4511.dts | 8 | ||||
-rw-r--r-- | drivers/misc/Kconfig | 6 | ||||
-rw-r--r-- | drivers/misc/Makefile | 1 | ||||
-rw-r--r-- | drivers/misc/hs_i2c_test.c | 149 |
4 files changed, 164 insertions, 0 deletions
diff --git a/arch/arm/boot/dts/hi4511.dts b/arch/arm/boot/dts/hi4511.dts index ffbb646f1de1..70a5c45bd8ee 100644 --- a/arch/arm/boot/dts/hi4511.dts +++ b/arch/arm/boot/dts/hi4511.dts @@ -814,12 +814,20 @@ status = "ok"; pinctrl-names = "default"; pinctrl-0 = <&i2c0_pmx_func &i2c0_cfg_func>; + i2c_test: i2c_test@58 { + compatible = "hs,i2c_test_tpa2028"; + reg = <0x58>; + }; }; i2c1: i2c@fcb09000 { status = "ok"; pinctrl-names = "default"; pinctrl-0 = <&i2c1_pmx_func &i2c1_cfg_func>; + bq24161: charger@6b { + compatible = "hs,i2c_test_bq24161"; + reg = <0x6b>; + }; }; regulators { diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig index b151b7c1bd59..636558a78045 100644 --- a/drivers/misc/Kconfig +++ b/drivers/misc/Kconfig @@ -315,6 +315,12 @@ config ISL29003 This driver can also be built as a module. If so, the module will be called isl29003. +config HS_I2C_TEST + tristate "Hisilicon i2c test" + depends on I2C + help + Hisilicon i2c test + config ISL29020 tristate "Intersil ISL29020 ambient light sensor" depends on I2C diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile index 2129377c0de6..5dc8ef2ac8f8 100644 --- a/drivers/misc/Makefile +++ b/drivers/misc/Makefile @@ -32,6 +32,7 @@ obj-$(CONFIG_APDS9802ALS) += apds9802als.o obj-$(CONFIG_ISL29003) += isl29003.o obj-$(CONFIG_ISL29020) += isl29020.o obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o +obj-$(CONFIG_HS_I2C_TEST) += hs_i2c_test.o obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o obj-$(CONFIG_DS1682) += ds1682.o obj-$(CONFIG_TI_DAC7512) += ti_dac7512.o diff --git a/drivers/misc/hs_i2c_test.c b/drivers/misc/hs_i2c_test.c new file mode 100644 index 000000000000..39cdff8e423c --- /dev/null +++ b/drivers/misc/hs_i2c_test.c @@ -0,0 +1,149 @@ +/* + * hs_i2c_test charger driver + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include <linux/version.h> +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/param.h> +#include <linux/err.h> +#include <linux/workqueue.h> +#include <linux/sysfs.h> +#include <linux/platform_device.h> +#include <linux/power_supply.h> +#include <linux/idr.h> +#include <linux/i2c.h> +#include <linux/slab.h> + +enum hs_i2c_test_type { + BQ24161 = 0, + TPA2028, +}; + +static const struct of_device_id hs_i2c_test_of_match[] = { + { .compatible = "hs,i2c_test_bq24161", .data = BQ24161}, + { .compatible = "hs,i2c_test_tpa2028", .data = TPA2028}, + {}, +}; +MODULE_DEVICE_TABLE(of, hs_i2c_test_of_match); + +static int k3_bq24161_read_block(struct i2c_client *client, u8 *value, + u8 reg, unsigned num_bytes) +{ + struct i2c_msg msg[2]; + u8 buf = 0; + int ret = 0; + + buf = reg; + + msg[0].addr = client->addr; + msg[0].flags = 0; + msg[0].buf = &buf; + msg[0].len = 1; + + msg[1].addr = client->addr; + msg[1].flags = I2C_M_RD; + msg[1].buf = value; + msg[1].len = num_bytes; + + ret = i2c_transfer(client->adapter, msg, 2); + + /* i2c_transfer returns number of messages transferred */ + if (ret != 2) { + printk(KERN_ERR + "i2c_write failed to transfer all messages\n"); + if (ret < 0) { + return ret; + } else + return -EIO; + } else { + return 0; + } +} + +static inline int hs_i2c_get_driver_data(struct i2c_client *i2c, + const struct i2c_device_id *id) +{ +#ifdef CONFIG_OF + if (i2c->dev.of_node) { + const struct of_device_id *match; + match = of_match_node(hs_i2c_test_of_match, i2c->dev.of_node); + return (int)match->data; + } +#endif + return (int)id->driver_data; +} + + +static int hs_i2c_test_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + int ret = 0; + int type = hs_i2c_get_driver_data(client, id); + + printk("%s, client->addr=0x%x\n\n", __func__, client->addr); + printk("id->driver_data=%d\n", type); + + if (BQ24161 == type) { + u8 read_reg = 0; + printk("BQ24161\n"); + ret = k3_bq24161_read_block(client, &read_reg, 0x4, 1); + printk("read_reg=0x%x\n", read_reg); + + } else if (TPA2028 == type) { + printk("TPA2028\n"); + + } + + return ret; +} + +static int hs_i2c_test_remove(struct i2c_client *client) +{ + return 0; +} + +static const struct i2c_device_id hs_i2c_test_id_table[] = { + { "hs_i2c_test", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, hs_i2c_test_id_table); + +static struct i2c_driver hs_i2c_test_driver = { + .driver = { + .name = "hs_i2c_test", + .of_match_table = hs_i2c_test_of_match, + }, + .probe = hs_i2c_test_probe, + .remove = hs_i2c_test_remove, + .id_table = hs_i2c_test_id_table, +}; + +static int __init hs_i2c_test_init(void) +{ + return i2c_add_driver(&hs_i2c_test_driver); +} +module_init(hs_i2c_test_init); + +static void __exit hs_i2c_test_exit(void) +{ + i2c_del_driver(&hs_i2c_test_driver); +} +module_exit(hs_i2c_test_exit); + +MODULE_DESCRIPTION("hs i2c test driver"); +MODULE_LICENSE("GPL"); |