Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Apple Onboard Audio driver for Toonie codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright 2006 Johannes Berg <johannes@sipsolutions.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This is a driver for the toonie codec chip. This chip is present
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * on the Mac Mini and is nothing but a DAC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) MODULE_AUTHOR("Johannes Berg <johannes@sipsolutions.net>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) MODULE_DESCRIPTION("toonie codec driver for snd-aoa");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include "../aoa.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include "../soundbus/soundbus.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define PFX "snd-aoa-codec-toonie: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) struct toonie {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 	struct aoa_codec	codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define codec_to_toonie(c) container_of(c, struct toonie, codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int toonie_dev_register(struct snd_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) static const struct snd_device_ops ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	.dev_register = toonie_dev_register,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) static struct transfer_info toonie_transfers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	/* This thing *only* has analog output,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	 * the rates are taken from Info.plist
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	 * from Darwin. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		.formats = SNDRV_PCM_FMTBIT_S16_BE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 			   SNDRV_PCM_FMTBIT_S24_BE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		.rates = SNDRV_PCM_RATE_32000 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 			 SNDRV_PCM_RATE_44100 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 			 SNDRV_PCM_RATE_48000 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 			 SNDRV_PCM_RATE_88200 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			 SNDRV_PCM_RATE_96000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int toonie_usable(struct codec_info_item *cii,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 			 struct transfer_info *ti,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 			 struct transfer_info *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static int toonie_suspend(struct codec_info_item *cii, pm_message_t state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	/* can we turn it off somehow? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) static int toonie_resume(struct codec_info_item *cii)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #endif /* CONFIG_PM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static struct codec_info toonie_codec_info = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.transfers = toonie_transfers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.sysclock_factor = 256,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.bus_factor = 64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.usable = toonie_usable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) #ifdef CONFIG_PM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	.suspend = toonie_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	.resume = toonie_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) static int toonie_init_codec(struct aoa_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	struct toonie *toonie = codec_to_toonie(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	/* nothing connected? what a joke! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if (toonie->codec.connected != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		return -ENOTCONN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	if (aoa_snd_device_new(SNDRV_DEV_CODEC, toonie, &ops)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		printk(KERN_ERR PFX "failed to create toonie snd device!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	if (toonie->codec.soundbus_dev->attach_codec(toonie->codec.soundbus_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 						     aoa_get_card(),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 						     &toonie_codec_info, toonie)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		printk(KERN_ERR PFX "error creating toonie pcm\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		snd_device_free(aoa_get_card(), toonie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) static void toonie_exit_codec(struct aoa_codec *codec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	struct toonie *toonie = codec_to_toonie(codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (!toonie->codec.soundbus_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		printk(KERN_ERR PFX "toonie_exit_codec called without soundbus_dev!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	toonie->codec.soundbus_dev->detach_codec(toonie->codec.soundbus_dev, toonie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) static struct toonie *toonie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) static int __init toonie_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	toonie = kzalloc(sizeof(struct toonie), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	if (!toonie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	strlcpy(toonie->codec.name, "toonie", sizeof(toonie->codec.name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	toonie->codec.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	toonie->codec.init = toonie_init_codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	toonie->codec.exit = toonie_exit_codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	if (aoa_codec_register(&toonie->codec)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		kfree(toonie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static void __exit toonie_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	aoa_codec_unregister(&toonie->codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	kfree(toonie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) module_init(toonie_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) module_exit(toonie_exit);