a559617ea7c0b66e2b8f1d956d66dbc80a0c989f
[linux-2.6-microblaze.git] / drivers / soc / qcom / llcc-qcom.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
4  *
5  */
6
7 #include <linux/bitfield.h>
8 #include <linux/bitmap.h>
9 #include <linux/bitops.h>
10 #include <linux/device.h>
11 #include <linux/io.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/mutex.h>
15 #include <linux/of.h>
16 #include <linux/of_device.h>
17 #include <linux/regmap.h>
18 #include <linux/sizes.h>
19 #include <linux/slab.h>
20 #include <linux/soc/qcom/llcc-qcom.h>
21
22 #define ACTIVATE                      BIT(0)
23 #define DEACTIVATE                    BIT(1)
24 #define ACT_CTRL_OPCODE_ACTIVATE      BIT(0)
25 #define ACT_CTRL_OPCODE_DEACTIVATE    BIT(1)
26 #define ACT_CTRL_ACT_TRIG             BIT(0)
27 #define ACT_CTRL_OPCODE_SHIFT         0x01
28 #define ATTR1_PROBE_TARGET_WAYS_SHIFT 0x02
29 #define ATTR1_FIXED_SIZE_SHIFT        0x03
30 #define ATTR1_PRIORITY_SHIFT          0x04
31 #define ATTR1_MAX_CAP_SHIFT           0x10
32 #define ATTR0_RES_WAYS_MASK           GENMASK(11, 0)
33 #define ATTR0_BONUS_WAYS_MASK         GENMASK(27, 16)
34 #define ATTR0_BONUS_WAYS_SHIFT        0x10
35 #define LLCC_STATUS_READ_DELAY        100
36
37 #define CACHE_LINE_SIZE_SHIFT         6
38
39 #define LLCC_COMMON_HW_INFO           0x00030000
40 #define LLCC_MAJOR_VERSION_MASK       GENMASK(31, 24)
41
42 #define LLCC_COMMON_STATUS0           0x0003000c
43 #define LLCC_LB_CNT_MASK              GENMASK(31, 28)
44 #define LLCC_LB_CNT_SHIFT             28
45
46 #define MAX_CAP_TO_BYTES(n)           (n * SZ_1K)
47 #define LLCC_TRP_ACT_CTRLn(n)         (n * SZ_4K)
48 #define LLCC_TRP_STATUSn(n)           (4 + n * SZ_4K)
49 #define LLCC_TRP_ATTR0_CFGn(n)        (0x21000 + SZ_8 * n)
50 #define LLCC_TRP_ATTR1_CFGn(n)        (0x21004 + SZ_8 * n)
51
52 #define LLCC_TRP_SCID_DIS_CAP_ALLOC   0x21f00
53 #define LLCC_TRP_PCB_ACT              0x21f04
54
55 #define BANK_OFFSET_STRIDE            0x80000
56
57 /**
58  * struct llcc_slice_config - Data associated with the llcc slice
59  * @usecase_id: Unique id for the client's use case
60  * @slice_id: llcc slice id for each client
61  * @max_cap: The maximum capacity of the cache slice provided in KB
62  * @priority: Priority of the client used to select victim line for replacement
63  * @fixed_size: Boolean indicating if the slice has a fixed capacity
64  * @bonus_ways: Bonus ways are additional ways to be used for any slice,
65  *              if client ends up using more than reserved cache ways. Bonus
66  *              ways are allocated only if they are not reserved for some
67  *              other client.
68  * @res_ways: Reserved ways for the cache slice, the reserved ways cannot
69  *              be used by any other client than the one its assigned to.
70  * @cache_mode: Each slice operates as a cache, this controls the mode of the
71  *             slice: normal or TCM(Tightly Coupled Memory)
72  * @probe_target_ways: Determines what ways to probe for access hit. When
73  *                    configured to 1 only bonus and reserved ways are probed.
74  *                    When configured to 0 all ways in llcc are probed.
75  * @dis_cap_alloc: Disable capacity based allocation for a client
76  * @retain_on_pc: If this bit is set and client has maintained active vote
77  *               then the ways assigned to this client are not flushed on power
78  *               collapse.
79  * @activate_on_init: Activate the slice immediately after it is programmed
80  */
81 struct llcc_slice_config {
82         u32 usecase_id;
83         u32 slice_id;
84         u32 max_cap;
85         u32 priority;
86         bool fixed_size;
87         u32 bonus_ways;
88         u32 res_ways;
89         u32 cache_mode;
90         u32 probe_target_ways;
91         bool dis_cap_alloc;
92         bool retain_on_pc;
93         bool activate_on_init;
94 };
95
96 struct qcom_llcc_config {
97         const struct llcc_slice_config *sct_data;
98         int size;
99         bool need_llcc_cfg;
100 };
101
102 static const struct llcc_slice_config sc7180_data[] =  {
103         { LLCC_CPUSS,    1,  256, 1, 0, 0xf, 0x0, 0, 0, 0, 1, 1 },
104         { LLCC_MDM,      8,  128, 1, 0, 0xf, 0x0, 0, 0, 0, 1, 0 },
105         { LLCC_GPUHTW,   11, 128, 1, 0, 0xf, 0x0, 0, 0, 0, 1, 0 },
106         { LLCC_GPU,      12, 128, 1, 0, 0xf, 0x0, 0, 0, 0, 1, 0 },
107 };
108
109 static const struct llcc_slice_config sdm845_data[] =  {
110         { LLCC_CPUSS,    1,  2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 1 },
111         { LLCC_VIDSC0,   2,  512,  2, 1, 0x0,   0x0f0, 0, 0, 1, 1, 0 },
112         { LLCC_VIDSC1,   3,  512,  2, 1, 0x0,   0x0f0, 0, 0, 1, 1, 0 },
113         { LLCC_ROTATOR,  4,  563,  2, 1, 0x0,   0x00e, 2, 0, 1, 1, 0 },
114         { LLCC_VOICE,    5,  2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 0 },
115         { LLCC_AUDIO,    6,  2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 0 },
116         { LLCC_MDMHPGRW, 7,  1024, 2, 0, 0xfc,  0xf00, 0, 0, 1, 1, 0 },
117         { LLCC_MDM,      8,  2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 0 },
118         { LLCC_CMPT,     10, 2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 0 },
119         { LLCC_GPUHTW,   11, 512,  1, 1, 0xc,   0x0,   0, 0, 1, 1, 0 },
120         { LLCC_GPU,      12, 2304, 1, 0, 0xff0, 0x2,   0, 0, 1, 1, 0 },
121         { LLCC_MMUHWT,   13, 256,  2, 0, 0x0,   0x1,   0, 0, 1, 0, 1 },
122         { LLCC_CMPTDMA,  15, 2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 0 },
123         { LLCC_DISP,     16, 2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 0 },
124         { LLCC_VIDFW,    17, 2816, 1, 0, 0xffc, 0x2,   0, 0, 1, 1, 0 },
125         { LLCC_MDMHPFX,  20, 1024, 2, 1, 0x0,   0xf00, 0, 0, 1, 1, 0 },
126         { LLCC_MDMPNG,   21, 1024, 0, 1, 0x1e,  0x0,   0, 0, 1, 1, 0 },
127         { LLCC_AUDHW,    22, 1024, 1, 1, 0xffc, 0x2,   0, 0, 1, 1, 0 },
128 };
129
130 static const struct llcc_slice_config sm8150_data[] =  {
131         {  LLCC_CPUSS,    1, 3072, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 1 },
132         {  LLCC_VIDSC0,   2, 512,  2, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
133         {  LLCC_VIDSC1,   3, 512,  2, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
134         {  LLCC_AUDIO,    6, 1024, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
135         {  LLCC_MDMHPGRW, 7, 3072, 1, 0, 0xFF,  0xF00, 0, 0, 0, 1, 0 },
136         {  LLCC_MDM,      8, 3072, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
137         {  LLCC_MODHW,    9, 1024, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
138         {  LLCC_CMPT,    10, 3072, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
139         {  LLCC_GPUHTW , 11, 512,  1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
140         {  LLCC_GPU,     12, 2560, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
141         {  LLCC_MMUHWT,  13, 1024, 1, 1, 0xFFF, 0x0,   0, 0, 0, 0, 1 },
142         {  LLCC_CMPTDMA, 15, 3072, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
143         {  LLCC_DISP,    16, 3072, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
144         {  LLCC_MDMHPFX, 20, 1024, 2, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
145         {  LLCC_MDMHPFX, 21, 1024, 0, 1, 0xF,   0x0,   0, 0, 0, 1, 0 },
146         {  LLCC_AUDHW,   22, 1024, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
147         {  LLCC_NPU,     23, 3072, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
148         {  LLCC_WLHW,    24, 3072, 1, 1, 0xFFF, 0x0,   0, 0, 0, 1, 0 },
149         {  LLCC_MODPE,   29, 256,  1, 1, 0xF,   0x0,   0, 0, 0, 1, 0 },
150         {  LLCC_APTCM,   30, 256,  3, 1, 0x0,   0x1,   1, 0, 0, 1, 0 },
151         {  LLCC_WRCACHE, 31, 128,  1, 1, 0xFFF, 0x0,   0, 0, 0, 0, 0 },
152 };
153
154 static const struct qcom_llcc_config sc7180_cfg = {
155         .sct_data       = sc7180_data,
156         .size           = ARRAY_SIZE(sc7180_data),
157         .need_llcc_cfg  = true,
158 };
159
160 static const struct qcom_llcc_config sdm845_cfg = {
161         .sct_data       = sdm845_data,
162         .size           = ARRAY_SIZE(sdm845_data),
163         .need_llcc_cfg  = false,
164 };
165
166 static const struct qcom_llcc_config sm8150_cfg = {
167         .sct_data       = sm8150_data,
168         .size           = ARRAY_SIZE(sm8150_data),
169 };
170
171 static struct llcc_drv_data *drv_data = (void *) -EPROBE_DEFER;
172
173 /**
174  * llcc_slice_getd - get llcc slice descriptor
175  * @uid: usecase_id for the client
176  *
177  * A pointer to llcc slice descriptor will be returned on success and
178  * and error pointer is returned on failure
179  */
180 struct llcc_slice_desc *llcc_slice_getd(u32 uid)
181 {
182         const struct llcc_slice_config *cfg;
183         struct llcc_slice_desc *desc;
184         u32 sz, count;
185
186         if (IS_ERR(drv_data))
187                 return ERR_CAST(drv_data);
188
189         cfg = drv_data->cfg;
190         sz = drv_data->cfg_size;
191
192         for (count = 0; cfg && count < sz; count++, cfg++)
193                 if (cfg->usecase_id == uid)
194                         break;
195
196         if (count == sz || !cfg)
197                 return ERR_PTR(-ENODEV);
198
199         desc = kzalloc(sizeof(*desc), GFP_KERNEL);
200         if (!desc)
201                 return ERR_PTR(-ENOMEM);
202
203         desc->slice_id = cfg->slice_id;
204         desc->slice_size = cfg->max_cap;
205
206         return desc;
207 }
208 EXPORT_SYMBOL_GPL(llcc_slice_getd);
209
210 /**
211  * llcc_slice_putd - llcc slice descritpor
212  * @desc: Pointer to llcc slice descriptor
213  */
214 void llcc_slice_putd(struct llcc_slice_desc *desc)
215 {
216         if (!IS_ERR_OR_NULL(desc))
217                 kfree(desc);
218 }
219 EXPORT_SYMBOL_GPL(llcc_slice_putd);
220
221 static int llcc_update_act_ctrl(u32 sid,
222                                 u32 act_ctrl_reg_val, u32 status)
223 {
224         u32 act_ctrl_reg;
225         u32 status_reg;
226         u32 slice_status;
227         int ret;
228
229         if (IS_ERR(drv_data))
230                 return PTR_ERR(drv_data);
231
232         act_ctrl_reg = LLCC_TRP_ACT_CTRLn(sid);
233         status_reg = LLCC_TRP_STATUSn(sid);
234
235         /* Set the ACTIVE trigger */
236         act_ctrl_reg_val |= ACT_CTRL_ACT_TRIG;
237         ret = regmap_write(drv_data->bcast_regmap, act_ctrl_reg,
238                                 act_ctrl_reg_val);
239         if (ret)
240                 return ret;
241
242         /* Clear the ACTIVE trigger */
243         act_ctrl_reg_val &= ~ACT_CTRL_ACT_TRIG;
244         ret = regmap_write(drv_data->bcast_regmap, act_ctrl_reg,
245                                 act_ctrl_reg_val);
246         if (ret)
247                 return ret;
248
249         ret = regmap_read_poll_timeout(drv_data->bcast_regmap, status_reg,
250                                       slice_status, !(slice_status & status),
251                                       0, LLCC_STATUS_READ_DELAY);
252         return ret;
253 }
254
255 /**
256  * llcc_slice_activate - Activate the llcc slice
257  * @desc: Pointer to llcc slice descriptor
258  *
259  * A value of zero will be returned on success and a negative errno will
260  * be returned in error cases
261  */
262 int llcc_slice_activate(struct llcc_slice_desc *desc)
263 {
264         int ret;
265         u32 act_ctrl_val;
266
267         if (IS_ERR(drv_data))
268                 return PTR_ERR(drv_data);
269
270         if (IS_ERR_OR_NULL(desc))
271                 return -EINVAL;
272
273         mutex_lock(&drv_data->lock);
274         if (test_bit(desc->slice_id, drv_data->bitmap)) {
275                 mutex_unlock(&drv_data->lock);
276                 return 0;
277         }
278
279         act_ctrl_val = ACT_CTRL_OPCODE_ACTIVATE << ACT_CTRL_OPCODE_SHIFT;
280
281         ret = llcc_update_act_ctrl(desc->slice_id, act_ctrl_val,
282                                   DEACTIVATE);
283         if (ret) {
284                 mutex_unlock(&drv_data->lock);
285                 return ret;
286         }
287
288         __set_bit(desc->slice_id, drv_data->bitmap);
289         mutex_unlock(&drv_data->lock);
290
291         return ret;
292 }
293 EXPORT_SYMBOL_GPL(llcc_slice_activate);
294
295 /**
296  * llcc_slice_deactivate - Deactivate the llcc slice
297  * @desc: Pointer to llcc slice descriptor
298  *
299  * A value of zero will be returned on success and a negative errno will
300  * be returned in error cases
301  */
302 int llcc_slice_deactivate(struct llcc_slice_desc *desc)
303 {
304         u32 act_ctrl_val;
305         int ret;
306
307         if (IS_ERR(drv_data))
308                 return PTR_ERR(drv_data);
309
310         if (IS_ERR_OR_NULL(desc))
311                 return -EINVAL;
312
313         mutex_lock(&drv_data->lock);
314         if (!test_bit(desc->slice_id, drv_data->bitmap)) {
315                 mutex_unlock(&drv_data->lock);
316                 return 0;
317         }
318         act_ctrl_val = ACT_CTRL_OPCODE_DEACTIVATE << ACT_CTRL_OPCODE_SHIFT;
319
320         ret = llcc_update_act_ctrl(desc->slice_id, act_ctrl_val,
321                                   ACTIVATE);
322         if (ret) {
323                 mutex_unlock(&drv_data->lock);
324                 return ret;
325         }
326
327         __clear_bit(desc->slice_id, drv_data->bitmap);
328         mutex_unlock(&drv_data->lock);
329
330         return ret;
331 }
332 EXPORT_SYMBOL_GPL(llcc_slice_deactivate);
333
334 /**
335  * llcc_get_slice_id - return the slice id
336  * @desc: Pointer to llcc slice descriptor
337  */
338 int llcc_get_slice_id(struct llcc_slice_desc *desc)
339 {
340         if (IS_ERR_OR_NULL(desc))
341                 return -EINVAL;
342
343         return desc->slice_id;
344 }
345 EXPORT_SYMBOL_GPL(llcc_get_slice_id);
346
347 /**
348  * llcc_get_slice_size - return the slice id
349  * @desc: Pointer to llcc slice descriptor
350  */
351 size_t llcc_get_slice_size(struct llcc_slice_desc *desc)
352 {
353         if (IS_ERR_OR_NULL(desc))
354                 return 0;
355
356         return desc->slice_size;
357 }
358 EXPORT_SYMBOL_GPL(llcc_get_slice_size);
359
360 static int _qcom_llcc_cfg_program(const struct llcc_slice_config *config,
361                                   const struct qcom_llcc_config *cfg)
362 {
363         int ret;
364         u32 attr1_cfg;
365         u32 attr0_cfg;
366         u32 attr1_val;
367         u32 attr0_val;
368         u32 max_cap_cacheline;
369         struct llcc_slice_desc desc;
370
371         attr1_val = config->cache_mode;
372         attr1_val |= config->probe_target_ways << ATTR1_PROBE_TARGET_WAYS_SHIFT;
373         attr1_val |= config->fixed_size << ATTR1_FIXED_SIZE_SHIFT;
374         attr1_val |= config->priority << ATTR1_PRIORITY_SHIFT;
375
376         max_cap_cacheline = MAX_CAP_TO_BYTES(config->max_cap);
377
378         /*
379          * LLCC instances can vary for each target.
380          * The SW writes to broadcast register which gets propagated
381          * to each llcc instance (llcc0,.. llccN).
382          * Since the size of the memory is divided equally amongst the
383          * llcc instances, we need to configure the max cap accordingly.
384          */
385         max_cap_cacheline = max_cap_cacheline / drv_data->num_banks;
386         max_cap_cacheline >>= CACHE_LINE_SIZE_SHIFT;
387         attr1_val |= max_cap_cacheline << ATTR1_MAX_CAP_SHIFT;
388
389         attr1_cfg = LLCC_TRP_ATTR1_CFGn(config->slice_id);
390
391         ret = regmap_write(drv_data->bcast_regmap, attr1_cfg, attr1_val);
392         if (ret)
393                 return ret;
394
395         attr0_val = config->res_ways & ATTR0_RES_WAYS_MASK;
396         attr0_val |= config->bonus_ways << ATTR0_BONUS_WAYS_SHIFT;
397
398         attr0_cfg = LLCC_TRP_ATTR0_CFGn(config->slice_id);
399
400         ret = regmap_write(drv_data->bcast_regmap, attr0_cfg, attr0_val);
401         if (ret)
402                 return ret;
403
404         if (cfg->need_llcc_cfg) {
405                 u32 disable_cap_alloc, retain_pc;
406
407                 disable_cap_alloc = config->dis_cap_alloc << config->slice_id;
408                 ret = regmap_write(drv_data->bcast_regmap,
409                                 LLCC_TRP_SCID_DIS_CAP_ALLOC, disable_cap_alloc);
410                 if (ret)
411                         return ret;
412
413                 retain_pc = config->retain_on_pc << config->slice_id;
414                 ret = regmap_write(drv_data->bcast_regmap,
415                                 LLCC_TRP_PCB_ACT, retain_pc);
416                 if (ret)
417                         return ret;
418         }
419
420         if (config->activate_on_init) {
421                 desc.slice_id = config->slice_id;
422                 ret = llcc_slice_activate(&desc);
423         }
424
425         return ret;
426 }
427
428 static int qcom_llcc_cfg_program(struct platform_device *pdev,
429                                  const struct qcom_llcc_config *cfg)
430 {
431         int i;
432         u32 sz;
433         int ret = 0;
434         const struct llcc_slice_config *llcc_table;
435
436         sz = drv_data->cfg_size;
437         llcc_table = drv_data->cfg;
438
439         for (i = 0; i < sz; i++) {
440                 ret = _qcom_llcc_cfg_program(&llcc_table[i], cfg);
441                 if (ret)
442                         return ret;
443         }
444
445         return ret;
446 }
447
448 static int qcom_llcc_remove(struct platform_device *pdev)
449 {
450         /* Set the global pointer to a error code to avoid referencing it */
451         drv_data = ERR_PTR(-ENODEV);
452         return 0;
453 }
454
455 static struct regmap *qcom_llcc_init_mmio(struct platform_device *pdev,
456                 const char *name)
457 {
458         void __iomem *base;
459         struct regmap_config llcc_regmap_config = {
460                 .reg_bits = 32,
461                 .reg_stride = 4,
462                 .val_bits = 32,
463                 .fast_io = true,
464         };
465
466         base = devm_platform_ioremap_resource_byname(pdev, name);
467         if (IS_ERR(base))
468                 return ERR_CAST(base);
469
470         llcc_regmap_config.name = name;
471         return devm_regmap_init_mmio(&pdev->dev, base, &llcc_regmap_config);
472 }
473
474 static int qcom_llcc_probe(struct platform_device *pdev)
475 {
476         u32 num_banks;
477         struct device *dev = &pdev->dev;
478         int ret, i;
479         struct platform_device *llcc_edac;
480         const struct qcom_llcc_config *cfg;
481         const struct llcc_slice_config *llcc_cfg;
482         u32 sz;
483         u32 version;
484
485         drv_data = devm_kzalloc(dev, sizeof(*drv_data), GFP_KERNEL);
486         if (!drv_data) {
487                 ret = -ENOMEM;
488                 goto err;
489         }
490
491         drv_data->regmap = qcom_llcc_init_mmio(pdev, "llcc_base");
492         if (IS_ERR(drv_data->regmap)) {
493                 ret = PTR_ERR(drv_data->regmap);
494                 goto err;
495         }
496
497         drv_data->bcast_regmap =
498                 qcom_llcc_init_mmio(pdev, "llcc_broadcast_base");
499         if (IS_ERR(drv_data->bcast_regmap)) {
500                 ret = PTR_ERR(drv_data->bcast_regmap);
501                 goto err;
502         }
503
504         /* Extract major version of the IP */
505         ret = regmap_read(drv_data->bcast_regmap, LLCC_COMMON_HW_INFO, &version);
506         if (ret)
507                 goto err;
508
509         drv_data->major_version = FIELD_GET(LLCC_MAJOR_VERSION_MASK, version);
510
511         ret = regmap_read(drv_data->regmap, LLCC_COMMON_STATUS0,
512                                                 &num_banks);
513         if (ret)
514                 goto err;
515
516         num_banks &= LLCC_LB_CNT_MASK;
517         num_banks >>= LLCC_LB_CNT_SHIFT;
518         drv_data->num_banks = num_banks;
519
520         cfg = of_device_get_match_data(&pdev->dev);
521         llcc_cfg = cfg->sct_data;
522         sz = cfg->size;
523
524         for (i = 0; i < sz; i++)
525                 if (llcc_cfg[i].slice_id > drv_data->max_slices)
526                         drv_data->max_slices = llcc_cfg[i].slice_id;
527
528         drv_data->offsets = devm_kcalloc(dev, num_banks, sizeof(u32),
529                                                         GFP_KERNEL);
530         if (!drv_data->offsets) {
531                 ret = -ENOMEM;
532                 goto err;
533         }
534
535         for (i = 0; i < num_banks; i++)
536                 drv_data->offsets[i] = i * BANK_OFFSET_STRIDE;
537
538         drv_data->bitmap = devm_kcalloc(dev,
539         BITS_TO_LONGS(drv_data->max_slices), sizeof(unsigned long),
540                                                 GFP_KERNEL);
541         if (!drv_data->bitmap) {
542                 ret = -ENOMEM;
543                 goto err;
544         }
545
546         drv_data->cfg = llcc_cfg;
547         drv_data->cfg_size = sz;
548         mutex_init(&drv_data->lock);
549         platform_set_drvdata(pdev, drv_data);
550
551         ret = qcom_llcc_cfg_program(pdev, cfg);
552         if (ret)
553                 goto err;
554
555         drv_data->ecc_irq = platform_get_irq(pdev, 0);
556         if (drv_data->ecc_irq >= 0) {
557                 llcc_edac = platform_device_register_data(&pdev->dev,
558                                                 "qcom_llcc_edac", -1, drv_data,
559                                                 sizeof(*drv_data));
560                 if (IS_ERR(llcc_edac))
561                         dev_err(dev, "Failed to register llcc edac driver\n");
562         }
563
564         return 0;
565 err:
566         drv_data = ERR_PTR(-ENODEV);
567         return ret;
568 }
569
570 static const struct of_device_id qcom_llcc_of_match[] = {
571         { .compatible = "qcom,sc7180-llcc", .data = &sc7180_cfg },
572         { .compatible = "qcom,sdm845-llcc", .data = &sdm845_cfg },
573         { .compatible = "qcom,sm8150-llcc", .data = &sm8150_cfg },
574         { }
575 };
576
577 static struct platform_driver qcom_llcc_driver = {
578         .driver = {
579                 .name = "qcom-llcc",
580                 .of_match_table = qcom_llcc_of_match,
581         },
582         .probe = qcom_llcc_probe,
583         .remove = qcom_llcc_remove,
584 };
585 module_platform_driver(qcom_llcc_driver);
586
587 MODULE_DESCRIPTION("Qualcomm Last Level Cache Controller");
588 MODULE_LICENSE("GPL v2");