Oder Chiou | 49ef792 | 2014-05-20 15:01:53 +0800 | [diff] [blame^] | 1 | /* |
| 2 | * rl6231.c - RL6231 class device shared support |
| 3 | * |
| 4 | * Copyright 2014 Realtek Semiconductor Corp. |
| 5 | * |
| 6 | * Author: Oder Chiou <oder_chiou@realtek.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
| 15 | #include <linux/init.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/pm.h> |
| 18 | #include <linux/gpio.h> |
| 19 | #include <linux/i2c.h> |
| 20 | #include <linux/regmap.h> |
| 21 | #include <linux/of.h> |
| 22 | #include <linux/of_gpio.h> |
| 23 | #include <linux/platform_device.h> |
| 24 | #include <linux/spi/spi.h> |
| 25 | #include <linux/acpi.h> |
| 26 | #include <sound/core.h> |
| 27 | #include <sound/pcm.h> |
| 28 | #include <sound/pcm_params.h> |
| 29 | #include <sound/soc.h> |
| 30 | #include <sound/soc-dapm.h> |
| 31 | #include <sound/initval.h> |
| 32 | #include <sound/tlv.h> |
| 33 | |
| 34 | #include "rl6231.h" |
| 35 | |
| 36 | /** |
| 37 | * rl6231_calc_dmic_clk - Calculate the parameter of dmic. |
| 38 | * |
| 39 | * @rate: base clock rate. |
| 40 | * |
| 41 | * Choose dmic clock between 1MHz and 3MHz. |
| 42 | * It is better for clock to approximate 3MHz. |
| 43 | */ |
| 44 | int rl6231_calc_dmic_clk(int rate) |
| 45 | { |
| 46 | int div[] = {2, 3, 4, 6, 8, 12}, idx = -EINVAL; |
| 47 | int i, red, bound, temp; |
| 48 | |
| 49 | red = 3000000 * 12; |
| 50 | for (i = 0; i < ARRAY_SIZE(div); i++) { |
| 51 | bound = div[i] * 3000000; |
| 52 | if (rate > bound) |
| 53 | continue; |
| 54 | temp = bound - rate; |
| 55 | if (temp < red) { |
| 56 | red = temp; |
| 57 | idx = i; |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | return idx; |
| 62 | } |
| 63 | EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); |
| 64 | |
| 65 | MODULE_DESCRIPTION("RL6231 class device shared support"); |
| 66 | MODULE_AUTHOR("Oder Chiou <oder_chiou@realtek.com>"); |
| 67 | MODULE_LICENSE("GPL v2"); |