Lines Matching refs:ocmem

52 struct ocmem {  struct
104 static inline void ocmem_write(struct ocmem *ocmem, u32 reg, u32 data) in ocmem_write() argument
106 writel(data, ocmem->mmio + reg); in ocmem_write()
109 static inline u32 ocmem_read(struct ocmem *ocmem, u32 reg) in ocmem_read() argument
111 return readl(ocmem->mmio + reg); in ocmem_read()
114 static void update_ocmem(struct ocmem *ocmem) in update_ocmem() argument
120 for (i = 0; i < ocmem->config->num_regions; i++) { in update_ocmem()
121 struct ocmem_region *region = &ocmem->regions[i]; in update_ocmem()
127 dev_dbg(ocmem->dev, "ocmem_region_mode_control %x\n", in update_ocmem()
129 ocmem_write(ocmem, OCMEM_REG_REGION_MODE_CTL, region_mode_ctrl); in update_ocmem()
132 for (i = 0; i < ocmem->config->num_regions; i++) { in update_ocmem()
133 struct ocmem_region *region = &ocmem->regions[i]; in update_ocmem()
141 ocmem_write(ocmem, OCMEM_REG_PSGSC_CTL(i), data); in update_ocmem()
145 static unsigned long phys_to_offset(struct ocmem *ocmem, in phys_to_offset() argument
148 if (addr < ocmem->memory->start || addr >= ocmem->memory->end) in phys_to_offset()
151 return addr - ocmem->memory->start; in phys_to_offset()
154 static unsigned long device_address(struct ocmem *ocmem, in device_address() argument
161 return phys_to_offset(ocmem, addr); in device_address()
164 static void update_range(struct ocmem *ocmem, struct ocmem_buf *buf, in update_range() argument
170 for (i = 0; i < ocmem->config->num_regions; i++) { in update_range()
171 struct ocmem_region *region = &ocmem->regions[i]; in update_range()
185 update_ocmem(ocmem); in update_range()
188 struct ocmem *of_get_ocmem(struct device *dev) in of_get_ocmem()
192 struct ocmem *ocmem; in of_get_ocmem() local
209 ocmem = platform_get_drvdata(pdev); in of_get_ocmem()
210 if (!ocmem) { in of_get_ocmem()
215 return ocmem; in of_get_ocmem()
219 struct ocmem_buf *ocmem_allocate(struct ocmem *ocmem, enum ocmem_client client, in ocmem_allocate() argument
232 if (test_and_set_bit_lock(BIT(client), &ocmem->active_allocations)) in ocmem_allocate()
242 buf->addr = device_address(ocmem, client, buf->offset); in ocmem_allocate()
245 update_range(ocmem, buf, CORE_ON, WIDE_MODE); in ocmem_allocate()
251 dev_err(ocmem->dev, "could not lock: %d\n", ret); in ocmem_allocate()
256 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, buf->offset); in ocmem_allocate()
257 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_END, in ocmem_allocate()
261 dev_dbg(ocmem->dev, "using %ldK of OCMEM at 0x%08lx for client %d\n", in ocmem_allocate()
269 clear_bit_unlock(BIT(client), &ocmem->active_allocations); in ocmem_allocate()
275 void ocmem_free(struct ocmem *ocmem, enum ocmem_client client, in ocmem_free() argument
282 update_range(ocmem, buf, CLK_OFF, MODE_DEFAULT); in ocmem_free()
290 dev_err(ocmem->dev, "could not unlock: %d\n", ret); in ocmem_free()
292 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_START, 0x0); in ocmem_free()
293 ocmem_write(ocmem, OCMEM_REG_GFX_MPU_END, 0x0); in ocmem_free()
298 clear_bit_unlock(BIT(client), &ocmem->active_allocations); in ocmem_free()
307 struct ocmem *ocmem; in ocmem_dev_probe() local
312 ocmem = devm_kzalloc(dev, sizeof(*ocmem), GFP_KERNEL); in ocmem_dev_probe()
313 if (!ocmem) in ocmem_dev_probe()
316 ocmem->dev = dev; in ocmem_dev_probe()
317 ocmem->config = device_get_match_data(dev); in ocmem_dev_probe()
327 ocmem->mmio = devm_platform_ioremap_resource_byname(pdev, "ctrl"); in ocmem_dev_probe()
328 if (IS_ERR(ocmem->mmio)) { in ocmem_dev_probe()
330 return PTR_ERR(ocmem->mmio); in ocmem_dev_probe()
333 ocmem->memory = platform_get_resource_byname(pdev, IORESOURCE_MEM, in ocmem_dev_probe()
335 if (!ocmem->memory) { in ocmem_dev_probe()
345 dev_info(ocmem->dev, "Failed to enable clocks\n"); in ocmem_dev_probe()
358 reg = ocmem_read(ocmem, OCMEM_REG_HW_PROFILE); in ocmem_dev_probe()
359 ocmem->num_ports = OCMEM_HW_PROFILE_NUM_PORTS(reg); in ocmem_dev_probe()
360 ocmem->num_macros = OCMEM_HW_PROFILE_NUM_MACROS(reg); in ocmem_dev_probe()
361 ocmem->interleaved = !!(reg & OCMEM_HW_PROFILE_INTERLEAVING); in ocmem_dev_probe()
363 num_banks = ocmem->num_ports / 2; in ocmem_dev_probe()
364 region_size = ocmem->config->macro_size * num_banks; in ocmem_dev_probe()
367 ocmem->num_ports, ocmem->config->num_regions, in ocmem_dev_probe()
368 ocmem->num_macros, ocmem->interleaved ? "" : "not "); in ocmem_dev_probe()
370 ocmem->regions = devm_kcalloc(dev, ocmem->config->num_regions, in ocmem_dev_probe()
372 if (!ocmem->regions) { in ocmem_dev_probe()
377 for (i = 0; i < ocmem->config->num_regions; i++) { in ocmem_dev_probe()
378 struct ocmem_region *region = &ocmem->regions[i]; in ocmem_dev_probe()
388 if (i == (ocmem->config->num_regions - 1) && in ocmem_dev_probe()
390 region->macro_size = ocmem->config->macro_size / 2; in ocmem_dev_probe()
393 region->macro_size = ocmem->config->macro_size; in ocmem_dev_probe()
401 platform_set_drvdata(pdev, ocmem); in ocmem_dev_probe()