1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) 2021-2022 Digiteq Automotive 4 * author: Martin Tuma <martin.tuma@digiteqautomotive.com> 5 */ 6 7 #include <linux/ioport.h> 8 #include "mgb4_regs.h" 9 mgb4_regs_map(struct resource * res,struct mgb4_regs * regs)10int mgb4_regs_map(struct resource *res, struct mgb4_regs *regs) 11 { 12 regs->mapbase = res->start; 13 regs->mapsize = resource_size(res); 14 15 if (!request_mem_region(regs->mapbase, regs->mapsize, res->name)) 16 return -EINVAL; 17 regs->membase = ioremap(regs->mapbase, regs->mapsize); 18 if (!regs->membase) { 19 release_mem_region(regs->mapbase, regs->mapsize); 20 return -EINVAL; 21 } 22 23 return 0; 24 } 25 mgb4_regs_free(struct mgb4_regs * regs)26void mgb4_regs_free(struct mgb4_regs *regs) 27 { 28 iounmap(regs->membase); 29 release_mem_region(regs->mapbase, regs->mapsize); 30 } 31