Commit cd0f34b0 authored by Uwe Kleine-König's avatar Uwe Kleine-König Committed by Samuel Ortiz

mfd: mc13xxx: Change probing details for mc13xxx devices

This removes auto-detection of which variant of mc13xxx is used because
mc34708 uses a different layout in the revision register that doesn't
allow differentiation any more.
Signed-off-by: default avatarUwe Kleine-König <u.kleine-koenig@pengutronix.de>
Acked-by: default avatarMarc Reilly <marc@cpdesign.com.au>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 5e53a69b
...@@ -410,62 +410,36 @@ static irqreturn_t mc13xxx_irq_thread(int irq, void *data) ...@@ -410,62 +410,36 @@ static irqreturn_t mc13xxx_irq_thread(int irq, void *data)
return IRQ_RETVAL(handled); return IRQ_RETVAL(handled);
} }
static const char *mc13xxx_chipname[] = {
[MC13XXX_ID_MC13783] = "mc13783",
[MC13XXX_ID_MC13892] = "mc13892",
};
#define maskval(reg, mask) (((reg) & (mask)) >> __ffs(mask)) #define maskval(reg, mask) (((reg) & (mask)) >> __ffs(mask))
static int mc13xxx_identify(struct mc13xxx *mc13xxx) static void mc13xxx_print_revision(struct mc13xxx *mc13xxx, u32 revision)
{ {
u32 icid; dev_info(mc13xxx->dev, "%s: rev: %d.%d, "
u32 revision; "fin: %d, fab: %d, icid: %d/%d\n",
int ret; mc13xxx->variant->name,
maskval(revision, MC13XXX_REVISION_REVFULL),
/* maskval(revision, MC13XXX_REVISION_REVMETAL),
* Get the generation ID from register 46, as apparently some older maskval(revision, MC13XXX_REVISION_FIN),
* IC revisions only have this info at this location. Newer ICs seem to maskval(revision, MC13XXX_REVISION_FAB),
* have both. maskval(revision, MC13XXX_REVISION_ICID),
*/ maskval(revision, MC13XXX_REVISION_ICIDCODE));
ret = mc13xxx_reg_read(mc13xxx, 46, &icid); }
if (ret)
return ret;
icid = (icid >> 6) & 0x7;
switch (icid) {
case 2:
mc13xxx->ictype = MC13XXX_ID_MC13783;
break;
case 7:
mc13xxx->ictype = MC13XXX_ID_MC13892;
break;
default:
mc13xxx->ictype = MC13XXX_ID_INVALID;
break;
}
if (mc13xxx->ictype == MC13XXX_ID_MC13783 || /* These are only exported for mc13xxx-i2c and mc13xxx-spi */
mc13xxx->ictype == MC13XXX_ID_MC13892) { struct mc13xxx_variant mc13xxx_variant_mc13783 = {
ret = mc13xxx_reg_read(mc13xxx, MC13XXX_REVISION, &revision); .name = "mc13783",
.print_revision = mc13xxx_print_revision,
dev_info(mc13xxx->dev, "%s: rev: %d.%d, " };
"fin: %d, fab: %d, icid: %d/%d\n", EXPORT_SYMBOL_GPL(mc13xxx_variant_mc13783);
mc13xxx_chipname[mc13xxx->ictype],
maskval(revision, MC13XXX_REVISION_REVFULL),
maskval(revision, MC13XXX_REVISION_REVMETAL),
maskval(revision, MC13XXX_REVISION_FIN),
maskval(revision, MC13XXX_REVISION_FAB),
maskval(revision, MC13XXX_REVISION_ICID),
maskval(revision, MC13XXX_REVISION_ICIDCODE));
}
return (mc13xxx->ictype == MC13XXX_ID_INVALID) ? -ENODEV : 0; struct mc13xxx_variant mc13xxx_variant_mc13892 = {
} .name = "mc13892",
.print_revision = mc13xxx_print_revision,
};
EXPORT_SYMBOL_GPL(mc13xxx_variant_mc13892);
static const char *mc13xxx_get_chipname(struct mc13xxx *mc13xxx) static const char *mc13xxx_get_chipname(struct mc13xxx *mc13xxx)
{ {
return mc13xxx_chipname[mc13xxx->ictype]; return mc13xxx->variant->name;
} }
int mc13xxx_get_flags(struct mc13xxx *mc13xxx) int mc13xxx_get_flags(struct mc13xxx *mc13xxx)
...@@ -653,13 +627,16 @@ int mc13xxx_common_init(struct mc13xxx *mc13xxx, ...@@ -653,13 +627,16 @@ int mc13xxx_common_init(struct mc13xxx *mc13xxx,
struct mc13xxx_platform_data *pdata, int irq) struct mc13xxx_platform_data *pdata, int irq)
{ {
int ret; int ret;
u32 revision;
mc13xxx_lock(mc13xxx); mc13xxx_lock(mc13xxx);
ret = mc13xxx_identify(mc13xxx); ret = mc13xxx_reg_read(mc13xxx, MC13XXX_REVISION, &revision);
if (ret) if (ret)
goto err_revision; goto err_revision;
mc13xxx->variant->print_revision(mc13xxx, revision);
/* mask all irqs */ /* mask all irqs */
ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK0, 0x00ffffff); ret = mc13xxx_reg_write(mc13xxx, MC13XXX_IRQMASK0, 0x00ffffff);
if (ret) if (ret)
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
static const struct i2c_device_id mc13xxx_i2c_device_id[] = { static const struct i2c_device_id mc13xxx_i2c_device_id[] = {
{ {
.name = "mc13892", .name = "mc13892",
.driver_data = MC13XXX_ID_MC13892, .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
}, { }, {
/* sentinel */ /* sentinel */
} }
...@@ -34,7 +34,7 @@ MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id); ...@@ -34,7 +34,7 @@ MODULE_DEVICE_TABLE(i2c, mc13xxx_i2c_device_id);
static const struct of_device_id mc13xxx_dt_ids[] = { static const struct of_device_id mc13xxx_dt_ids[] = {
{ {
.compatible = "fsl,mc13892", .compatible = "fsl,mc13892",
.data = (void *) &mc13xxx_i2c_device_id[0], .data = &mc13xxx_variant_mc13892,
}, { }, {
/* sentinel */ /* sentinel */
} }
...@@ -76,11 +76,15 @@ static int mc13xxx_i2c_probe(struct i2c_client *client, ...@@ -76,11 +76,15 @@ static int mc13xxx_i2c_probe(struct i2c_client *client,
return ret; return ret;
} }
ret = mc13xxx_common_init(mc13xxx, pdata, client->irq); if (client->dev.of_node) {
const struct of_device_id *of_id =
of_match_device(mc13xxx_dt_ids, &client->dev);
mc13xxx->variant = of_id->data;
} else {
mc13xxx->variant = (void *)id->driver_data;
}
if (ret == 0 && (id->driver_data != mc13xxx->ictype)) ret = mc13xxx_common_init(mc13xxx, pdata, client->irq);
dev_warn(mc13xxx->dev,
"device id doesn't match auto detection!\n");
return ret; return ret;
} }
......
...@@ -28,10 +28,10 @@ ...@@ -28,10 +28,10 @@
static const struct spi_device_id mc13xxx_device_id[] = { static const struct spi_device_id mc13xxx_device_id[] = {
{ {
.name = "mc13783", .name = "mc13783",
.driver_data = MC13XXX_ID_MC13783, .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13783,
}, { }, {
.name = "mc13892", .name = "mc13892",
.driver_data = MC13XXX_ID_MC13892, .driver_data = (kernel_ulong_t)&mc13xxx_variant_mc13892,
}, { }, {
/* sentinel */ /* sentinel */
} }
...@@ -39,8 +39,8 @@ static const struct spi_device_id mc13xxx_device_id[] = { ...@@ -39,8 +39,8 @@ static const struct spi_device_id mc13xxx_device_id[] = {
MODULE_DEVICE_TABLE(spi, mc13xxx_device_id); MODULE_DEVICE_TABLE(spi, mc13xxx_device_id);
static const struct of_device_id mc13xxx_dt_ids[] = { static const struct of_device_id mc13xxx_dt_ids[] = {
{ .compatible = "fsl,mc13783", .data = (void *) MC13XXX_ID_MC13783, }, { .compatible = "fsl,mc13783", .data = &mc13xxx_variant_mc13783, },
{ .compatible = "fsl,mc13892", .data = (void *) MC13XXX_ID_MC13892, }, { .compatible = "fsl,mc13892", .data = &mc13xxx_variant_mc13892, },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids); MODULE_DEVICE_TABLE(of, mc13xxx_dt_ids);
...@@ -144,19 +144,18 @@ static int mc13xxx_spi_probe(struct spi_device *spi) ...@@ -144,19 +144,18 @@ static int mc13xxx_spi_probe(struct spi_device *spi)
return ret; return ret;
} }
ret = mc13xxx_common_init(mc13xxx, pdata, spi->irq); if (spi->dev.of_node) {
const struct of_device_id *of_id =
of_match_device(mc13xxx_dt_ids, &spi->dev);
if (ret) { mc13xxx->variant = of_id->data;
dev_set_drvdata(&spi->dev, NULL);
} else { } else {
const struct spi_device_id *devid = const struct spi_device_id *id_entry = spi_get_device_id(spi);
spi_get_device_id(spi);
if (!devid || devid->driver_data != mc13xxx->ictype) mc13xxx->variant = (void *)id_entry->driver_data;
dev_warn(mc13xxx->dev,
"device id doesn't match auto detection!\n");
} }
return ret; return mc13xxx_common_init(mc13xxx, pdata, spi->irq);
} }
static int __devexit mc13xxx_spi_remove(struct spi_device *spi) static int __devexit mc13xxx_spi_remove(struct spi_device *spi)
......
...@@ -13,19 +13,24 @@ ...@@ -13,19 +13,24 @@
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/mfd/mc13xxx.h> #include <linux/mfd/mc13xxx.h>
enum mc13xxx_id { #define MC13XXX_NUMREGS 0x3f
MC13XXX_ID_MC13783,
MC13XXX_ID_MC13892, struct mc13xxx;
MC13XXX_ID_INVALID,
struct mc13xxx_variant {
const char *name;
void (*print_revision)(struct mc13xxx *mc13xxx, u32 revision);
}; };
#define MC13XXX_NUMREGS 0x3f extern struct mc13xxx_variant
mc13xxx_variant_mc13783,
mc13xxx_variant_mc13892;
struct mc13xxx { struct mc13xxx {
struct regmap *regmap; struct regmap *regmap;
struct device *dev; struct device *dev;
enum mc13xxx_id ictype; const struct mc13xxx_variant *variant;
struct mutex lock; struct mutex lock;
int irq; int irq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment