blob: 44be27e29e48fca25e63115ebaedf3e6d4e78fab [file] [log] [blame]
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001/*
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -08002 * Copyright (c) 2012-2016, The Linux Foundation. All rights reserved.
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06003 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
Stephen Boyd987a9f12015-11-17 16:13:55 -080013#include <linux/bitmap.h>
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060014#include <linux/delay.h>
15#include <linux/err.h>
16#include <linux/interrupt.h>
17#include <linux/io.h>
Josh Cartwright67b563f2014-02-12 13:44:25 -060018#include <linux/irqchip/chained_irq.h>
19#include <linux/irqdomain.h>
20#include <linux/irq.h>
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060021#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/of.h>
24#include <linux/platform_device.h>
25#include <linux/slab.h>
26#include <linux/spmi.h>
27
28/* PMIC Arbiter configuration registers */
29#define PMIC_ARB_VERSION 0x0000
Gilad Avidovd0c6ae42015-03-25 11:37:32 -060030#define PMIC_ARB_VERSION_V2_MIN 0x20010000
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060031#define PMIC_ARB_INT_EN 0x0004
32
Gilad Avidovd0c6ae42015-03-25 11:37:32 -060033/* PMIC Arbiter channel registers offsets */
34#define PMIC_ARB_CMD 0x00
35#define PMIC_ARB_CONFIG 0x04
36#define PMIC_ARB_STATUS 0x08
37#define PMIC_ARB_WDATA0 0x10
38#define PMIC_ARB_WDATA1 0x14
39#define PMIC_ARB_RDATA0 0x18
40#define PMIC_ARB_RDATA1 0x1C
41#define PMIC_ARB_REG_CHNL(N) (0x800 + 0x4 * (N))
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060042
43/* Mapping Table */
44#define SPMI_MAPPING_TABLE_REG(N) (0x0B00 + (4 * (N)))
45#define SPMI_MAPPING_BIT_INDEX(X) (((X) >> 18) & 0xF)
46#define SPMI_MAPPING_BIT_IS_0_FLAG(X) (((X) >> 17) & 0x1)
47#define SPMI_MAPPING_BIT_IS_0_RESULT(X) (((X) >> 9) & 0xFF)
48#define SPMI_MAPPING_BIT_IS_1_FLAG(X) (((X) >> 8) & 0x1)
49#define SPMI_MAPPING_BIT_IS_1_RESULT(X) (((X) >> 0) & 0xFF)
50
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060051#define SPMI_MAPPING_TABLE_TREE_DEPTH 16 /* Maximum of 16-bits */
Stephen Boyd987a9f12015-11-17 16:13:55 -080052#define PMIC_ARB_MAX_PPID BIT(12) /* PPID is 12bit */
53#define PMIC_ARB_CHAN_VALID BIT(15)
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060054
55/* Ownership Table */
56#define SPMI_OWNERSHIP_TABLE_REG(N) (0x0700 + (4 * (N)))
57#define SPMI_OWNERSHIP_PERIPH2OWNER(X) ((X) & 0x7)
58
59/* Channel Status fields */
60enum pmic_arb_chnl_status {
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -080061 PMIC_ARB_STATUS_DONE = BIT(0),
62 PMIC_ARB_STATUS_FAILURE = BIT(1),
63 PMIC_ARB_STATUS_DENIED = BIT(2),
64 PMIC_ARB_STATUS_DROPPED = BIT(3),
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060065};
66
67/* Command register fields */
68#define PMIC_ARB_CMD_MAX_BYTE_COUNT 8
69
70/* Command Opcodes */
71enum pmic_arb_cmd_op_code {
72 PMIC_ARB_OP_EXT_WRITEL = 0,
73 PMIC_ARB_OP_EXT_READL = 1,
74 PMIC_ARB_OP_EXT_WRITE = 2,
75 PMIC_ARB_OP_RESET = 3,
76 PMIC_ARB_OP_SLEEP = 4,
77 PMIC_ARB_OP_SHUTDOWN = 5,
78 PMIC_ARB_OP_WAKEUP = 6,
79 PMIC_ARB_OP_AUTHENTICATE = 7,
80 PMIC_ARB_OP_MSTR_READ = 8,
81 PMIC_ARB_OP_MSTR_WRITE = 9,
82 PMIC_ARB_OP_EXT_READ = 13,
83 PMIC_ARB_OP_WRITE = 14,
84 PMIC_ARB_OP_READ = 15,
85 PMIC_ARB_OP_ZERO_WRITE = 16,
86};
87
88/* Maximum number of support PMIC peripherals */
Stephen Boyd987a9f12015-11-17 16:13:55 -080089#define PMIC_ARB_MAX_PERIPHS 512
Kenneth Heitke39ae93e2014-02-12 13:44:24 -060090#define PMIC_ARB_TIMEOUT_US 100
91#define PMIC_ARB_MAX_TRANS_BYTES (8)
92
93#define PMIC_ARB_APID_MASK 0xFF
94#define PMIC_ARB_PPID_MASK 0xFFF
95
96/* interrupt enable bit */
97#define SPMI_PIC_ACC_ENABLE_BIT BIT(0)
98
Gilad Avidovd0c6ae42015-03-25 11:37:32 -060099struct pmic_arb_ver_ops;
100
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800101struct apid_data {
102 u16 ppid;
103 u8 owner;
104 u8 enabled_irq_mask;
105};
106
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600107/**
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800108 * spmi_pmic_arb - SPMI PMIC Arbiter object
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600109 *
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600110 * @rd_base: on v1 "core", on v2 "observer" register base off DT.
111 * @wr_base: on v1 "core", on v2 "chnls" register base off DT.
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600112 * @intr: address of the SPMI interrupt control registers.
113 * @cnfg: address of the PMIC Arbiter configuration registers.
114 * @lock: lock to synchronize accesses.
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600115 * @channel: execution environment channel to use for accesses.
Josh Cartwright67b563f2014-02-12 13:44:25 -0600116 * @irq: PMIC ARB interrupt.
117 * @ee: the current Execution Environment
118 * @min_apid: minimum APID (used for bounding IRQ search)
119 * @max_apid: maximum APID
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800120 * @max_periph: maximum number of PMIC peripherals supported by HW.
Josh Cartwright67b563f2014-02-12 13:44:25 -0600121 * @mapping_table: in-memory copy of PPID -> APID mapping table.
122 * @domain: irq domain object for PMIC IRQ domain
123 * @spmic: SPMI controller object
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600124 * @ver_ops: version dependent operations.
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800125 * @ppid_to_apid in-memory copy of PPID -> channel (APID) mapping table.
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600126 * v2 only.
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600127 */
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800128struct spmi_pmic_arb {
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600129 void __iomem *rd_base;
130 void __iomem *wr_base;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600131 void __iomem *intr;
132 void __iomem *cnfg;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800133 void __iomem *core;
134 resource_size_t core_size;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600135 raw_spinlock_t lock;
136 u8 channel;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600137 int irq;
138 u8 ee;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800139 u16 min_apid;
140 u16 max_apid;
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800141 u16 max_periph;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800142 u32 *mapping_table;
143 DECLARE_BITMAP(mapping_table_valid, PMIC_ARB_MAX_PERIPHS);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600144 struct irq_domain *domain;
145 struct spmi_controller *spmic;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600146 const struct pmic_arb_ver_ops *ver_ops;
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800147 u16 *ppid_to_apid;
148 u16 last_apid;
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800149 struct apid_data apid_data[PMIC_ARB_MAX_PERIPHS];
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600150};
151
152/**
153 * pmic_arb_ver: version dependent functionality.
154 *
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800155 * @mode: access rights to specified pmic peripheral.
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600156 * @non_data_cmd: on v1 issues an spmi non-data command.
157 * on v2 no HW support, returns -EOPNOTSUPP.
158 * @offset: on v1 offset of per-ee channel.
159 * on v2 offset of per-ee and per-ppid channel.
160 * @fmt_cmd: formats a GENI/SPMI command.
161 * @owner_acc_status: on v1 offset of PMIC_ARB_SPMI_PIC_OWNERm_ACC_STATUSn
162 * on v2 offset of SPMI_PIC_OWNERm_ACC_STATUSn.
163 * @acc_enable: on v1 offset of PMIC_ARB_SPMI_PIC_ACC_ENABLEn
164 * on v2 offset of SPMI_PIC_ACC_ENABLEn.
165 * @irq_status: on v1 offset of PMIC_ARB_SPMI_PIC_IRQ_STATUSn
166 * on v2 offset of SPMI_PIC_IRQ_STATUSn.
167 * @irq_clear: on v1 offset of PMIC_ARB_SPMI_PIC_IRQ_CLEARn
168 * on v2 offset of SPMI_PIC_IRQ_CLEARn.
169 */
170struct pmic_arb_ver_ops {
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800171 int (*ppid_to_apid)(struct spmi_pmic_arb *pa, u8 sid, u16 addr,
172 u8 *apid);
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800173 int (*mode)(struct spmi_pmic_arb *dev, u8 sid, u16 addr,
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800174 mode_t *mode);
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600175 /* spmi commands (read_cmd, write_cmd, cmd) functionality */
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800176 int (*offset)(struct spmi_pmic_arb *dev, u8 sid, u16 addr,
Stephen Boyd987a9f12015-11-17 16:13:55 -0800177 u32 *offset);
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600178 u32 (*fmt_cmd)(u8 opc, u8 sid, u16 addr, u8 bc);
179 int (*non_data_cmd)(struct spmi_controller *ctrl, u8 opc, u8 sid);
180 /* Interrupts controller functionality (offset of PIC registers) */
181 u32 (*owner_acc_status)(u8 m, u8 n);
182 u32 (*acc_enable)(u8 n);
183 u32 (*irq_status)(u8 n);
184 u32 (*irq_clear)(u8 n);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600185};
186
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800187static inline void pmic_arb_base_write(struct spmi_pmic_arb *pa,
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600188 u32 offset, u32 val)
189{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800190 writel_relaxed(val, pa->wr_base + offset);
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600191}
192
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800193static inline void pmic_arb_set_rd_cmd(struct spmi_pmic_arb *pa,
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600194 u32 offset, u32 val)
195{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800196 writel_relaxed(val, pa->rd_base + offset);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600197}
198
199/**
200 * pa_read_data: reads pmic-arb's register and copy 1..4 bytes to buf
201 * @bc: byte count -1. range: 0..3
202 * @reg: register's address
203 * @buf: output parameter, length must be bc + 1
204 */
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800205static void pa_read_data(struct spmi_pmic_arb *pa, u8 *buf, u32 reg, u8 bc)
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600206{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800207 u32 data = __raw_readl(pa->rd_base + reg);
208
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600209 memcpy(buf, &data, (bc & 3) + 1);
210}
211
212/**
213 * pa_write_data: write 1..4 bytes from buf to pmic-arb's register
214 * @bc: byte-count -1. range: 0..3.
215 * @reg: register's address.
216 * @buf: buffer to write. length must be bc + 1.
217 */
218static void
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800219pa_write_data(struct spmi_pmic_arb *pa, const u8 *buf, u32 reg, u8 bc)
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600220{
221 u32 data = 0;
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800222
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600223 memcpy(&data, buf, (bc & 3) + 1);
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800224 pmic_arb_base_write(pa, reg, data);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600225}
226
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600227static int pmic_arb_wait_for_done(struct spmi_controller *ctrl,
228 void __iomem *base, u8 sid, u16 addr)
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600229{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800230 struct spmi_pmic_arb *pa = spmi_controller_get_drvdata(ctrl);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600231 u32 status = 0;
232 u32 timeout = PMIC_ARB_TIMEOUT_US;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800233 u32 offset;
234 int rc;
235
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800236 rc = pa->ver_ops->offset(pa, sid, addr, &offset);
Stephen Boyd987a9f12015-11-17 16:13:55 -0800237 if (rc)
238 return rc;
239
240 offset += PMIC_ARB_STATUS;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600241
242 while (timeout--) {
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600243 status = readl_relaxed(base + offset);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600244
245 if (status & PMIC_ARB_STATUS_DONE) {
246 if (status & PMIC_ARB_STATUS_DENIED) {
247 dev_err(&ctrl->dev,
248 "%s: transaction denied (0x%x)\n",
249 __func__, status);
250 return -EPERM;
251 }
252
253 if (status & PMIC_ARB_STATUS_FAILURE) {
254 dev_err(&ctrl->dev,
255 "%s: transaction failed (0x%x)\n",
256 __func__, status);
257 return -EIO;
258 }
259
260 if (status & PMIC_ARB_STATUS_DROPPED) {
261 dev_err(&ctrl->dev,
262 "%s: transaction dropped (0x%x)\n",
263 __func__, status);
264 return -EIO;
265 }
266
267 return 0;
268 }
269 udelay(1);
270 }
271
272 dev_err(&ctrl->dev,
273 "%s: timeout, status 0x%x\n",
274 __func__, status);
275 return -ETIMEDOUT;
276}
277
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600278static int
279pmic_arb_non_data_cmd_v1(struct spmi_controller *ctrl, u8 opc, u8 sid)
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600280{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800281 struct spmi_pmic_arb *pa = spmi_controller_get_drvdata(ctrl);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600282 unsigned long flags;
283 u32 cmd;
284 int rc;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800285 u32 offset;
286
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800287 rc = pa->ver_ops->offset(pa, sid, 0, &offset);
Stephen Boyd987a9f12015-11-17 16:13:55 -0800288 if (rc)
289 return rc;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600290
291 cmd = ((opc | 0x40) << 27) | ((sid & 0xf) << 20);
292
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800293 raw_spin_lock_irqsave(&pa->lock, flags);
294 pmic_arb_base_write(pa, offset + PMIC_ARB_CMD, cmd);
295 rc = pmic_arb_wait_for_done(ctrl, pa->wr_base, sid, 0);
296 raw_spin_unlock_irqrestore(&pa->lock, flags);
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600297
298 return rc;
299}
300
301static int
302pmic_arb_non_data_cmd_v2(struct spmi_controller *ctrl, u8 opc, u8 sid)
303{
304 return -EOPNOTSUPP;
305}
306
307/* Non-data command */
308static int pmic_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid)
309{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800310 struct spmi_pmic_arb *pa = spmi_controller_get_drvdata(ctrl);
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600311
312 dev_dbg(&ctrl->dev, "cmd op:0x%x sid:%d\n", opc, sid);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600313
314 /* Check for valid non-data command */
315 if (opc < SPMI_CMD_RESET || opc > SPMI_CMD_WAKEUP)
316 return -EINVAL;
317
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800318 return pa->ver_ops->non_data_cmd(ctrl, opc, sid);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600319}
320
321static int pmic_arb_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
322 u16 addr, u8 *buf, size_t len)
323{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800324 struct spmi_pmic_arb *pa = spmi_controller_get_drvdata(ctrl);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600325 unsigned long flags;
326 u8 bc = len - 1;
327 u32 cmd;
328 int rc;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800329 u32 offset;
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800330 mode_t mode;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800331
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800332 rc = pa->ver_ops->offset(pa, sid, addr, &offset);
Stephen Boyd987a9f12015-11-17 16:13:55 -0800333 if (rc)
334 return rc;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600335
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800336 rc = pa->ver_ops->mode(pa, sid, addr, &mode);
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800337 if (rc)
338 return rc;
339
340 if (!(mode & 0400)) {
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800341 dev_err(&pa->spmic->dev,
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800342 "error: impermissible read from peripheral sid:%d addr:0x%x\n",
343 sid, addr);
344 return -ENODEV;
345 }
346
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600347 if (bc >= PMIC_ARB_MAX_TRANS_BYTES) {
348 dev_err(&ctrl->dev,
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600349 "pmic-arb supports 1..%d bytes per trans, but:%zu requested",
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600350 PMIC_ARB_MAX_TRANS_BYTES, len);
351 return -EINVAL;
352 }
353
354 /* Check the opcode */
355 if (opc >= 0x60 && opc <= 0x7F)
356 opc = PMIC_ARB_OP_READ;
357 else if (opc >= 0x20 && opc <= 0x2F)
358 opc = PMIC_ARB_OP_EXT_READ;
359 else if (opc >= 0x38 && opc <= 0x3F)
360 opc = PMIC_ARB_OP_EXT_READL;
361 else
362 return -EINVAL;
363
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800364 cmd = pa->ver_ops->fmt_cmd(opc, sid, addr, bc);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600365
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800366 raw_spin_lock_irqsave(&pa->lock, flags);
367 pmic_arb_set_rd_cmd(pa, offset + PMIC_ARB_CMD, cmd);
368 rc = pmic_arb_wait_for_done(ctrl, pa->rd_base, sid, addr);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600369 if (rc)
370 goto done;
371
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800372 pa_read_data(pa, buf, offset + PMIC_ARB_RDATA0,
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600373 min_t(u8, bc, 3));
374
375 if (bc > 3)
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800376 pa_read_data(pa, buf + 4, offset + PMIC_ARB_RDATA1, bc - 4);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600377
378done:
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800379 raw_spin_unlock_irqrestore(&pa->lock, flags);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600380 return rc;
381}
382
383static int pmic_arb_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
384 u16 addr, const u8 *buf, size_t len)
385{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800386 struct spmi_pmic_arb *pa = spmi_controller_get_drvdata(ctrl);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600387 unsigned long flags;
388 u8 bc = len - 1;
389 u32 cmd;
390 int rc;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800391 u32 offset;
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800392 mode_t mode;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800393
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800394 rc = pa->ver_ops->offset(pa, sid, addr, &offset);
Stephen Boyd987a9f12015-11-17 16:13:55 -0800395 if (rc)
396 return rc;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600397
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800398 rc = pa->ver_ops->mode(pa, sid, addr, &mode);
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800399 if (rc)
400 return rc;
401
402 if (!(mode & 0200)) {
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800403 dev_err(&pa->spmic->dev,
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800404 "error: impermissible write to peripheral sid:%d addr:0x%x\n",
405 sid, addr);
406 return -ENODEV;
407 }
408
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600409 if (bc >= PMIC_ARB_MAX_TRANS_BYTES) {
410 dev_err(&ctrl->dev,
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600411 "pmic-arb supports 1..%d bytes per trans, but:%zu requested",
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600412 PMIC_ARB_MAX_TRANS_BYTES, len);
413 return -EINVAL;
414 }
415
416 /* Check the opcode */
417 if (opc >= 0x40 && opc <= 0x5F)
418 opc = PMIC_ARB_OP_WRITE;
419 else if (opc >= 0x00 && opc <= 0x0F)
420 opc = PMIC_ARB_OP_EXT_WRITE;
421 else if (opc >= 0x30 && opc <= 0x37)
422 opc = PMIC_ARB_OP_EXT_WRITEL;
Stephen Boyd9b769682015-08-28 12:31:10 -0700423 else if (opc >= 0x80)
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600424 opc = PMIC_ARB_OP_ZERO_WRITE;
425 else
426 return -EINVAL;
427
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800428 cmd = pa->ver_ops->fmt_cmd(opc, sid, addr, bc);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600429
430 /* Write data to FIFOs */
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800431 raw_spin_lock_irqsave(&pa->lock, flags);
432 pa_write_data(pa, buf, offset + PMIC_ARB_WDATA0, min_t(u8, bc, 3));
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600433 if (bc > 3)
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800434 pa_write_data(pa, buf + 4, offset + PMIC_ARB_WDATA1, bc - 4);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600435
436 /* Start the transaction */
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800437 pmic_arb_base_write(pa, offset + PMIC_ARB_CMD, cmd);
438 rc = pmic_arb_wait_for_done(ctrl, pa->wr_base, sid, addr);
439 raw_spin_unlock_irqrestore(&pa->lock, flags);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600440
441 return rc;
442}
443
Josh Cartwright67b563f2014-02-12 13:44:25 -0600444enum qpnpint_regs {
445 QPNPINT_REG_RT_STS = 0x10,
446 QPNPINT_REG_SET_TYPE = 0x11,
447 QPNPINT_REG_POLARITY_HIGH = 0x12,
448 QPNPINT_REG_POLARITY_LOW = 0x13,
449 QPNPINT_REG_LATCHED_CLR = 0x14,
450 QPNPINT_REG_EN_SET = 0x15,
451 QPNPINT_REG_EN_CLR = 0x16,
452 QPNPINT_REG_LATCHED_STS = 0x18,
453};
454
455struct spmi_pmic_arb_qpnpint_type {
456 u8 type; /* 1 -> edge */
457 u8 polarity_high;
458 u8 polarity_low;
459} __packed;
460
461/* Simplified accessor functions for irqchip callbacks */
462static void qpnpint_spmi_write(struct irq_data *d, u8 reg, void *buf,
463 size_t len)
464{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800465 struct spmi_pmic_arb *pa = irq_data_get_irq_chip_data(d);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600466 u8 sid = d->hwirq >> 24;
467 u8 per = d->hwirq >> 16;
468
469 if (pmic_arb_write_cmd(pa->spmic, SPMI_CMD_EXT_WRITEL, sid,
470 (per << 8) + reg, buf, len))
471 dev_err_ratelimited(&pa->spmic->dev,
472 "failed irqchip transaction on %x\n",
473 d->irq);
474}
475
476static void qpnpint_spmi_read(struct irq_data *d, u8 reg, void *buf, size_t len)
477{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800478 struct spmi_pmic_arb *pa = irq_data_get_irq_chip_data(d);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600479 u8 sid = d->hwirq >> 24;
480 u8 per = d->hwirq >> 16;
481
482 if (pmic_arb_read_cmd(pa->spmic, SPMI_CMD_EXT_READL, sid,
483 (per << 8) + reg, buf, len))
484 dev_err_ratelimited(&pa->spmic->dev,
485 "failed irqchip transaction on %x\n",
486 d->irq);
487}
488
Abhijeet Dharmapurikarb9b87442016-01-08 10:50:19 -0800489static void cleanup_irq(struct spmi_pmic_arb *pa, u8 apid, int id)
490{
491 u32 status;
492 u16 ppid = pa->apid_data[apid].ppid;
493 u8 sid = ppid >> 8;
494 u8 per = ppid & 0xFF;
495 unsigned long flags;
496 u8 irq_mask = BIT(id);
497
498 raw_spin_lock_irqsave(&pa->lock, flags);
499 writel_relaxed(irq_mask, pa->intr + pa->ver_ops->irq_clear(apid));
500 if (pa->apid_data[apid].enabled_irq_mask == 0) {
501 status
502 = readl_relaxed(pa->intr + pa->ver_ops->acc_enable(apid));
503 status = status & ~SPMI_PIC_ACC_ENABLE_BIT;
504 writel_relaxed(status,
505 pa->intr + pa->ver_ops->acc_enable(apid));
506 }
507 raw_spin_unlock_irqrestore(&pa->lock, flags);
508
509 if (pmic_arb_write_cmd(pa->spmic, SPMI_CMD_EXT_WRITEL, sid,
510 (per << 8) + QPNPINT_REG_LATCHED_CLR, &irq_mask, 1))
511 dev_err_ratelimited(&pa->spmic->dev,
512 "failed to ack irq_mask = 0x%x for ppid = %x\n",
513 irq_mask, ppid);
514
515 if (pmic_arb_write_cmd(pa->spmic, SPMI_CMD_EXT_WRITEL, sid,
516 (per << 8) + QPNPINT_REG_EN_CLR, &irq_mask, 1))
517 dev_err_ratelimited(&pa->spmic->dev,
518 "failed to ack irq_mask = 0x%x for ppid = %x\n",
519 irq_mask, ppid);
520}
521
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800522static void periph_interrupt(struct spmi_pmic_arb *pa, u8 apid)
Josh Cartwright67b563f2014-02-12 13:44:25 -0600523{
524 unsigned int irq;
525 u32 status;
526 int id;
527
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600528 status = readl_relaxed(pa->intr + pa->ver_ops->irq_status(apid));
Josh Cartwright67b563f2014-02-12 13:44:25 -0600529 while (status) {
530 id = ffs(status) - 1;
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800531 status &= ~BIT(id);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600532 irq = irq_find_mapping(pa->domain,
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800533 pa->apid_data[apid].ppid << 16
Josh Cartwright67b563f2014-02-12 13:44:25 -0600534 | id << 8
535 | apid);
Abhijeet Dharmapurikarb9b87442016-01-08 10:50:19 -0800536 if (irq == 0) {
537 cleanup_irq(pa, apid, id);
538 continue;
539 }
Josh Cartwright67b563f2014-02-12 13:44:25 -0600540 generic_handle_irq(irq);
541 }
542}
543
Thomas Gleixnerbd0b9ac2015-09-14 10:42:37 +0200544static void pmic_arb_chained_irq(struct irq_desc *desc)
Josh Cartwright67b563f2014-02-12 13:44:25 -0600545{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800546 struct spmi_pmic_arb *pa = irq_desc_get_handler_data(desc);
Jiang Liu7fe88f32015-07-13 20:52:25 +0000547 struct irq_chip *chip = irq_desc_get_chip(desc);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600548 void __iomem *intr = pa->intr;
549 int first = pa->min_apid >> 5;
550 int last = pa->max_apid >> 5;
551 u32 status;
552 int i, id;
553
554 chained_irq_enter(chip, desc);
555
556 for (i = first; i <= last; ++i) {
557 status = readl_relaxed(intr +
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600558 pa->ver_ops->owner_acc_status(pa->ee, i));
Josh Cartwright67b563f2014-02-12 13:44:25 -0600559 while (status) {
560 id = ffs(status) - 1;
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800561 status &= ~BIT(id);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600562 periph_interrupt(pa, id + i * 32);
563 }
564 }
565
566 chained_irq_exit(chip, desc);
567}
568
569static void qpnpint_irq_ack(struct irq_data *d)
570{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800571 struct spmi_pmic_arb *pa = irq_data_get_irq_chip_data(d);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600572 u8 irq = d->hwirq >> 8;
573 u8 apid = d->hwirq;
574 unsigned long flags;
575 u8 data;
576
577 raw_spin_lock_irqsave(&pa->lock, flags);
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800578 writel_relaxed(BIT(irq), pa->intr + pa->ver_ops->irq_clear(apid));
Josh Cartwright67b563f2014-02-12 13:44:25 -0600579 raw_spin_unlock_irqrestore(&pa->lock, flags);
580
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800581 data = BIT(irq);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600582 qpnpint_spmi_write(d, QPNPINT_REG_LATCHED_CLR, &data, 1);
583}
584
585static void qpnpint_irq_mask(struct irq_data *d)
586{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800587 struct spmi_pmic_arb *pa = irq_data_get_irq_chip_data(d);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600588 u8 irq = d->hwirq >> 8;
589 u8 apid = d->hwirq;
590 unsigned long flags;
591 u32 status;
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800592 u8 data = BIT(irq);
593 u8 prev_enabled_irq_mask;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600594
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800595 prev_enabled_irq_mask = pa->apid_data[apid].enabled_irq_mask;
596 pa->apid_data[apid].enabled_irq_mask &= ~BIT(irq);
597
598 if (prev_enabled_irq_mask != 0 &&
599 pa->apid_data[apid].enabled_irq_mask == 0) {
600 raw_spin_lock_irqsave(&pa->lock, flags);
601 status = readl_relaxed(pa->intr
602 + pa->ver_ops->acc_enable(apid));
603 if (status & SPMI_PIC_ACC_ENABLE_BIT) {
604 status = status & ~SPMI_PIC_ACC_ENABLE_BIT;
605 writel_relaxed(status, pa->intr +
606 pa->ver_ops->acc_enable(apid));
607 }
608 raw_spin_unlock_irqrestore(&pa->lock, flags);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600609 }
Josh Cartwright67b563f2014-02-12 13:44:25 -0600610
Josh Cartwright67b563f2014-02-12 13:44:25 -0600611 qpnpint_spmi_write(d, QPNPINT_REG_EN_CLR, &data, 1);
612}
613
614static void qpnpint_irq_unmask(struct irq_data *d)
615{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800616 struct spmi_pmic_arb *pa = irq_data_get_irq_chip_data(d);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600617 u8 irq = d->hwirq >> 8;
618 u8 apid = d->hwirq;
619 unsigned long flags;
620 u32 status;
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800621 u8 prev_enabled_irq_mask;
David Collinsa5a32ce2013-11-05 09:31:16 -0800622 u8 buf[2];
Josh Cartwright67b563f2014-02-12 13:44:25 -0600623
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800624 prev_enabled_irq_mask = pa->apid_data[apid].enabled_irq_mask;
625 pa->apid_data[apid].enabled_irq_mask &= ~BIT(irq);
626 pa->apid_data[apid].enabled_irq_mask |= BIT(irq);
627
628 if (prev_enabled_irq_mask == 0 &&
629 pa->apid_data[apid].enabled_irq_mask != 0) {
630 raw_spin_lock_irqsave(&pa->lock, flags);
631 status = readl_relaxed(pa->intr
632 + pa->ver_ops->acc_enable(apid));
633 if (!(status & SPMI_PIC_ACC_ENABLE_BIT)) {
634 writel_relaxed(status | SPMI_PIC_ACC_ENABLE_BIT,
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600635 pa->intr + pa->ver_ops->acc_enable(apid));
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800636 }
637 raw_spin_unlock_irqrestore(&pa->lock, flags);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600638 }
Josh Cartwright67b563f2014-02-12 13:44:25 -0600639
David Collinsa5a32ce2013-11-05 09:31:16 -0800640 qpnpint_spmi_read(d, QPNPINT_REG_EN_SET, &buf[0], 1);
641 if (!(buf[0] & BIT(irq))) {
642 /*
643 * Since the interrupt is currently disabled, write to both the
644 * LATCHED_CLR and EN_SET registers so that a spurious interrupt
645 * cannot be triggered when the interrupt is enabled
646 */
647 buf[0] = BIT(irq);
648 buf[1] = BIT(irq);
649 qpnpint_spmi_write(d, QPNPINT_REG_LATCHED_CLR, &buf, 2);
650 }
Josh Cartwright67b563f2014-02-12 13:44:25 -0600651}
652
Josh Cartwright67b563f2014-02-12 13:44:25 -0600653static int qpnpint_irq_set_type(struct irq_data *d, unsigned int flow_type)
654{
655 struct spmi_pmic_arb_qpnpint_type type;
656 u8 irq = d->hwirq >> 8;
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800657 u8 bit_mask_irq = BIT(irq);
Josh Cartwright67b563f2014-02-12 13:44:25 -0600658
659 qpnpint_spmi_read(d, QPNPINT_REG_SET_TYPE, &type, sizeof(type));
660
661 if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) {
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800662 type.type |= bit_mask_irq;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600663 if (flow_type & IRQF_TRIGGER_RISING)
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800664 type.polarity_high |= bit_mask_irq;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600665 if (flow_type & IRQF_TRIGGER_FALLING)
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800666 type.polarity_low |= bit_mask_irq;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600667 } else {
668 if ((flow_type & (IRQF_TRIGGER_HIGH)) &&
669 (flow_type & (IRQF_TRIGGER_LOW)))
670 return -EINVAL;
671
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800672 type.type &= ~bit_mask_irq; /* level trig */
Josh Cartwright67b563f2014-02-12 13:44:25 -0600673 if (flow_type & IRQF_TRIGGER_HIGH)
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800674 type.polarity_high |= bit_mask_irq;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600675 else
Abhijeet Dharmapurikar469f2c32016-01-05 16:52:38 -0800676 type.polarity_low |= bit_mask_irq;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600677 }
678
679 qpnpint_spmi_write(d, QPNPINT_REG_SET_TYPE, &type, sizeof(type));
680 return 0;
681}
682
Courtney Cavin60be4232015-07-30 10:53:54 -0700683static int qpnpint_get_irqchip_state(struct irq_data *d,
684 enum irqchip_irq_state which,
685 bool *state)
686{
687 u8 irq = d->hwirq >> 8;
688 u8 status = 0;
689
690 if (which != IRQCHIP_STATE_LINE_LEVEL)
691 return -EINVAL;
692
693 qpnpint_spmi_read(d, QPNPINT_REG_RT_STS, &status, 1);
694 *state = !!(status & BIT(irq));
695
696 return 0;
697}
698
Josh Cartwright67b563f2014-02-12 13:44:25 -0600699static struct irq_chip pmic_arb_irqchip = {
700 .name = "pmic_arb",
Josh Cartwright67b563f2014-02-12 13:44:25 -0600701 .irq_ack = qpnpint_irq_ack,
702 .irq_mask = qpnpint_irq_mask,
703 .irq_unmask = qpnpint_irq_unmask,
704 .irq_set_type = qpnpint_irq_set_type,
Courtney Cavin60be4232015-07-30 10:53:54 -0700705 .irq_get_irqchip_state = qpnpint_get_irqchip_state,
Josh Cartwright67b563f2014-02-12 13:44:25 -0600706 .flags = IRQCHIP_MASK_ON_SUSPEND
707 | IRQCHIP_SKIP_SET_WAKE,
708};
709
Josh Cartwright67b563f2014-02-12 13:44:25 -0600710static int qpnpint_irq_domain_dt_translate(struct irq_domain *d,
711 struct device_node *controller,
712 const u32 *intspec,
713 unsigned int intsize,
714 unsigned long *out_hwirq,
715 unsigned int *out_type)
716{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800717 struct spmi_pmic_arb *pa = d->host_data;
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800718 int rc;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600719 u8 apid;
720
721 dev_dbg(&pa->spmic->dev,
722 "intspec[0] 0x%1x intspec[1] 0x%02x intspec[2] 0x%02x\n",
723 intspec[0], intspec[1], intspec[2]);
724
Marc Zyngier5d4c9bc2015-10-13 12:51:29 +0100725 if (irq_domain_get_of_node(d) != controller)
Josh Cartwright67b563f2014-02-12 13:44:25 -0600726 return -EINVAL;
727 if (intsize != 4)
728 return -EINVAL;
729 if (intspec[0] > 0xF || intspec[1] > 0xFF || intspec[2] > 0x7)
730 return -EINVAL;
731
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800732 rc = pa->ver_ops->ppid_to_apid(pa, intspec[0],
733 (intspec[1] << 8), &apid);
734 if (rc < 0) {
735 dev_err(&pa->spmic->dev,
736 "failed to xlate sid = 0x%x, periph = 0x%x, irq = %x rc = %d\n",
737 intspec[0], intspec[1], intspec[2], rc);
738 return rc;
739 }
Josh Cartwright67b563f2014-02-12 13:44:25 -0600740
741 /* Keep track of {max,min}_apid for bounding search during interrupt */
742 if (apid > pa->max_apid)
743 pa->max_apid = apid;
744 if (apid < pa->min_apid)
745 pa->min_apid = apid;
746
Abhijeet Dharmapurikar0571f6f2016-01-11 12:30:34 -0800747 *out_hwirq = (intspec[0] & 0xF) << 24
748 | (intspec[1] & 0xFF) << 16
749 | (intspec[2] & 0x7) << 8
Josh Cartwright67b563f2014-02-12 13:44:25 -0600750 | apid;
751 *out_type = intspec[3] & IRQ_TYPE_SENSE_MASK;
752
753 dev_dbg(&pa->spmic->dev, "out_hwirq = %lu\n", *out_hwirq);
754
755 return 0;
756}
757
758static int qpnpint_irq_domain_map(struct irq_domain *d,
759 unsigned int virq,
760 irq_hw_number_t hwirq)
761{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800762 struct spmi_pmic_arb *pa = d->host_data;
Josh Cartwright67b563f2014-02-12 13:44:25 -0600763
764 dev_dbg(&pa->spmic->dev, "virq = %u, hwirq = %lu\n", virq, hwirq);
765
766 irq_set_chip_and_handler(virq, &pmic_arb_irqchip, handle_level_irq);
767 irq_set_chip_data(virq, d->host_data);
768 irq_set_noprobe(virq);
769 return 0;
770}
771
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800772static int
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800773pmic_arb_ppid_to_apid_v1(struct spmi_pmic_arb *pa, u8 sid, u16 addr, u8 *apid)
774{
775 u16 ppid = sid << 8 | ((addr >> 8) & 0xFF);
776 u32 *mapping_table = pa->mapping_table;
777 int index = 0, i;
778 u16 apid_valid;
779 u32 data;
780
781 apid_valid = pa->ppid_to_apid[ppid];
782 if (apid_valid & PMIC_ARB_CHAN_VALID) {
783 *apid = (apid_valid & ~PMIC_ARB_CHAN_VALID);
784 return 0;
785 }
786
787 for (i = 0; i < SPMI_MAPPING_TABLE_TREE_DEPTH; ++i) {
788 if (!test_and_set_bit(index, pa->mapping_table_valid))
789 mapping_table[index] = readl_relaxed(pa->cnfg +
790 SPMI_MAPPING_TABLE_REG(index));
791
792 data = mapping_table[index];
793
794 if (ppid & BIT(SPMI_MAPPING_BIT_INDEX(data))) {
795 if (SPMI_MAPPING_BIT_IS_1_FLAG(data)) {
796 index = SPMI_MAPPING_BIT_IS_1_RESULT(data);
797 } else {
798 *apid = SPMI_MAPPING_BIT_IS_1_RESULT(data);
799 pa->ppid_to_apid[ppid]
800 = *apid | PMIC_ARB_CHAN_VALID;
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800801 pa->apid_data[*apid].ppid = ppid;
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800802 return 0;
803 }
804 } else {
805 if (SPMI_MAPPING_BIT_IS_0_FLAG(data)) {
806 index = SPMI_MAPPING_BIT_IS_0_RESULT(data);
807 } else {
808 *apid = SPMI_MAPPING_BIT_IS_0_RESULT(data);
809 pa->ppid_to_apid[ppid]
810 = *apid | PMIC_ARB_CHAN_VALID;
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800811 pa->apid_data[*apid].ppid = ppid;
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800812 return 0;
813 }
814 }
815 }
816
817 return -ENODEV;
818}
819
820static int
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800821pmic_arb_mode_v1(struct spmi_pmic_arb *pa, u8 sid, u16 addr, mode_t *mode)
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800822{
823 *mode = 0600;
824 return 0;
825}
826
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600827/* v1 offset per ee */
Stephen Boyd987a9f12015-11-17 16:13:55 -0800828static int
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800829pmic_arb_offset_v1(struct spmi_pmic_arb *pa, u8 sid, u16 addr, u32 *offset)
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600830{
Stephen Boyd987a9f12015-11-17 16:13:55 -0800831 *offset = 0x800 + 0x80 * pa->channel;
832 return 0;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600833}
834
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800835static u16 pmic_arb_find_apid(struct spmi_pmic_arb *pa, u16 ppid)
Stephen Boyd987a9f12015-11-17 16:13:55 -0800836{
837 u32 regval, offset;
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800838 u16 apid;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800839 u16 id;
840
841 /*
842 * PMIC_ARB_REG_CHNL is a table in HW mapping channel to ppid.
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800843 * ppid_to_apid is an in-memory invert of that table.
Stephen Boyd987a9f12015-11-17 16:13:55 -0800844 */
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800845 for (apid = pa->last_apid; apid < pa->max_periph; apid++) {
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800846 regval = readl_relaxed(pa->cnfg +
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800847 SPMI_OWNERSHIP_TABLE_REG(apid));
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800848 pa->apid_data[apid].owner = SPMI_OWNERSHIP_PERIPH2OWNER(regval);
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800849
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800850 offset = PMIC_ARB_REG_CHNL(apid);
Stephen Boyd987a9f12015-11-17 16:13:55 -0800851 if (offset >= pa->core_size)
852 break;
853
854 regval = readl_relaxed(pa->core + offset);
855 if (!regval)
856 continue;
857
858 id = (regval >> 8) & PMIC_ARB_PPID_MASK;
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800859 pa->ppid_to_apid[id] = apid | PMIC_ARB_CHAN_VALID;
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800860 pa->apid_data[apid].ppid = id;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800861 if (id == ppid) {
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800862 apid |= PMIC_ARB_CHAN_VALID;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800863 break;
864 }
865 }
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800866 pa->last_apid = apid & ~PMIC_ARB_CHAN_VALID;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800867
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800868 return apid;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800869}
870
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800871static int
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800872pmic_arb_ppid_to_apid_v2(struct spmi_pmic_arb *pa, u8 sid, u16 addr, u8 *apid)
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800873{
874 u16 ppid = (sid << 8) | (addr >> 8);
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800875 u16 apid_valid;
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800876
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800877 apid_valid = pa->ppid_to_apid[ppid];
878 if (!(apid_valid & PMIC_ARB_CHAN_VALID))
879 apid_valid = pmic_arb_find_apid(pa, ppid);
880 if (!(apid_valid & PMIC_ARB_CHAN_VALID))
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800881 return -ENODEV;
882
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800883 *apid = (apid_valid & ~PMIC_ARB_CHAN_VALID);
884 return 0;
885}
886
887static int
888pmic_arb_mode_v2(struct spmi_pmic_arb *pa, u8 sid, u16 addr, mode_t *mode)
889{
890 u8 apid;
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800891 int rc;
892
893 rc = pmic_arb_ppid_to_apid_v2(pa, sid, addr, &apid);
894 if (rc < 0)
895 return rc;
896
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800897 *mode = 0;
898 *mode |= 0400;
899
Abhijeet Dharmapurikar8f8ec812016-01-08 12:54:36 -0800900 if (pa->ee == pa->apid_data[apid].owner)
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800901 *mode |= 0200;
902 return 0;
903}
Stephen Boyd987a9f12015-11-17 16:13:55 -0800904
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800905/* v2 offset per ppid and per ee */
Stephen Boyd987a9f12015-11-17 16:13:55 -0800906static int
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -0800907pmic_arb_offset_v2(struct spmi_pmic_arb *pa, u8 sid, u16 addr, u32 *offset)
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600908{
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800909 u8 apid;
910 int rc;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600911
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800912 rc = pmic_arb_ppid_to_apid_v2(pa, sid, addr, &apid);
913 if (rc < 0)
914 return rc;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800915
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -0800916 *offset = 0x1000 * pa->ee + 0x8000 * apid;
Stephen Boyd987a9f12015-11-17 16:13:55 -0800917 return 0;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600918}
919
920static u32 pmic_arb_fmt_cmd_v1(u8 opc, u8 sid, u16 addr, u8 bc)
921{
922 return (opc << 27) | ((sid & 0xf) << 20) | (addr << 4) | (bc & 0x7);
923}
924
925static u32 pmic_arb_fmt_cmd_v2(u8 opc, u8 sid, u16 addr, u8 bc)
926{
927 return (opc << 27) | ((addr & 0xff) << 4) | (bc & 0x7);
928}
929
930static u32 pmic_arb_owner_acc_status_v1(u8 m, u8 n)
931{
932 return 0x20 * m + 0x4 * n;
933}
934
935static u32 pmic_arb_owner_acc_status_v2(u8 m, u8 n)
936{
937 return 0x100000 + 0x1000 * m + 0x4 * n;
938}
939
940static u32 pmic_arb_acc_enable_v1(u8 n)
941{
942 return 0x200 + 0x4 * n;
943}
944
945static u32 pmic_arb_acc_enable_v2(u8 n)
946{
947 return 0x1000 * n;
948}
949
950static u32 pmic_arb_irq_status_v1(u8 n)
951{
952 return 0x600 + 0x4 * n;
953}
954
955static u32 pmic_arb_irq_status_v2(u8 n)
956{
957 return 0x4 + 0x1000 * n;
958}
959
960static u32 pmic_arb_irq_clear_v1(u8 n)
961{
962 return 0xA00 + 0x4 * n;
963}
964
965static u32 pmic_arb_irq_clear_v2(u8 n)
966{
967 return 0x8 + 0x1000 * n;
968}
969
970static const struct pmic_arb_ver_ops pmic_arb_v1 = {
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800971 .ppid_to_apid = pmic_arb_ppid_to_apid_v1,
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800972 .mode = pmic_arb_mode_v1,
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600973 .non_data_cmd = pmic_arb_non_data_cmd_v1,
974 .offset = pmic_arb_offset_v1,
975 .fmt_cmd = pmic_arb_fmt_cmd_v1,
976 .owner_acc_status = pmic_arb_owner_acc_status_v1,
977 .acc_enable = pmic_arb_acc_enable_v1,
978 .irq_status = pmic_arb_irq_status_v1,
979 .irq_clear = pmic_arb_irq_clear_v1,
980};
981
982static const struct pmic_arb_ver_ops pmic_arb_v2 = {
Abhijeet Dharmapurikar6e9eb382016-01-08 12:50:24 -0800983 .ppid_to_apid = pmic_arb_ppid_to_apid_v2,
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -0800984 .mode = pmic_arb_mode_v2,
Gilad Avidovd0c6ae42015-03-25 11:37:32 -0600985 .non_data_cmd = pmic_arb_non_data_cmd_v2,
986 .offset = pmic_arb_offset_v2,
987 .fmt_cmd = pmic_arb_fmt_cmd_v2,
988 .owner_acc_status = pmic_arb_owner_acc_status_v2,
989 .acc_enable = pmic_arb_acc_enable_v2,
990 .irq_status = pmic_arb_irq_status_v2,
991 .irq_clear = pmic_arb_irq_clear_v2,
992};
993
Josh Cartwright67b563f2014-02-12 13:44:25 -0600994static const struct irq_domain_ops pmic_arb_irq_domain_ops = {
995 .map = qpnpint_irq_domain_map,
996 .xlate = qpnpint_irq_domain_dt_translate,
997};
998
Kenneth Heitke39ae93e2014-02-12 13:44:24 -0600999static int spmi_pmic_arb_probe(struct platform_device *pdev)
1000{
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -08001001 struct spmi_pmic_arb *pa;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001002 struct spmi_controller *ctrl;
1003 struct resource *res;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001004 void __iomem *core;
1005 u32 channel, ee, hw_ver;
Stephen Boyd987a9f12015-11-17 16:13:55 -08001006 int err;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001007 bool is_v1;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001008
1009 ctrl = spmi_controller_alloc(&pdev->dev, sizeof(*pa));
1010 if (!ctrl)
1011 return -ENOMEM;
1012
1013 pa = spmi_controller_get_drvdata(ctrl);
Josh Cartwright67b563f2014-02-12 13:44:25 -06001014 pa->spmic = ctrl;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001015
1016 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core");
Stephen Boyd987a9f12015-11-17 16:13:55 -08001017 pa->core_size = resource_size(res);
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -08001018 if (pa->core_size <= 0x800) {
1019 dev_err(&pdev->dev, "core_size is smaller than 0x800. Failing Probe\n");
1020 err = -EINVAL;
1021 goto err_put_ctrl;
1022 }
1023
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001024 core = devm_ioremap_resource(&ctrl->dev, res);
1025 if (IS_ERR(core)) {
1026 err = PTR_ERR(core);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001027 goto err_put_ctrl;
1028 }
1029
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001030 hw_ver = readl_relaxed(core + PMIC_ARB_VERSION);
1031 is_v1 = (hw_ver < PMIC_ARB_VERSION_V2_MIN);
1032
1033 dev_info(&ctrl->dev, "PMIC Arb Version-%d (0x%x)\n", (is_v1 ? 1 : 2),
1034 hw_ver);
1035
1036 if (is_v1) {
1037 pa->ver_ops = &pmic_arb_v1;
1038 pa->wr_base = core;
1039 pa->rd_base = core;
1040 } else {
Stephen Boyd987a9f12015-11-17 16:13:55 -08001041 pa->core = core;
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001042 pa->ver_ops = &pmic_arb_v2;
1043
Abhijeet Dharmapurikarea64f7f2016-01-18 22:00:33 -08001044 /* the apid to ppid table starts at PMIC_ARB_REG_CHNL(0) */
1045 pa->max_periph = (pa->core_size - PMIC_ARB_REG_CHNL(0)) / 4;
1046
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001047 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1048 "obsrvr");
1049 pa->rd_base = devm_ioremap_resource(&ctrl->dev, res);
1050 if (IS_ERR(pa->rd_base)) {
1051 err = PTR_ERR(pa->rd_base);
1052 goto err_put_ctrl;
1053 }
1054
1055 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1056 "chnls");
1057 pa->wr_base = devm_ioremap_resource(&ctrl->dev, res);
1058 if (IS_ERR(pa->wr_base)) {
1059 err = PTR_ERR(pa->wr_base);
1060 goto err_put_ctrl;
1061 }
1062
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -08001063 pa->ppid_to_apid = devm_kcalloc(&ctrl->dev,
Stephen Boyd987a9f12015-11-17 16:13:55 -08001064 PMIC_ARB_MAX_PPID,
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -08001065 sizeof(*pa->ppid_to_apid),
Stephen Boyd987a9f12015-11-17 16:13:55 -08001066 GFP_KERNEL);
Abhijeet Dharmapurikar39155b62016-01-06 19:55:21 -08001067 if (!pa->ppid_to_apid) {
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001068 err = -ENOMEM;
1069 goto err_put_ctrl;
1070 }
Gilad Avidovd0c6ae42015-03-25 11:37:32 -06001071 }
1072
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001073 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "intr");
1074 pa->intr = devm_ioremap_resource(&ctrl->dev, res);
1075 if (IS_ERR(pa->intr)) {
1076 err = PTR_ERR(pa->intr);
1077 goto err_put_ctrl;
1078 }
1079
1080 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cnfg");
1081 pa->cnfg = devm_ioremap_resource(&ctrl->dev, res);
1082 if (IS_ERR(pa->cnfg)) {
1083 err = PTR_ERR(pa->cnfg);
1084 goto err_put_ctrl;
1085 }
1086
Josh Cartwright67b563f2014-02-12 13:44:25 -06001087 pa->irq = platform_get_irq_byname(pdev, "periph_irq");
1088 if (pa->irq < 0) {
1089 err = pa->irq;
1090 goto err_put_ctrl;
1091 }
1092
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001093 err = of_property_read_u32(pdev->dev.of_node, "qcom,channel", &channel);
1094 if (err) {
1095 dev_err(&pdev->dev, "channel unspecified.\n");
1096 goto err_put_ctrl;
1097 }
1098
1099 if (channel > 5) {
1100 dev_err(&pdev->dev, "invalid channel (%u) specified.\n",
1101 channel);
Christophe JAILLETe98cc182016-09-26 22:24:46 +02001102 err = -EINVAL;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001103 goto err_put_ctrl;
1104 }
1105
1106 pa->channel = channel;
1107
Josh Cartwright67b563f2014-02-12 13:44:25 -06001108 err = of_property_read_u32(pdev->dev.of_node, "qcom,ee", &ee);
1109 if (err) {
1110 dev_err(&pdev->dev, "EE unspecified.\n");
1111 goto err_put_ctrl;
1112 }
1113
1114 if (ee > 5) {
1115 dev_err(&pdev->dev, "invalid EE (%u) specified\n", ee);
1116 err = -EINVAL;
1117 goto err_put_ctrl;
1118 }
1119
1120 pa->ee = ee;
1121
Stephen Boyd987a9f12015-11-17 16:13:55 -08001122 pa->mapping_table = devm_kcalloc(&ctrl->dev, PMIC_ARB_MAX_PERIPHS - 1,
1123 sizeof(*pa->mapping_table), GFP_KERNEL);
1124 if (!pa->mapping_table) {
1125 err = -ENOMEM;
1126 goto err_put_ctrl;
1127 }
Josh Cartwright67b563f2014-02-12 13:44:25 -06001128
1129 /* Initialize max_apid/min_apid to the opposite bounds, during
1130 * the irq domain translation, we are sure to update these */
1131 pa->max_apid = 0;
1132 pa->min_apid = PMIC_ARB_MAX_PERIPHS - 1;
1133
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001134 platform_set_drvdata(pdev, ctrl);
1135 raw_spin_lock_init(&pa->lock);
1136
1137 ctrl->cmd = pmic_arb_cmd;
1138 ctrl->read_cmd = pmic_arb_read_cmd;
1139 ctrl->write_cmd = pmic_arb_write_cmd;
1140
Josh Cartwright67b563f2014-02-12 13:44:25 -06001141 dev_dbg(&pdev->dev, "adding irq domain\n");
1142 pa->domain = irq_domain_add_tree(pdev->dev.of_node,
1143 &pmic_arb_irq_domain_ops, pa);
1144 if (!pa->domain) {
1145 dev_err(&pdev->dev, "unable to create irq_domain\n");
1146 err = -ENOMEM;
1147 goto err_put_ctrl;
1148 }
1149
Thomas Gleixnerfb68ba62015-07-13 20:52:24 +00001150 irq_set_chained_handler_and_data(pa->irq, pmic_arb_chained_irq, pa);
Josh Cartwright67b563f2014-02-12 13:44:25 -06001151
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001152 err = spmi_controller_add(ctrl);
1153 if (err)
Josh Cartwright67b563f2014-02-12 13:44:25 -06001154 goto err_domain_remove;
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001155
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001156 return 0;
1157
Josh Cartwright67b563f2014-02-12 13:44:25 -06001158err_domain_remove:
Thomas Gleixnerfb68ba62015-07-13 20:52:24 +00001159 irq_set_chained_handler_and_data(pa->irq, NULL, NULL);
Josh Cartwright67b563f2014-02-12 13:44:25 -06001160 irq_domain_remove(pa->domain);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001161err_put_ctrl:
1162 spmi_controller_put(ctrl);
1163 return err;
1164}
1165
1166static int spmi_pmic_arb_remove(struct platform_device *pdev)
1167{
1168 struct spmi_controller *ctrl = platform_get_drvdata(pdev);
Abhijeet Dharmapurikarfbcfb7e2016-01-08 12:45:20 -08001169 struct spmi_pmic_arb *pa = spmi_controller_get_drvdata(ctrl);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001170 spmi_controller_remove(ctrl);
Thomas Gleixnerfb68ba62015-07-13 20:52:24 +00001171 irq_set_chained_handler_and_data(pa->irq, NULL, NULL);
Josh Cartwright67b563f2014-02-12 13:44:25 -06001172 irq_domain_remove(pa->domain);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001173 spmi_controller_put(ctrl);
1174 return 0;
1175}
1176
1177static const struct of_device_id spmi_pmic_arb_match_table[] = {
1178 { .compatible = "qcom,spmi-pmic-arb", },
1179 {},
1180};
1181MODULE_DEVICE_TABLE(of, spmi_pmic_arb_match_table);
1182
1183static struct platform_driver spmi_pmic_arb_driver = {
1184 .probe = spmi_pmic_arb_probe,
1185 .remove = spmi_pmic_arb_remove,
1186 .driver = {
1187 .name = "spmi_pmic_arb",
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001188 .of_match_table = spmi_pmic_arb_match_table,
1189 },
1190};
Abhijeet Dharmapurikardf9bf942015-09-23 11:36:23 -07001191
1192int __init spmi_pmic_arb_init(void)
1193{
1194 return platform_driver_register(&spmi_pmic_arb_driver);
1195}
1196arch_initcall(spmi_pmic_arb_init);
Kenneth Heitke39ae93e2014-02-12 13:44:24 -06001197
1198MODULE_LICENSE("GPL v2");
1199MODULE_ALIAS("platform:spmi_pmic_arb");