b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * ASRMICRO Audio driver |
| 3 | * |
| 4 | * Copyright (C) 2022 ASRMICRO. |
| 5 | * |
| 6 | * Author: Wen Chen <wenchen@asrmicro.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | */ |
| 17 | #include <linux/kernel.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/gpio.h> |
| 22 | #include <linux/of.h> |
| 23 | #include <linux/of_gpio.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/regulator/machine.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | #include <linux/pinctrl/consumer.h> |
| 28 | #include <linux/edge_wakeup_mmp.h> |
| 29 | #include <linux/mfd/88pm80x.h> |
| 30 | #include <soc/asr/addr-map.h> |
| 31 | |
| 32 | char * vir_MCLK_start_addr = NULL; |
| 33 | |
| 34 | char * get_MCLK_start_addr(void) |
| 35 | { |
| 36 | return vir_MCLK_start_addr; |
| 37 | } |
| 38 | EXPORT_SYMBOL_GPL(get_MCLK_start_addr); |
| 39 | |
| 40 | static int audio_regs_probe(struct platform_device *pdev) |
| 41 | { |
| 42 | struct resource *MCLK_reg_res = NULL; |
| 43 | |
| 44 | printk(KERN_INFO "enter %s. \n", __FUNCTION__); |
| 45 | |
| 46 | /* get the resource */ |
| 47 | MCLK_reg_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 48 | if (!MCLK_reg_res) { |
| 49 | printk(KERN_INFO "Couldn't platform_get_resource.\n"); |
| 50 | return -ENOENT; |
| 51 | } |
| 52 | |
| 53 | vir_MCLK_start_addr = ioremap(MCLK_reg_res->start, resource_size(MCLK_reg_res)); |
| 54 | if (!vir_MCLK_start_addr) { |
| 55 | printk(KERN_INFO "Couldn't ioremap\n"); |
| 56 | return -ENOMEM; |
| 57 | } |
| 58 | |
| 59 | printk(KERN_INFO"%s, phy MCLK_reg_res start is 0x%0x, vir_MCLK_start_addr is 0x%0x.\n", |
| 60 | __FUNCTION__, (unsigned int)(MCLK_reg_res->start), (unsigned int)vir_MCLK_start_addr); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static int audio_regs_remove(struct platform_device *pdev) |
| 66 | { |
| 67 | printk(KERN_INFO "enter %s. \n", __FUNCTION__); |
| 68 | |
| 69 | if (vir_MCLK_start_addr) { |
| 70 | iounmap(vir_MCLK_start_addr); |
| 71 | } |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | #ifdef CONFIG_OF |
| 77 | static const struct of_device_id audio_regs_dt_match[] = { |
| 78 | { .compatible = "ASRMICRO,audio-registers", }, |
| 79 | {}, |
| 80 | }; |
| 81 | #endif |
| 82 | |
| 83 | static struct platform_driver audio_regs_driver = { |
| 84 | .driver = { |
| 85 | .name = "audio-registers", |
| 86 | .owner = THIS_MODULE, |
| 87 | #ifdef CONFIG_OF |
| 88 | .of_match_table = of_match_ptr(audio_regs_dt_match), |
| 89 | #endif |
| 90 | }, |
| 91 | .probe = audio_regs_probe, |
| 92 | .remove = audio_regs_remove, |
| 93 | }; |
| 94 | |
| 95 | static int audio_regs_init(void) |
| 96 | { |
| 97 | return platform_driver_register(&audio_regs_driver); |
| 98 | } |
| 99 | |
| 100 | static void audio_regs_exit(void) |
| 101 | { |
| 102 | platform_driver_unregister(&audio_regs_driver); |
| 103 | } |
| 104 | |
| 105 | subsys_initcall(audio_regs_init); |
| 106 | //module_init(audio_regs_init); |
| 107 | module_exit(audio_regs_exit); |
| 108 | |
| 109 | MODULE_AUTHOR("Wen Chen <wenchen@asrmicro.com>"); |
| 110 | MODULE_DESCRIPTION("driver for audio registers config"); |
| 111 | MODULE_LICENSE("GPL v2"); |