Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
#include <linux/miscdevice.h> #include <linux/sysfs.h> #include <linux/fs.h> #include <linux/uaccess.h> #include <linux/delay.h> #include <linux/ioctl.h> #include <linux/err.h> #include <linux/errno.h> #include <linux/module.h> #include <linux/platform_device.h> #include <asm/io.h> #include "sr2351_fm_ctrl.h" #ifdef CONFIG_OF #include <linux/device.h> #include <linux/platform_device.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/of_irq.h> #endif #define SR2351_FM_VERSION "v0.9" static u32 g_volume = 0; int sr2351_fm_set_volume(u32 iarg) { SR2351_PRINT("FM set volume : %i.", iarg); g_volume = iarg; if(0 == iarg) { sr2351_fm_mute(); } else { sr2351_fm_unmute(); } return 0; } u32 sr2351_fm_get_volume(void) { SR2351_PRINT("FM get volume."); return g_volume; } int sr2351_fm_open(struct inode *inode, struct file *filep) { int ret = -EINVAL; int status; SR2351_PRINT("start open shark fm module..."); /* if (get_suspend_state() != PM_SUSPEND_ON) { SR2351_PRINT("The system is suspending!"); return -2; } */ /* ret = nonseekable_open(inode, filep); if (ret < 0) { SR2351_PRINT("open misc device failed."); return ret; } */ ret = sr2351_fm_init(); if (ret < 0) { SR2351_PRINT("sr2351_fm_init failed!"); return ret; } ret = sr2351_fm_get_status(&status); if (ret < 0) { SR2351_PRINT("sr2351_read_fm_en failed!"); return ret; } if (status) { SR2351_PRINT("sr2351 fm have been opened."); } else { ret = sr2351_fm_en(); if (ret < 0) { SR2351_PRINT("sr2351_fm_en failed!"); return ret; } } SR2351_PRINT("Open shark fm module success."); return 0; } long sr2351_fm_ioctl(struct file *filep, unsigned int cmd, unsigned long arg) { void __user *argp = (void __user *)arg; long ret = 0; u32 iarg = 0; u32 buf[4] = { 0 }; SR2351_PRINT("FM IOCTL: 0x%x.", cmd); switch (cmd) { case FM_IOCTL_ENABLE: if (copy_from_user(&iarg, argp, sizeof(iarg)) || iarg > 1) ret = -EFAULT; if (iarg == 1) ret = sr2351_fm_en(); else ret = sr2351_fm_dis(); break; case FM_IOCTL_GET_ENABLE: ret = sr2351_fm_get_status(&iarg); if (copy_to_user(argp, &iarg, sizeof(iarg))) ret = -EFAULT; break; case FM_IOCTL_SET_TUNE: if (copy_from_user(&iarg, argp, sizeof(iarg))) return -EFAULT; sr2351_fm_mute(); ret = sr2351_fm_set_tune(iarg); sr2351_fm_unmute(); break; case FM_IOCTL_GET_FREQ: ret = sr2351_fm_get_frequency(&iarg); if (copy_to_user(argp, &iarg, sizeof(iarg))) ret = -EFAULT; break; case FM_IOCTL_SEARCH: if (copy_from_user(buf, argp, sizeof(buf))) ret = -EFAULT; sr2351_fm_mute(); ret = sr2351_fm_seek(buf[0], /* start frequency */ buf[1], /* seek direction */ buf[2], /* time out */ &buf[3]); /* frequency found */ if (copy_to_user(argp, buf, sizeof(buf))) ret = -EFAULT; break; case FM_IOCTL_STOP_SEARCH: ret = sr2351_fm_stop_seek(); break; case FM_IOCTL_MUTE: break; case FM_IOCTL_SET_VOLUME: if (copy_from_user(&iarg, argp, sizeof(iarg))) ret = -EFAULT; ret = sr2351_fm_set_volume(iarg); break; case FM_IOCTL_GET_VOLUME: iarg = sr2351_fm_get_volume(); if (copy_to_user(argp, &iarg, sizeof(iarg))) ret = -EFAULT; break; case FM_IOCTL_CONFIG: if (copy_from_user(&iarg, argp, sizeof(iarg))) ret = -EFAULT; SR2351_PRINT("\n\nFM FM_IOCTL_CONFIG set %d\n\n", iarg); break; case FM_IOCTL_GET_RSSI: ret = sr2351_fm_get_rssi(&iarg); if(copy_to_user(argp,&iarg,sizeof(iarg))) ret = -EFAULT; break; case FM_IOCTL_SET_BAND: if (copy_from_user(buf, argp, sizeof(buf))) ret = -EFAULT; ret = sr2351_fm_set_band(buf[0],//min freq buf[1]);//max freq break; default: SR2351_PRINT("Unknown FM IOCTL!"); return -EINVAL; } return ret; } int sr2351_fm_release(struct inode *inode, struct file *filep) { SR2351_PRINT("sr2351_fm_misc_release"); sr2351_fm_deinit(); return 0; } const struct file_operations sr2351_fm_misc_fops = { .owner = THIS_MODULE, .open = sr2351_fm_open, .unlocked_ioctl = sr2351_fm_ioctl, .release = sr2351_fm_release, }; struct miscdevice sr2351_fm_misc_device = { .minor = MISC_DYNAMIC_MINOR, .name = SR2351_FM_DEV_NAME, .fops = &sr2351_fm_misc_fops, }; #ifdef CONFIG_OF static struct sr2351_fm_addr { unsigned long fm_base; unsigned long apb_base; unsigned long pmu_base; unsigned long aonckg_base; unsigned long pin_base; }sr2351_fm_base; unsigned long rf2351_fm_get_fm_base(void) { return sr2351_fm_base.fm_base; } unsigned long rf2351_fm_get_apb_base(void) { return sr2351_fm_base.apb_base; } unsigned long rf2351_fm_get_pmu_base(void) { return sr2351_fm_base.pmu_base; } unsigned long rf2351_fm_get_aonckg_base(void) { return sr2351_fm_base.aonckg_base; } unsigned long rf2351_fm_get_pin_base(void) { return sr2351_fm_base.pin_base; } static int sr2351_fm_parse_dts(struct device_node *np) { int ret; struct resource res; //np = of_find_node_by_name(NULL, "sprd_fm"); if (NULL == np) { SR2351_PRINT("Can't get the sprd_fm node!\n"); return -ENODEV; } SR2351_PRINT(" find the fm_sr2351 node!\n"); ret = of_address_to_resource(np, 0, &res); if (ret < 0) { SR2351_PRINT("Can't get the fm reg base!\n"); return -EIO; } sr2351_fm_base.fm_base = (unsigned long)ioremap_nocache(res.start, resource_size(&res)); if(!sr2351_fm_base.fm_base) { BUG(); } SR2351_PRINT("fm reg base is 0x%x\n", sr2351_fm_base.fm_base); ret = of_address_to_resource(np, 1, &res); if (ret < 0) { SR2351_PRINT("Can't get the apb reg base!\n"); return -EIO; } sr2351_fm_base.apb_base = (unsigned long)ioremap_nocache(res.start, resource_size(&res)); if(!sr2351_fm_base.apb_base) { BUG(); } SR2351_PRINT("apb reg base is 0x%x\n", sr2351_fm_base.apb_base); ret = of_address_to_resource(np, 2, &res); if (ret < 0) { SR2351_PRINT("Can't get the pmu reg base!\n"); return -EIO; } sr2351_fm_base.pmu_base = (unsigned long)ioremap_nocache(res.start, resource_size(&res)); if(!sr2351_fm_base.pmu_base) { BUG(); } SR2351_PRINT("pmu reg base is 0x%x\n", sr2351_fm_base.pmu_base); ret = of_address_to_resource(np, 3, &res); if (ret < 0) { SR2351_PRINT("Can't get the aonckg reg base!\n"); return -EIO; } sr2351_fm_base.aonckg_base = (unsigned long)ioremap_nocache(res.start, resource_size(&res)); if(!sr2351_fm_base.aonckg_base) { BUG(); } SR2351_PRINT("pmu reg base is 0x%x\n", sr2351_fm_base.aonckg_base); ret = of_address_to_resource(np, 4, &res); if (ret < 0) { SR2351_PRINT("Can't get the pin reg base!\n"); return -EIO; } sr2351_fm_base.pin_base = (unsigned long)ioremap_nocache(res.start, resource_size(&res)); if(!sr2351_fm_base.pin_base) { BUG(); } SR2351_PRINT("pin reg base is 0x%x\n", sr2351_fm_base.pin_base); return 0; } static const struct of_device_id of_match_table_fm[] = { { .compatible = "sprd,sprd_fm", }, { }, }; MODULE_DEVICE_TABLE(of, of_match_table_fm); #endif static int sr2351_fm_probe(struct platform_device *pdev) { int ret = -EINVAL; char *ver_str = SR2351_FM_VERSION; #ifdef CONFIG_OF struct device_node *np; np = pdev->dev.of_node; ret = sr2351_fm_parse_dts(np); if (ret < 0) { SR2351_PRINT("sr2351_fm_parse_dts failed!"); return ret; } #endif SR2351_PRINT("**********************************************"); SR2351_PRINT(" SR2351 FM driver "); SR2351_PRINT(" Version: %s", ver_str); SR2351_PRINT(" Build date: %s %s", __DATE__, __TIME__); SR2351_PRINT("**********************************************"); ret = misc_register(&sr2351_fm_misc_device); if (ret < 0) { SR2351_PRINT("misc_register failed!"); return ret; } SR2351_PRINT("sr2351_fm_init success.\n"); return 0; } static int sr2351_fm_remove(struct platform_device *pdev) { SR2351_PRINT("exit_fm_driver!\n"); misc_deregister(&sr2351_fm_misc_device); return 0; } #ifdef CONFIG_PM static int sr2351_fm_suspend(struct platform_device *dev, pm_message_t state) { sr2351_fm_enter_sleep(); return 0; } static int sr2351_fm_resume(struct platform_device *dev) { sr2351_fm_exit_sleep(); return 0; } #else #define sr2351_fmt_suspend NULL #define sr2351_fm_resume NULL #endif static struct platform_driver sr2351_fm_driver = { .driver = { .name = "sprd_fm", .owner = THIS_MODULE, #ifdef CONFIG_OF .of_match_table = of_match_ptr(of_match_table_fm) , #endif }, .probe = sr2351_fm_probe, .remove = sr2351_fm_remove, .suspend = sr2351_fm_suspend, .resume = sr2351_fm_resume, }; #ifndef CONFIG_OF struct platform_device sr2351_fm_device = { .name = "sprd_fm", .id = -1, }; #endif int __init init_fm_driver(void) { int ret; #ifndef CONFIG_OF ret = platform_device_register(&sr2351_fm_device); if (ret) { SR2351_PRINT("sr2351_fm: platform_device_register failed: %d\n", ret); return ret; } #endif ret = platform_driver_register(&sr2351_fm_driver); if (ret) { #ifndef CONFIG_OF platform_device_unregister(&sr2351_fm_device); #endif SR2351_PRINT("sr2351_fm: probe failed: %d\n", ret); } SR2351_PRINT("sr2351_fm: probe sucess: %d\n", ret); return ret; } void __exit exit_fm_driver(void) { platform_driver_unregister(&sr2351_fm_driver); } module_init(init_fm_driver); module_exit(exit_fm_driver); MODULE_DESCRIPTION("SR2351 FM radio driver"); MODULE_AUTHOR("Spreadtrum Inc."); MODULE_LICENSE("GPL"); MODULE_VERSION(SR2351_FM_VERSION);
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Untitled
49 sec ago | 0.31 KB
Untitled
3 min ago | 0.92 KB
Untitled
5 min ago | 0.67 KB
Untitled
6 min ago | 0.46 KB
Untitled
7 min ago | 0.61 KB
Untitled
8 min ago | 2.08 KB
Untitled
9 min ago | 0.86 KB
Untitled
9 min ago | 0.53 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!