diff options
author | Stephen Boyd <sboyd@codeaurora.org> | 2014-02-26 13:59:23 -0500 |
---|---|---|
committer | Lee Jones <lee.jones@linaro.org> | 2014-03-19 04:58:31 -0400 |
commit | e7b81fca7dd7cfa9f02722307e1a045f4565fec4 (patch) | |
tree | 413e0ff6d4f2d7dc29bb341ef230eee4c76e4136 /drivers/mfd/pm8921-core.c | |
parent | 559c04f6f116075a1ebead411666c7ab47dcc7fe (diff) |
mfd: pm8921: Use ssbi regmap
Use a regmap so that the pm8xxx read/write APIs can be removed
once all consumer drivers are converted.
Reviewed-by: Mark Brown <broonie@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/pm8921-core.c')
-rw-r--r-- | drivers/mfd/pm8921-core.c | 66 |
1 files changed, 38 insertions, 28 deletions
diff --git a/drivers/mfd/pm8921-core.c b/drivers/mfd/pm8921-core.c index c25e7dae150b..e9340bd6d1ab 100644 --- a/drivers/mfd/pm8921-core.c +++ b/drivers/mfd/pm8921-core.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/slab.h> | 23 | #include <linux/slab.h> |
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/ssbi.h> | 25 | #include <linux/ssbi.h> |
26 | #include <linux/regmap.h> | ||
26 | #include <linux/of_platform.h> | 27 | #include <linux/of_platform.h> |
27 | #include <linux/mfd/core.h> | 28 | #include <linux/mfd/core.h> |
28 | #include <linux/mfd/pm8xxx/core.h> | 29 | #include <linux/mfd/pm8xxx/core.h> |
@@ -57,6 +58,7 @@ | |||
57 | 58 | ||
58 | struct pm_irq_chip { | 59 | struct pm_irq_chip { |
59 | struct device *dev; | 60 | struct device *dev; |
61 | struct regmap *regmap; | ||
60 | spinlock_t pm_irq_lock; | 62 | spinlock_t pm_irq_lock; |
61 | struct irq_domain *irqdomain; | 63 | struct irq_domain *irqdomain; |
62 | unsigned int num_irqs; | 64 | unsigned int num_irqs; |
@@ -70,29 +72,19 @@ struct pm8921 { | |||
70 | struct pm_irq_chip *irq_chip; | 72 | struct pm_irq_chip *irq_chip; |
71 | }; | 73 | }; |
72 | 74 | ||
73 | static int pm8xxx_read_root_irq(const struct pm_irq_chip *chip, u8 *rp) | 75 | static int pm8xxx_read_block_irq(struct pm_irq_chip *chip, unsigned int bp, |
74 | { | 76 | unsigned int *ip) |
75 | return pm8xxx_readb(chip->dev, SSBI_REG_ADDR_IRQ_ROOT, rp); | ||
76 | } | ||
77 | |||
78 | static int pm8xxx_read_master_irq(const struct pm_irq_chip *chip, u8 m, u8 *bp) | ||
79 | { | ||
80 | return pm8xxx_readb(chip->dev, | ||
81 | SSBI_REG_ADDR_IRQ_M_STATUS1 + m, bp); | ||
82 | } | ||
83 | |||
84 | static int pm8xxx_read_block_irq(struct pm_irq_chip *chip, u8 bp, u8 *ip) | ||
85 | { | 77 | { |
86 | int rc; | 78 | int rc; |
87 | 79 | ||
88 | spin_lock(&chip->pm_irq_lock); | 80 | spin_lock(&chip->pm_irq_lock); |
89 | rc = pm8xxx_writeb(chip->dev, SSBI_REG_ADDR_IRQ_BLK_SEL, bp); | 81 | rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_BLK_SEL, bp); |
90 | if (rc) { | 82 | if (rc) { |
91 | pr_err("Failed Selecting Block %d rc=%d\n", bp, rc); | 83 | pr_err("Failed Selecting Block %d rc=%d\n", bp, rc); |
92 | goto bail; | 84 | goto bail; |
93 | } | 85 | } |
94 | 86 | ||
95 | rc = pm8xxx_readb(chip->dev, SSBI_REG_ADDR_IRQ_IT_STATUS, ip); | 87 | rc = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_IT_STATUS, ip); |
96 | if (rc) | 88 | if (rc) |
97 | pr_err("Failed Reading Status rc=%d\n", rc); | 89 | pr_err("Failed Reading Status rc=%d\n", rc); |
98 | bail: | 90 | bail: |
@@ -100,19 +92,20 @@ bail: | |||
100 | return rc; | 92 | return rc; |
101 | } | 93 | } |
102 | 94 | ||
103 | static int pm8xxx_config_irq(struct pm_irq_chip *chip, u8 bp, u8 cp) | 95 | static int |
96 | pm8xxx_config_irq(struct pm_irq_chip *chip, unsigned int bp, unsigned int cp) | ||
104 | { | 97 | { |
105 | int rc; | 98 | int rc; |
106 | 99 | ||
107 | spin_lock(&chip->pm_irq_lock); | 100 | spin_lock(&chip->pm_irq_lock); |
108 | rc = pm8xxx_writeb(chip->dev, SSBI_REG_ADDR_IRQ_BLK_SEL, bp); | 101 | rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_BLK_SEL, bp); |
109 | if (rc) { | 102 | if (rc) { |
110 | pr_err("Failed Selecting Block %d rc=%d\n", bp, rc); | 103 | pr_err("Failed Selecting Block %d rc=%d\n", bp, rc); |
111 | goto bail; | 104 | goto bail; |
112 | } | 105 | } |
113 | 106 | ||
114 | cp |= PM_IRQF_WRITE; | 107 | cp |= PM_IRQF_WRITE; |
115 | rc = pm8xxx_writeb(chip->dev, SSBI_REG_ADDR_IRQ_CONFIG, cp); | 108 | rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_CONFIG, cp); |
116 | if (rc) | 109 | if (rc) |
117 | pr_err("Failed Configuring IRQ rc=%d\n", rc); | 110 | pr_err("Failed Configuring IRQ rc=%d\n", rc); |
118 | bail: | 111 | bail: |
@@ -123,7 +116,7 @@ bail: | |||
123 | static int pm8xxx_irq_block_handler(struct pm_irq_chip *chip, int block) | 116 | static int pm8xxx_irq_block_handler(struct pm_irq_chip *chip, int block) |
124 | { | 117 | { |
125 | int pmirq, irq, i, ret = 0; | 118 | int pmirq, irq, i, ret = 0; |
126 | u8 bits; | 119 | unsigned int bits; |
127 | 120 | ||
128 | ret = pm8xxx_read_block_irq(chip, block, &bits); | 121 | ret = pm8xxx_read_block_irq(chip, block, &bits); |
129 | if (ret) { | 122 | if (ret) { |
@@ -148,10 +141,11 @@ static int pm8xxx_irq_block_handler(struct pm_irq_chip *chip, int block) | |||
148 | 141 | ||
149 | static int pm8xxx_irq_master_handler(struct pm_irq_chip *chip, int master) | 142 | static int pm8xxx_irq_master_handler(struct pm_irq_chip *chip, int master) |
150 | { | 143 | { |
151 | u8 blockbits; | 144 | unsigned int blockbits; |
152 | int block_number, i, ret = 0; | 145 | int block_number, i, ret = 0; |
153 | 146 | ||
154 | ret = pm8xxx_read_master_irq(chip, master, &blockbits); | 147 | ret = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_M_STATUS1 + master, |
148 | &blockbits); | ||
155 | if (ret) { | 149 | if (ret) { |
156 | pr_err("Failed to read master %d ret=%d\n", master, ret); | 150 | pr_err("Failed to read master %d ret=%d\n", master, ret); |
157 | return ret; | 151 | return ret; |
@@ -173,12 +167,12 @@ static void pm8xxx_irq_handler(unsigned int irq, struct irq_desc *desc) | |||
173 | { | 167 | { |
174 | struct pm_irq_chip *chip = irq_desc_get_handler_data(desc); | 168 | struct pm_irq_chip *chip = irq_desc_get_handler_data(desc); |
175 | struct irq_chip *irq_chip = irq_desc_get_chip(desc); | 169 | struct irq_chip *irq_chip = irq_desc_get_chip(desc); |
176 | u8 root; | 170 | unsigned int root; |
177 | int i, ret, masters = 0; | 171 | int i, ret, masters = 0; |
178 | 172 | ||
179 | chained_irq_enter(irq_chip, desc); | 173 | chained_irq_enter(irq_chip, desc); |
180 | 174 | ||
181 | ret = pm8xxx_read_root_irq(chip, &root); | 175 | ret = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_ROOT, &root); |
182 | if (ret) { | 176 | if (ret) { |
183 | pr_err("Can't read root status ret=%d\n", ret); | 177 | pr_err("Can't read root status ret=%d\n", ret); |
184 | return; | 178 | return; |
@@ -283,7 +277,7 @@ static struct irq_chip pm8xxx_irq_chip = { | |||
283 | static int pm8xxx_get_irq_stat(struct pm_irq_chip *chip, int irq) | 277 | static int pm8xxx_get_irq_stat(struct pm_irq_chip *chip, int irq) |
284 | { | 278 | { |
285 | int pmirq, rc; | 279 | int pmirq, rc; |
286 | u8 block, bits, bit; | 280 | unsigned int block, bits, bit; |
287 | unsigned long flags; | 281 | unsigned long flags; |
288 | struct irq_data *irq_data = irq_get_irq_data(irq); | 282 | struct irq_data *irq_data = irq_get_irq_data(irq); |
289 | 283 | ||
@@ -294,14 +288,14 @@ static int pm8xxx_get_irq_stat(struct pm_irq_chip *chip, int irq) | |||
294 | 288 | ||
295 | spin_lock_irqsave(&chip->pm_irq_lock, flags); | 289 | spin_lock_irqsave(&chip->pm_irq_lock, flags); |
296 | 290 | ||
297 | rc = pm8xxx_writeb(chip->dev, SSBI_REG_ADDR_IRQ_BLK_SEL, block); | 291 | rc = regmap_write(chip->regmap, SSBI_REG_ADDR_IRQ_BLK_SEL, block); |
298 | if (rc) { | 292 | if (rc) { |
299 | pr_err("Failed Selecting block irq=%d pmirq=%d blk=%d rc=%d\n", | 293 | pr_err("Failed Selecting block irq=%d pmirq=%d blk=%d rc=%d\n", |
300 | irq, pmirq, block, rc); | 294 | irq, pmirq, block, rc); |
301 | goto bail_out; | 295 | goto bail_out; |
302 | } | 296 | } |
303 | 297 | ||
304 | rc = pm8xxx_readb(chip->dev, SSBI_REG_ADDR_IRQ_RT_STATUS, &bits); | 298 | rc = regmap_read(chip->regmap, SSBI_REG_ADDR_IRQ_RT_STATUS, &bits); |
305 | if (rc) { | 299 | if (rc) { |
306 | pr_err("Failed Configuring irq=%d pmirq=%d blk=%d rc=%d\n", | 300 | pr_err("Failed Configuring irq=%d pmirq=%d blk=%d rc=%d\n", |
307 | irq, pmirq, block, rc); | 301 | irq, pmirq, block, rc); |
@@ -389,11 +383,21 @@ static struct pm8xxx_drvdata pm8921_drvdata = { | |||
389 | .pmic_read_irq_stat = pm8921_read_irq_stat, | 383 | .pmic_read_irq_stat = pm8921_read_irq_stat, |
390 | }; | 384 | }; |
391 | 385 | ||
386 | static const struct regmap_config ssbi_regmap_config = { | ||
387 | .reg_bits = 16, | ||
388 | .val_bits = 8, | ||
389 | .max_register = 0x3ff, | ||
390 | .fast_io = true, | ||
391 | .reg_read = ssbi_reg_read, | ||
392 | .reg_write = ssbi_reg_write | ||
393 | }; | ||
394 | |||
392 | static int pm8921_probe(struct platform_device *pdev) | 395 | static int pm8921_probe(struct platform_device *pdev) |
393 | { | 396 | { |
394 | struct pm8921 *pmic; | 397 | struct pm8921 *pmic; |
398 | struct regmap *regmap; | ||
395 | int rc; | 399 | int rc; |
396 | u8 val; | 400 | unsigned int val; |
397 | unsigned int irq; | 401 | unsigned int irq; |
398 | u32 rev; | 402 | u32 rev; |
399 | struct pm_irq_chip *chip; | 403 | struct pm_irq_chip *chip; |
@@ -409,8 +413,13 @@ static int pm8921_probe(struct platform_device *pdev) | |||
409 | return -ENOMEM; | 413 | return -ENOMEM; |
410 | } | 414 | } |
411 | 415 | ||
416 | regmap = devm_regmap_init(&pdev->dev, NULL, pdev->dev.parent, | ||
417 | &ssbi_regmap_config); | ||
418 | if (IS_ERR(regmap)) | ||
419 | return PTR_ERR(regmap); | ||
420 | |||
412 | /* Read PMIC chip revision */ | 421 | /* Read PMIC chip revision */ |
413 | rc = ssbi_read(pdev->dev.parent, REG_HWREV, &val, sizeof(val)); | 422 | rc = regmap_read(regmap, REG_HWREV, &val); |
414 | if (rc) { | 423 | if (rc) { |
415 | pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); | 424 | pr_err("Failed to read hw rev reg %d:rc=%d\n", REG_HWREV, rc); |
416 | return rc; | 425 | return rc; |
@@ -419,7 +428,7 @@ static int pm8921_probe(struct platform_device *pdev) | |||
419 | rev = val; | 428 | rev = val; |
420 | 429 | ||
421 | /* Read PMIC chip revision 2 */ | 430 | /* Read PMIC chip revision 2 */ |
422 | rc = ssbi_read(pdev->dev.parent, REG_HWREV_2, &val, sizeof(val)); | 431 | rc = regmap_read(regmap, REG_HWREV_2, &val); |
423 | if (rc) { | 432 | if (rc) { |
424 | pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", | 433 | pr_err("Failed to read hw rev 2 reg %d:rc=%d\n", |
425 | REG_HWREV_2, rc); | 434 | REG_HWREV_2, rc); |
@@ -440,6 +449,7 @@ static int pm8921_probe(struct platform_device *pdev) | |||
440 | 449 | ||
441 | pmic->irq_chip = chip; | 450 | pmic->irq_chip = chip; |
442 | chip->dev = &pdev->dev; | 451 | chip->dev = &pdev->dev; |
452 | chip->regmap = regmap; | ||
443 | chip->num_irqs = nirqs; | 453 | chip->num_irqs = nirqs; |
444 | chip->num_blocks = DIV_ROUND_UP(chip->num_irqs, 8); | 454 | chip->num_blocks = DIV_ROUND_UP(chip->num_irqs, 8); |
445 | chip->num_masters = DIV_ROUND_UP(chip->num_blocks, 8); | 455 | chip->num_masters = DIV_ROUND_UP(chip->num_blocks, 8); |