aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorPhilippe Rétornaz <philippe.retornaz@epfl.ch>2012-05-29 05:06:29 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2012-07-08 18:16:25 -0400
commitada72d0a9308105b535c8fc53ba5b33e9f076a1a (patch)
tree824a2842a5b7787c1cb0bfd66f761307d235254b /drivers/mfd
parent44716ec2f423da1965d444cd349b14b994998299 (diff)
mfd: mc13xxx workaround SPI hardware bug on i.Mx
The MC13xxx PMIC is mainly used on i.Mx SoC. On those SoC the SPI hardware will deassert CS line as soon as the SPI FIFO is empty. The MC13xxx hardware is very sensitive to CS line change as it corrupts the transfer if CS is deasserted in the middle of a register read or write. It is not possible to use the CS line as a GPIO on some SoC, so we need to workaround this by implementing a single SPI transfer to access the PMIC. Reviewed-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Acked-by: Marc Reilly <marc@cpdesign.com.au> Signed-off-by: Philippe Rétornaz <philippe.retornaz@epfl.ch> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/mc13xxx-spi.c65
1 files changed, 64 insertions, 1 deletions
diff --git a/drivers/mfd/mc13xxx-spi.c b/drivers/mfd/mc13xxx-spi.c
index 5d1969f67d82..03df422feb76 100644
--- a/drivers/mfd/mc13xxx-spi.c
+++ b/drivers/mfd/mc13xxx-spi.c
@@ -54,6 +54,67 @@ static struct regmap_config mc13xxx_regmap_spi_config = {
54 .max_register = MC13XXX_NUMREGS, 54 .max_register = MC13XXX_NUMREGS,
55 55
56 .cache_type = REGCACHE_NONE, 56 .cache_type = REGCACHE_NONE,
57 .use_single_rw = 1,
58};
59
60static int mc13xxx_spi_read(void *context, const void *reg, size_t reg_size,
61 void *val, size_t val_size)
62{
63 unsigned char w[4] = { *((unsigned char *) reg), 0, 0, 0};
64 unsigned char r[4];
65 unsigned char *p = val;
66 struct device *dev = context;
67 struct spi_device *spi = to_spi_device(dev);
68 struct spi_transfer t = {
69 .tx_buf = w,
70 .rx_buf = r,
71 .len = 4,
72 };
73
74 struct spi_message m;
75 int ret;
76
77 if (val_size != 3 || reg_size != 1)
78 return -ENOTSUPP;
79
80 spi_message_init(&m);
81 spi_message_add_tail(&t, &m);
82 ret = spi_sync(spi, &m);
83
84 memcpy(p, &r[1], 3);
85
86 return ret;
87}
88
89static int mc13xxx_spi_write(void *context, const void *data, size_t count)
90{
91 struct device *dev = context;
92 struct spi_device *spi = to_spi_device(dev);
93
94 if (count != 4)
95 return -ENOTSUPP;
96
97 return spi_write(spi, data, count);
98}
99
100/*
101 * We cannot use regmap-spi generic bus implementation here.
102 * The MC13783 chip will get corrupted if CS signal is deasserted
103 * and on i.Mx31 SoC (the target SoC for MC13783 PMIC) the SPI controller
104 * has the following errata (DSPhl22960):
105 * "The CSPI negates SS when the FIFO becomes empty with
106 * SSCTL= 0. Software cannot guarantee that the FIFO will not
107 * drain because of higher priority interrupts and the
108 * non-realtime characteristics of the operating system. As a
109 * result, the SS will negate before all of the data has been
110 * transferred to/from the peripheral."
111 * We workaround this by accessing the SPI controller with a
112 * single transfert.
113 */
114
115static struct regmap_bus regmap_mc13xxx_bus = {
116 .write = mc13xxx_spi_write,
117 .read = mc13xxx_spi_read,
57}; 118};
58 119
59static int mc13xxx_spi_probe(struct spi_device *spi) 120static int mc13xxx_spi_probe(struct spi_device *spi)
@@ -78,7 +139,9 @@ static int mc13xxx_spi_probe(struct spi_device *spi)
78 mc13xxx->dev = &spi->dev; 139 mc13xxx->dev = &spi->dev;
79 mutex_init(&mc13xxx->lock); 140 mutex_init(&mc13xxx->lock);
80 141
81 mc13xxx->regmap = regmap_init_spi(spi, &mc13xxx_regmap_spi_config); 142 mc13xxx->regmap = regmap_init(&spi->dev, &regmap_mc13xxx_bus, &spi->dev,
143 &mc13xxx_regmap_spi_config);
144
82 if (IS_ERR(mc13xxx->regmap)) { 145 if (IS_ERR(mc13xxx->regmap)) {
83 ret = PTR_ERR(mc13xxx->regmap); 146 ret = PTR_ERR(mc13xxx->regmap);
84 dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n", 147 dev_err(mc13xxx->dev, "Failed to initialize register map: %d\n",