summaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorAlexander Shiyan <shc_work@mail.ru>2013-07-12 00:24:06 +0400
committerSascha Hauer <s.hauer@pengutronix.de>2013-07-15 10:19:36 +0200
commit8c1a4930e1294e41d78b01e5e59007cb2a534236 (patch)
tree14755a5182da3904e51814d066c719b9e52f8adf /drivers/mfd
parentc243873a771bacd2c9c362a0917455b17b00ebae (diff)
downloadbarebox-8c1a4930e1294e41d78b01e5e59007cb2a534236.tar.gz
barebox-8c1a4930e1294e41d78b01e5e59007cb2a534236.tar.xz
mfd: mc13xxx: Separate query_revision function for each supported IC
Signed-off-by: Alexander Shiyan <shc_work@mail.ru> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/mc13xxx.c165
1 files changed, 97 insertions, 68 deletions
diff --git a/drivers/mfd/mc13xxx.c b/drivers/mfd/mc13xxx.c
index 2be6f627a8..556f0b21a9 100644
--- a/drivers/mfd/mc13xxx.c
+++ b/drivers/mfd/mc13xxx.c
@@ -39,6 +39,10 @@ struct mc13xxx {
int (*reg_write)(struct mc13xxx*, u8, u32);
};
+struct mc13xxx_devtype {
+ int (*revision)(struct mc13xxx*);
+};
+
#define to_mc13xxx(a) container_of(a, struct mc13xxx, cdev)
static struct mc13xxx *mc_dev;
@@ -205,13 +209,37 @@ static struct file_operations mc_fops = {
.write = mc_write,
};
-struct mc13892_rev {
+static int __init mc13783_revision(struct mc13xxx *mc13xxx)
+{
+ unsigned int rev_id;
+ char revstr[5];
+ int rev;
+
+ mc13xxx_reg_read(mc13xxx, MC13XXX_REG_IDENTIFICATION, &rev_id);
+
+ if (((rev_id >> 6) & 0x7) != 0x2)
+ return -ENODEV;
+
+
+ rev = (((rev_id & 0x18) >> 3) << 4) | (rev_id & 0x7);
+ /* Ver 0.2 is actually 3.2a. Report as 3.2 */
+ if (rev == 0x02) {
+ rev = 0x32;
+ strcpy(revstr, "3.2a");
+ } else
+ sprintf(revstr, "%d.%d", rev / 0x10, rev % 10);
+
+ dev_info(mc_dev->cdev.dev, "Found MC13783 ID: 0x%06x [Rev: %s]\n",
+ rev_id, revstr);
+
+ return rev;
+}
+
+static struct __init {
u16 rev_id;
int rev;
char *revstr;
-};
-
-static struct mc13892_rev mc13892_revisions[] = {
+} mc13892_revisions[] = {
{ 0x01, MC13892_REVISION_1_0, "1.0" },
{ 0x09, MC13892_REVISION_1_1, "1.1" },
{ 0x0a, MC13892_REVISION_1_2, "1.2" },
@@ -225,66 +253,53 @@ static struct mc13892_rev mc13892_revisions[] = {
{ 0x1d, MC13892_REVISION_3_5, "3.5" },
};
-static int mc13xxx_query_revision(struct mc13xxx *mc13xxx)
+static int __init mc13892_revision(struct mc13xxx *mc13xxx)
{
unsigned int rev_id;
- char *chipname, revstr[5];
+ char revstr[5];
int rev, i;
mc13xxx_reg_read(mc13xxx, MC13XXX_REG_IDENTIFICATION, &rev_id);
- /* Determine chip type by decode ICID bits */
- switch ((rev_id >> 6) & 0x7) {
- case 2:
- chipname = "MC13783";
- rev = (((rev_id & 0x18) >> 3) << 4) | (rev_id & 0x7);
- /* Ver 0.2 is actually 3.2a. Report as 3.2 */
- if (rev == 0x02) {
- rev = 0x32;
- strcpy(revstr, "3.2a");
- } else
- sprintf(revstr, "%d.%d", rev / 0x10, rev % 10);
- break;
- case 7:
- chipname = "MC13892";
- for (i = 0; i < ARRAY_SIZE(mc13892_revisions); i++)
- if ((rev_id & 0x1f) == mc13892_revisions[i].rev_id)
- break;
-
- if (i == ARRAY_SIZE(mc13892_revisions))
- return -EINVAL;
-
- rev = mc13892_revisions[i].rev;
- strcpy(revstr, mc13892_revisions[i].revstr);
-
- if (rev == MC13892_REVISION_2_0) {
- if ((rev_id >> 9) & 0x3) {
- rev = MC13892_REVISION_2_0a;
- strcpy(revstr, "2.0a");
- }
+ if (((rev_id >> 6) & 0x7) != 0x7)
+ return -ENODEV;
+
+ for (i = 0; i < ARRAY_SIZE(mc13892_revisions); i++)
+ if ((rev_id & 0x1f) == mc13892_revisions[i].rev_id)
+ break;
+
+ if (i == ARRAY_SIZE(mc13892_revisions))
+ return -ENOSYS;
+
+ rev = mc13892_revisions[i].rev;
+ strcpy(revstr, mc13892_revisions[i].revstr);
+
+ if (rev == MC13892_REVISION_2_0) {
+ if ((rev_id >> 9) & 0x3) {
+ rev = MC13892_REVISION_2_0a;
+ strcpy(revstr, "2.0a");
}
- break;
- default:
- dev_info(mc_dev->cdev.dev, "No PMIC detected.\n");
- return -EINVAL;
}
- dev_info(mc_dev->cdev.dev, "Found %s ID: 0x%06x [Rev: %s]\n",
- chipname, rev_id, revstr);
-
- mc13xxx->revision = rev;
+ dev_info(mc_dev->cdev.dev, "Found MC13892 ID: 0x%06x [Rev: %s]\n",
+ rev_id, revstr);
return rev;
}
-static int __init mc_probe(struct device_d *dev)
+static int __init mc13xxx_probe(struct device_d *dev)
{
- int rev;
+ struct mc13xxx_devtype *devtype;
+ int ret, rev;
if (mc_dev)
return -EBUSY;
- mc_dev = xzalloc(sizeof(struct mc13xxx));
+ ret = dev_get_drvdata(dev, (unsigned long *)&devtype);
+ if (ret)
+ return ret;
+
+ mc_dev = xzalloc(sizeof(*mc_dev));
mc_dev->cdev.name = DRIVERNAME;
#ifdef CONFIG_I2C
@@ -309,47 +324,61 @@ static int __init mc_probe(struct device_d *dev)
mc_dev->cdev.dev = dev;
mc_dev->cdev.ops = &mc_fops;
- rev = mc13xxx_query_revision(mc_dev);
+ rev = devtype->revision(mc_dev);
if (rev < 0) {
+ dev_err(mc_dev->cdev.dev, "No PMIC detected.\n");
free(mc_dev);
mc_dev = NULL;
- return -EINVAL;
+ return rev;
}
+ mc_dev->revision = rev;
devfs_create(&mc_dev->cdev);
return 0;
}
-static __maybe_unused struct of_device_id mc13892_dt_ids[] = {
- {
- .compatible = "fsl,mc13892",
- }, {
- .compatible = "fsl,mc13783",
- }, {
- /* sentinel */
- }
+static struct mc13xxx_devtype mc13783_devtype = {
+ .revision = mc13783_revision,
+};
+
+static struct mc13xxx_devtype mc13892_devtype = {
+ .revision = mc13892_revision,
+};
+
+static struct platform_device_id mc13xxx_ids[] = {
+ { .name = "mc13783", .driver_data = (ulong)&mc13783_devtype, },
+ { .name = "mc13892", .driver_data = (ulong)&mc13892_devtype, },
+ { }
+};
+
+static __maybe_unused struct of_device_id mc13xxx_dt_ids[] = {
+ { .compatible = "fsl,mc13783", .data = (ulong)&mc13783_devtype, },
+ { .compatible = "fsl,mc13892", .data = (ulong)&mc13892_devtype, },
+ { }
};
#ifdef CONFIG_I2C
-static struct driver_d mc_i2c_driver = {
- .name = "mc13xxx-i2c",
- .probe = mc_probe,
- .of_compatible = DRV_OF_COMPAT(mc13892_dt_ids),
+static struct driver_d mc13xxx_i2c_driver = {
+ .name = "mc13xxx-i2c",
+ .probe = mc13xxx_probe,
+ .id_table = mc13xxx_ids,
+ .of_compatible = DRV_OF_COMPAT(mc13xxx_dt_ids),
};
-static int mc_i2c_init(void)
+static int __init mc13xxx_i2c_init(void)
{
- return i2c_driver_register(&mc_i2c_driver);
+ return i2c_driver_register(&mc13xxx_i2c_driver);
}
-device_initcall(mc_i2c_init);
+device_initcall(mc13xxx_i2c_init);
#endif
#ifdef CONFIG_SPI
-static struct driver_d mc_spi_driver = {
- .name = "mc13xxx-spi",
- .probe = mc_probe,
- .of_compatible = DRV_OF_COMPAT(mc13892_dt_ids),
+static struct driver_d mc13xxx_spi_driver = {
+ .name = "mc13xxx-spi",
+ .probe = mc13xxx_probe,
+ .id_table = mc13xxx_ids,
+ .of_compatible = DRV_OF_COMPAT(mc13xxx_dt_ids),
};
-device_spi_driver(mc_spi_driver);
+device_spi_driver(mc13xxx_spi_driver);
#endif