soc.h 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  1. /*
  2. * linux/sound/soc.h -- ALSA SoC Layer
  3. *
  4. * Author: Liam Girdwood
  5. * Created: Aug 11th 2005
  6. * Copyright: Wolfson Microelectronics. PLC.
  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. #ifndef __LINUX_SND_SOC_H
  13. #define __LINUX_SND_SOC_H
  14. #include <linux/platform_device.h>
  15. #include <linux/types.h>
  16. #include <linux/notifier.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/kernel.h>
  20. #include <linux/regmap.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/control.h>
  24. #include <sound/ac97_codec.h>
  25. /*
  26. * Convenience kcontrol builders
  27. */
  28. #define SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, xmax, xinvert) \
  29. ((unsigned long)&(struct soc_mixer_control) \
  30. {.reg = xreg, .rreg = xreg, .shift = shift_left, \
  31. .rshift = shift_right, .max = xmax, .platform_max = xmax, \
  32. .invert = xinvert})
  33. #define SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) \
  34. SOC_DOUBLE_VALUE(xreg, xshift, xshift, xmax, xinvert)
  35. #define SOC_SINGLE_VALUE_EXT(xreg, xmax, xinvert) \
  36. ((unsigned long)&(struct soc_mixer_control) \
  37. {.reg = xreg, .max = xmax, .platform_max = xmax, .invert = xinvert})
  38. #define SOC_DOUBLE_R_VALUE(xlreg, xrreg, xshift, xmax, xinvert) \
  39. ((unsigned long)&(struct soc_mixer_control) \
  40. {.reg = xlreg, .rreg = xrreg, .shift = xshift, .rshift = xshift, \
  41. .max = xmax, .platform_max = xmax, .invert = xinvert})
  42. #define SOC_SINGLE(xname, reg, shift, max, invert) \
  43. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  44. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  45. .put = snd_soc_put_volsw, \
  46. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  47. #define SOC_SINGLE_TLV(xname, reg, shift, max, invert, tlv_array) \
  48. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  49. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  50. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  51. .tlv.p = (tlv_array), \
  52. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw,\
  53. .put = snd_soc_put_volsw, \
  54. .private_value = SOC_SINGLE_VALUE(reg, shift, max, invert) }
  55. #define SOC_DOUBLE(xname, reg, shift_left, shift_right, max, invert) \
  56. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  57. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  58. .put = snd_soc_put_volsw, \
  59. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  60. max, invert) }
  61. #define SOC_DOUBLE_R(xname, reg_left, reg_right, xshift, xmax, xinvert) \
  62. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  63. .info = snd_soc_info_volsw, \
  64. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  65. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  66. xmax, xinvert) }
  67. #define SOC_DOUBLE_TLV(xname, reg, shift_left, shift_right, max, invert, tlv_array) \
  68. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  69. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  70. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  71. .tlv.p = (tlv_array), \
  72. .info = snd_soc_info_volsw, .get = snd_soc_get_volsw, \
  73. .put = snd_soc_put_volsw, \
  74. .private_value = SOC_DOUBLE_VALUE(reg, shift_left, shift_right, \
  75. max, invert) }
  76. #define SOC_DOUBLE_R_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert, tlv_array) \
  77. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  78. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  79. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  80. .tlv.p = (tlv_array), \
  81. .info = snd_soc_info_volsw, \
  82. .get = snd_soc_get_volsw, .put = snd_soc_put_volsw, \
  83. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  84. xmax, xinvert) }
  85. #define SOC_DOUBLE_S8_TLV(xname, xreg, xmin, xmax, tlv_array) \
  86. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  87. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  88. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  89. .tlv.p = (tlv_array), \
  90. .info = snd_soc_info_volsw_s8, .get = snd_soc_get_volsw_s8, \
  91. .put = snd_soc_put_volsw_s8, \
  92. .private_value = (unsigned long)&(struct soc_mixer_control) \
  93. {.reg = xreg, .min = xmin, .max = xmax, \
  94. .platform_max = xmax} }
  95. #define SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmax, xtexts) \
  96. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  97. .max = xmax, .texts = xtexts }
  98. #define SOC_ENUM_SINGLE(xreg, xshift, xmax, xtexts) \
  99. SOC_ENUM_DOUBLE(xreg, xshift, xshift, xmax, xtexts)
  100. #define SOC_ENUM_SINGLE_EXT(xmax, xtexts) \
  101. { .max = xmax, .texts = xtexts }
  102. #define SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, xmax, xtexts, xvalues) \
  103. { .reg = xreg, .shift_l = xshift_l, .shift_r = xshift_r, \
  104. .mask = xmask, .max = xmax, .texts = xtexts, .values = xvalues}
  105. #define SOC_VALUE_ENUM_SINGLE(xreg, xshift, xmask, xmax, xtexts, xvalues) \
  106. SOC_VALUE_ENUM_DOUBLE(xreg, xshift, xshift, xmask, xmax, xtexts, xvalues)
  107. #define SOC_ENUM(xname, xenum) \
  108. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  109. .info = snd_soc_info_enum_double, \
  110. .get = snd_soc_get_enum_double, .put = snd_soc_put_enum_double, \
  111. .private_value = (unsigned long)&xenum }
  112. #define SOC_VALUE_ENUM(xname, xenum) \
  113. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname,\
  114. .info = snd_soc_info_enum_double, \
  115. .get = snd_soc_get_value_enum_double, \
  116. .put = snd_soc_put_value_enum_double, \
  117. .private_value = (unsigned long)&xenum }
  118. #define SOC_SINGLE_EXT(xname, xreg, xshift, xmax, xinvert,\
  119. xhandler_get, xhandler_put) \
  120. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  121. .info = snd_soc_info_volsw, \
  122. .get = xhandler_get, .put = xhandler_put, \
  123. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  124. #define SOC_DOUBLE_EXT(xname, reg, shift_left, shift_right, max, invert,\
  125. xhandler_get, xhandler_put) \
  126. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname),\
  127. .info = snd_soc_info_volsw, \
  128. .get = xhandler_get, .put = xhandler_put, \
  129. .private_value = \
  130. SOC_DOUBLE_VALUE(reg, shift_left, shift_right, max, invert) }
  131. #define SOC_SINGLE_EXT_TLV(xname, xreg, xshift, xmax, xinvert,\
  132. xhandler_get, xhandler_put, tlv_array) \
  133. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  134. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
  135. SNDRV_CTL_ELEM_ACCESS_READWRITE,\
  136. .tlv.p = (tlv_array), \
  137. .info = snd_soc_info_volsw, \
  138. .get = xhandler_get, .put = xhandler_put, \
  139. .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
  140. #define SOC_DOUBLE_EXT_TLV(xname, xreg, shift_left, shift_right, xmax, xinvert,\
  141. xhandler_get, xhandler_put, tlv_array) \
  142. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  143. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  144. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  145. .tlv.p = (tlv_array), \
  146. .info = snd_soc_info_volsw, \
  147. .get = xhandler_get, .put = xhandler_put, \
  148. .private_value = SOC_DOUBLE_VALUE(xreg, shift_left, shift_right, \
  149. xmax, xinvert) }
  150. #define SOC_DOUBLE_R_EXT_TLV(xname, reg_left, reg_right, xshift, xmax, xinvert,\
  151. xhandler_get, xhandler_put, tlv_array) \
  152. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  153. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  154. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  155. .tlv.p = (tlv_array), \
  156. .info = snd_soc_info_volsw, \
  157. .get = xhandler_get, .put = xhandler_put, \
  158. .private_value = SOC_DOUBLE_R_VALUE(reg_left, reg_right, xshift, \
  159. xmax, xinvert) }
  160. #define SOC_SINGLE_BOOL_EXT(xname, xdata, xhandler_get, xhandler_put) \
  161. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  162. .info = snd_soc_info_bool_ext, \
  163. .get = xhandler_get, .put = xhandler_put, \
  164. .private_value = xdata }
  165. #define SOC_ENUM_EXT(xname, xenum, xhandler_get, xhandler_put) \
  166. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  167. .info = snd_soc_info_enum_ext, \
  168. .get = xhandler_get, .put = xhandler_put, \
  169. .private_value = (unsigned long)&xenum }
  170. #define SOC_DOUBLE_R_SX_TLV(xname, xreg_left, xreg_right, xshift,\
  171. xmin, xmax, tlv_array) \
  172. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
  173. .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
  174. SNDRV_CTL_ELEM_ACCESS_READWRITE, \
  175. .tlv.p = (tlv_array), \
  176. .info = snd_soc_info_volsw_2r_sx, \
  177. .get = snd_soc_get_volsw_2r_sx, \
  178. .put = snd_soc_put_volsw_2r_sx, \
  179. .private_value = (unsigned long)&(struct soc_mixer_control) \
  180. {.reg = xreg_left, \
  181. .rreg = xreg_right, .shift = xshift, \
  182. .min = xmin, .max = xmax} }
  183. #define SND_SOC_BYTES(xname, xbase, xregs) \
  184. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  185. .info = snd_soc_bytes_info, .get = snd_soc_bytes_get, \
  186. .put = snd_soc_bytes_put, .private_value = \
  187. ((unsigned long)&(struct soc_bytes) \
  188. {.base = xbase, .num_regs = xregs }) }
  189. /*
  190. * Simplified versions of above macros, declaring a struct and calculating
  191. * ARRAY_SIZE internally
  192. */
  193. #define SOC_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xtexts) \
  194. struct soc_enum name = SOC_ENUM_DOUBLE(xreg, xshift_l, xshift_r, \
  195. ARRAY_SIZE(xtexts), xtexts)
  196. #define SOC_ENUM_SINGLE_DECL(name, xreg, xshift, xtexts) \
  197. SOC_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xtexts)
  198. #define SOC_ENUM_SINGLE_EXT_DECL(name, xtexts) \
  199. struct soc_enum name = SOC_ENUM_SINGLE_EXT(ARRAY_SIZE(xtexts), xtexts)
  200. #define SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift_l, xshift_r, xmask, xtexts, xvalues) \
  201. struct soc_enum name = SOC_VALUE_ENUM_DOUBLE(xreg, xshift_l, xshift_r, xmask, \
  202. ARRAY_SIZE(xtexts), xtexts, xvalues)
  203. #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
  204. SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
  205. /*
  206. * Component probe and remove ordering levels for components with runtime
  207. * dependencies.
  208. */
  209. #define SND_SOC_COMP_ORDER_FIRST -2
  210. #define SND_SOC_COMP_ORDER_EARLY -1
  211. #define SND_SOC_COMP_ORDER_NORMAL 0
  212. #define SND_SOC_COMP_ORDER_LATE 1
  213. #define SND_SOC_COMP_ORDER_LAST 2
  214. /*
  215. * Bias levels
  216. *
  217. * @ON: Bias is fully on for audio playback and capture operations.
  218. * @PREPARE: Prepare for audio operations. Called before DAPM switching for
  219. * stream start and stop operations.
  220. * @STANDBY: Low power standby state when no playback/capture operations are
  221. * in progress. NOTE: The transition time between STANDBY and ON
  222. * should be as fast as possible and no longer than 10ms.
  223. * @OFF: Power Off. No restrictions on transition times.
  224. */
  225. enum snd_soc_bias_level {
  226. SND_SOC_BIAS_OFF = 0,
  227. SND_SOC_BIAS_STANDBY = 1,
  228. SND_SOC_BIAS_PREPARE = 2,
  229. SND_SOC_BIAS_ON = 3,
  230. };
  231. struct device_node;
  232. struct snd_jack;
  233. struct snd_soc_card;
  234. struct snd_soc_pcm_stream;
  235. struct snd_soc_ops;
  236. struct snd_soc_pcm_runtime;
  237. struct snd_soc_dai;
  238. struct snd_soc_dai_driver;
  239. struct snd_soc_platform;
  240. struct snd_soc_dai_link;
  241. struct snd_soc_platform_driver;
  242. struct snd_soc_codec;
  243. struct snd_soc_codec_driver;
  244. struct soc_enum;
  245. struct snd_soc_jack;
  246. struct snd_soc_jack_zone;
  247. struct snd_soc_jack_pin;
  248. struct snd_soc_cache_ops;
  249. #include <sound/soc-dapm.h>
  250. #ifdef CONFIG_GPIOLIB
  251. struct snd_soc_jack_gpio;
  252. #endif
  253. typedef int (*hw_write_t)(void *,const char* ,int);
  254. extern struct snd_ac97_bus_ops soc_ac97_ops;
  255. enum snd_soc_control_type {
  256. SND_SOC_I2C = 1,
  257. SND_SOC_SPI,
  258. SND_SOC_REGMAP,
  259. };
  260. enum snd_soc_compress_type {
  261. SND_SOC_FLAT_COMPRESSION = 1,
  262. };
  263. enum snd_soc_pcm_subclass {
  264. SND_SOC_PCM_CLASS_PCM = 0,
  265. SND_SOC_PCM_CLASS_BE = 1,
  266. };
  267. int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
  268. int source, unsigned int freq, int dir);
  269. int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
  270. unsigned int freq_in, unsigned int freq_out);
  271. int snd_soc_register_card(struct snd_soc_card *card);
  272. int snd_soc_unregister_card(struct snd_soc_card *card);
  273. int snd_soc_suspend(struct device *dev);
  274. int snd_soc_resume(struct device *dev);
  275. int snd_soc_poweroff(struct device *dev);
  276. int snd_soc_register_platform(struct device *dev,
  277. struct snd_soc_platform_driver *platform_drv);
  278. void snd_soc_unregister_platform(struct device *dev);
  279. int snd_soc_register_codec(struct device *dev,
  280. const struct snd_soc_codec_driver *codec_drv,
  281. struct snd_soc_dai_driver *dai_drv, int num_dai);
  282. void snd_soc_unregister_codec(struct device *dev);
  283. int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
  284. unsigned int reg);
  285. int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
  286. unsigned int reg);
  287. int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
  288. unsigned int reg);
  289. int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
  290. int addr_bits, int data_bits,
  291. enum snd_soc_control_type control);
  292. int snd_soc_cache_sync(struct snd_soc_codec *codec);
  293. int snd_soc_cache_init(struct snd_soc_codec *codec);
  294. int snd_soc_cache_exit(struct snd_soc_codec *codec);
  295. int snd_soc_cache_write(struct snd_soc_codec *codec,
  296. unsigned int reg, unsigned int value);
  297. int snd_soc_cache_read(struct snd_soc_codec *codec,
  298. unsigned int reg, unsigned int *value);
  299. int snd_soc_default_volatile_register(struct snd_soc_codec *codec,
  300. unsigned int reg);
  301. int snd_soc_default_readable_register(struct snd_soc_codec *codec,
  302. unsigned int reg);
  303. int snd_soc_default_writable_register(struct snd_soc_codec *codec,
  304. unsigned int reg);
  305. int snd_soc_platform_read(struct snd_soc_platform *platform,
  306. unsigned int reg);
  307. int snd_soc_platform_write(struct snd_soc_platform *platform,
  308. unsigned int reg, unsigned int val);
  309. int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
  310. /* Utility functions to get clock rates from various things */
  311. int snd_soc_calc_frame_size(int sample_size, int channels, int tdm_slots);
  312. int snd_soc_params_to_frame_size(struct snd_pcm_hw_params *params);
  313. int snd_soc_calc_bclk(int fs, int sample_size, int channels, int tdm_slots);
  314. int snd_soc_params_to_bclk(struct snd_pcm_hw_params *parms);
  315. /* set runtime hw params */
  316. int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
  317. const struct snd_pcm_hardware *hw);
  318. /* Jack reporting */
  319. int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
  320. struct snd_soc_jack *jack);
  321. void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
  322. int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
  323. struct snd_soc_jack_pin *pins);
  324. void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
  325. struct notifier_block *nb);
  326. void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
  327. struct notifier_block *nb);
  328. int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
  329. struct snd_soc_jack_zone *zones);
  330. int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
  331. #ifdef CONFIG_GPIOLIB
  332. int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
  333. struct snd_soc_jack_gpio *gpios);
  334. void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
  335. struct snd_soc_jack_gpio *gpios);
  336. #endif
  337. /* codec register bit access */
  338. int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
  339. unsigned int mask, unsigned int value);
  340. int snd_soc_update_bits_locked(struct snd_soc_codec *codec,
  341. unsigned short reg, unsigned int mask,
  342. unsigned int value);
  343. int snd_soc_test_bits(struct snd_soc_codec *codec, unsigned short reg,
  344. unsigned int mask, unsigned int value);
  345. int snd_soc_new_ac97_codec(struct snd_soc_codec *codec,
  346. struct snd_ac97_bus_ops *ops, int num);
  347. void snd_soc_free_ac97_codec(struct snd_soc_codec *codec);
  348. /*
  349. *Controls
  350. */
  351. struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
  352. void *data, const char *long_name,
  353. const char *prefix);
  354. int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
  355. const struct snd_kcontrol_new *controls, int num_controls);
  356. int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
  357. const struct snd_kcontrol_new *controls, int num_controls);
  358. int snd_soc_add_card_controls(struct snd_soc_card *soc_card,
  359. const struct snd_kcontrol_new *controls, int num_controls);
  360. int snd_soc_add_dai_controls(struct snd_soc_dai *dai,
  361. const struct snd_kcontrol_new *controls, int num_controls);
  362. int snd_soc_info_enum_double(struct snd_kcontrol *kcontrol,
  363. struct snd_ctl_elem_info *uinfo);
  364. int snd_soc_info_enum_ext(struct snd_kcontrol *kcontrol,
  365. struct snd_ctl_elem_info *uinfo);
  366. int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
  367. struct snd_ctl_elem_value *ucontrol);
  368. int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol,
  369. struct snd_ctl_elem_value *ucontrol);
  370. int snd_soc_get_value_enum_double(struct snd_kcontrol *kcontrol,
  371. struct snd_ctl_elem_value *ucontrol);
  372. int snd_soc_put_value_enum_double(struct snd_kcontrol *kcontrol,
  373. struct snd_ctl_elem_value *ucontrol);
  374. int snd_soc_info_volsw(struct snd_kcontrol *kcontrol,
  375. struct snd_ctl_elem_info *uinfo);
  376. int snd_soc_info_volsw_ext(struct snd_kcontrol *kcontrol,
  377. struct snd_ctl_elem_info *uinfo);
  378. #define snd_soc_info_bool_ext snd_ctl_boolean_mono_info
  379. int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
  380. struct snd_ctl_elem_value *ucontrol);
  381. int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
  382. struct snd_ctl_elem_value *ucontrol);
  383. #define snd_soc_get_volsw_2r snd_soc_get_volsw
  384. #define snd_soc_put_volsw_2r snd_soc_put_volsw
  385. int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
  386. struct snd_ctl_elem_info *uinfo);
  387. int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
  388. struct snd_ctl_elem_value *ucontrol);
  389. int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
  390. struct snd_ctl_elem_value *ucontrol);
  391. int snd_soc_limit_volume(struct snd_soc_codec *codec,
  392. const char *name, int max);
  393. int snd_soc_info_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  394. struct snd_ctl_elem_info *uinfo);
  395. int snd_soc_get_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  396. struct snd_ctl_elem_value *ucontrol);
  397. int snd_soc_put_volsw_2r_sx(struct snd_kcontrol *kcontrol,
  398. struct snd_ctl_elem_value *ucontrol);
  399. int snd_soc_bytes_info(struct snd_kcontrol *kcontrol,
  400. struct snd_ctl_elem_info *uinfo);
  401. int snd_soc_bytes_get(struct snd_kcontrol *kcontrol,
  402. struct snd_ctl_elem_value *ucontrol);
  403. int snd_soc_bytes_put(struct snd_kcontrol *kcontrol,
  404. struct snd_ctl_elem_value *ucontrol);
  405. /**
  406. * struct snd_soc_reg_access - Describes whether a given register is
  407. * readable, writable or volatile.
  408. *
  409. * @reg: the register number
  410. * @read: whether this register is readable
  411. * @write: whether this register is writable
  412. * @vol: whether this register is volatile
  413. */
  414. struct snd_soc_reg_access {
  415. u16 reg;
  416. u16 read;
  417. u16 write;
  418. u16 vol;
  419. };
  420. /**
  421. * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
  422. *
  423. * @pin: name of the pin to update
  424. * @mask: bits to check for in reported jack status
  425. * @invert: if non-zero then pin is enabled when status is not reported
  426. */
  427. struct snd_soc_jack_pin {
  428. struct list_head list;
  429. const char *pin;
  430. int mask;
  431. bool invert;
  432. };
  433. /**
  434. * struct snd_soc_jack_zone - Describes voltage zones of jack detection
  435. *
  436. * @min_mv: start voltage in mv
  437. * @max_mv: end voltage in mv
  438. * @jack_type: type of jack that is expected for this voltage
  439. * @debounce_time: debounce_time for jack, codec driver should wait for this
  440. * duration before reading the adc for voltages
  441. * @:list: list container
  442. */
  443. struct snd_soc_jack_zone {
  444. unsigned int min_mv;
  445. unsigned int max_mv;
  446. unsigned int jack_type;
  447. unsigned int debounce_time;
  448. struct list_head list;
  449. };
  450. /**
  451. * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
  452. *
  453. * @gpio: gpio number
  454. * @name: gpio name
  455. * @report: value to report when jack detected
  456. * @invert: report presence in low state
  457. * @debouce_time: debouce time in ms
  458. * @wake: enable as wake source
  459. * @jack_status_check: callback function which overrides the detection
  460. * to provide more complex checks (eg, reading an
  461. * ADC).
  462. */
  463. #ifdef CONFIG_GPIOLIB
  464. struct snd_soc_jack_gpio {
  465. unsigned int gpio;
  466. const char *name;
  467. int report;
  468. int invert;
  469. int debounce_time;
  470. bool wake;
  471. struct snd_soc_jack *jack;
  472. struct delayed_work work;
  473. int (*jack_status_check)(void);
  474. };
  475. #endif
  476. struct snd_soc_jack {
  477. struct snd_jack *jack;
  478. struct snd_soc_codec *codec;
  479. struct list_head pins;
  480. int status;
  481. struct blocking_notifier_head notifier;
  482. struct list_head jack_zones;
  483. };
  484. /* SoC PCM stream information */
  485. struct snd_soc_pcm_stream {
  486. const char *stream_name;
  487. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  488. unsigned int rates; /* SNDRV_PCM_RATE_* */
  489. unsigned int rate_min; /* min rate */
  490. unsigned int rate_max; /* max rate */
  491. unsigned int channels_min; /* min channels */
  492. unsigned int channels_max; /* max channels */
  493. unsigned int sig_bits; /* number of bits of content */
  494. };
  495. /* SoC audio ops */
  496. struct snd_soc_ops {
  497. int (*startup)(struct snd_pcm_substream *);
  498. void (*shutdown)(struct snd_pcm_substream *);
  499. int (*hw_params)(struct snd_pcm_substream *, struct snd_pcm_hw_params *);
  500. int (*hw_free)(struct snd_pcm_substream *);
  501. int (*prepare)(struct snd_pcm_substream *);
  502. int (*trigger)(struct snd_pcm_substream *, int);
  503. };
  504. /* SoC cache ops */
  505. struct snd_soc_cache_ops {
  506. const char *name;
  507. enum snd_soc_compress_type id;
  508. int (*init)(struct snd_soc_codec *codec);
  509. int (*exit)(struct snd_soc_codec *codec);
  510. int (*read)(struct snd_soc_codec *codec, unsigned int reg,
  511. unsigned int *value);
  512. int (*write)(struct snd_soc_codec *codec, unsigned int reg,
  513. unsigned int value);
  514. int (*sync)(struct snd_soc_codec *codec);
  515. };
  516. /* SoC Audio Codec device */
  517. struct snd_soc_codec {
  518. const char *name;
  519. const char *name_prefix;
  520. int id;
  521. struct device *dev;
  522. const struct snd_soc_codec_driver *driver;
  523. struct mutex mutex;
  524. struct snd_soc_card *card;
  525. struct list_head list;
  526. struct list_head card_list;
  527. int num_dai;
  528. enum snd_soc_compress_type compress_type;
  529. size_t reg_size; /* reg_cache_size * reg_word_size */
  530. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  531. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  532. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  533. /* runtime */
  534. struct snd_ac97 *ac97; /* for ad-hoc ac97 devices */
  535. unsigned int active;
  536. unsigned int cache_bypass:1; /* Suppress access to the cache */
  537. unsigned int suspended:1; /* Codec is in suspend PM state */
  538. unsigned int probed:1; /* Codec has been probed */
  539. unsigned int ac97_registered:1; /* Codec has been AC97 registered */
  540. unsigned int ac97_created:1; /* Codec has been created by SoC */
  541. unsigned int sysfs_registered:1; /* codec has been sysfs registered */
  542. unsigned int cache_init:1; /* codec cache has been initialized */
  543. unsigned int using_regmap:1; /* using regmap access */
  544. u32 cache_only; /* Suppress writes to hardware */
  545. u32 cache_sync; /* Cache needs to be synced to hardware */
  546. /* codec IO */
  547. void *control_data; /* codec control (i2c/3wire) data */
  548. enum snd_soc_control_type control_type;
  549. hw_write_t hw_write;
  550. unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
  551. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  552. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  553. int (*bulk_write_raw)(struct snd_soc_codec *, unsigned int, const void *, size_t);
  554. void *reg_cache;
  555. const void *reg_def_copy;
  556. const struct snd_soc_cache_ops *cache_ops;
  557. struct mutex cache_rw_mutex;
  558. int val_bytes;
  559. /* dapm */
  560. struct snd_soc_dapm_context dapm;
  561. unsigned int ignore_pmdown_time:1; /* pmdown_time is ignored at stop */
  562. #ifdef CONFIG_DEBUG_FS
  563. struct dentry *debugfs_codec_root;
  564. struct dentry *debugfs_reg;
  565. struct dentry *debugfs_dapm;
  566. #endif
  567. };
  568. /* codec driver */
  569. struct snd_soc_codec_driver {
  570. /* driver ops */
  571. int (*probe)(struct snd_soc_codec *);
  572. int (*remove)(struct snd_soc_codec *);
  573. int (*suspend)(struct snd_soc_codec *);
  574. int (*resume)(struct snd_soc_codec *);
  575. /* Default control and setup, added after probe() is run */
  576. const struct snd_kcontrol_new *controls;
  577. int num_controls;
  578. const struct snd_soc_dapm_widget *dapm_widgets;
  579. int num_dapm_widgets;
  580. const struct snd_soc_dapm_route *dapm_routes;
  581. int num_dapm_routes;
  582. /* codec wide operations */
  583. int (*set_sysclk)(struct snd_soc_codec *codec,
  584. int clk_id, int source, unsigned int freq, int dir);
  585. int (*set_pll)(struct snd_soc_codec *codec, int pll_id, int source,
  586. unsigned int freq_in, unsigned int freq_out);
  587. /* codec IO */
  588. unsigned int (*read)(struct snd_soc_codec *, unsigned int);
  589. int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
  590. int (*display_register)(struct snd_soc_codec *, char *,
  591. size_t, unsigned int);
  592. int (*volatile_register)(struct snd_soc_codec *, unsigned int);
  593. int (*readable_register)(struct snd_soc_codec *, unsigned int);
  594. int (*writable_register)(struct snd_soc_codec *, unsigned int);
  595. unsigned int reg_cache_size;
  596. short reg_cache_step;
  597. short reg_word_size;
  598. const void *reg_cache_default;
  599. short reg_access_size;
  600. const struct snd_soc_reg_access *reg_access_default;
  601. enum snd_soc_compress_type compress_type;
  602. /* codec bias level */
  603. int (*set_bias_level)(struct snd_soc_codec *,
  604. enum snd_soc_bias_level level);
  605. bool idle_bias_off;
  606. void (*seq_notifier)(struct snd_soc_dapm_context *,
  607. enum snd_soc_dapm_type, int);
  608. /* codec stream completion event */
  609. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  610. bool ignore_pmdown_time; /* Doesn't benefit from pmdown delay */
  611. /* probe ordering - for components with runtime dependencies */
  612. int probe_order;
  613. int remove_order;
  614. };
  615. /* SoC platform interface */
  616. struct snd_soc_platform_driver {
  617. int (*probe)(struct snd_soc_platform *);
  618. int (*remove)(struct snd_soc_platform *);
  619. int (*suspend)(struct snd_soc_dai *dai);
  620. int (*resume)(struct snd_soc_dai *dai);
  621. /* pcm creation and destruction */
  622. int (*pcm_new)(struct snd_soc_pcm_runtime *);
  623. void (*pcm_free)(struct snd_pcm *);
  624. /* Default control and setup, added after probe() is run */
  625. const struct snd_kcontrol_new *controls;
  626. int num_controls;
  627. const struct snd_soc_dapm_widget *dapm_widgets;
  628. int num_dapm_widgets;
  629. const struct snd_soc_dapm_route *dapm_routes;
  630. int num_dapm_routes;
  631. /*
  632. * For platform caused delay reporting.
  633. * Optional.
  634. */
  635. snd_pcm_sframes_t (*delay)(struct snd_pcm_substream *,
  636. struct snd_soc_dai *);
  637. /* platform stream ops */
  638. struct snd_pcm_ops *ops;
  639. /* platform stream completion event */
  640. int (*stream_event)(struct snd_soc_dapm_context *dapm, int event);
  641. /* probe ordering - for components with runtime dependencies */
  642. int probe_order;
  643. int remove_order;
  644. /* platform IO - used for platform DAPM */
  645. unsigned int (*read)(struct snd_soc_platform *, unsigned int);
  646. int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
  647. };
  648. struct snd_soc_platform {
  649. const char *name;
  650. int id;
  651. struct device *dev;
  652. struct snd_soc_platform_driver *driver;
  653. unsigned int suspended:1; /* platform is suspended */
  654. unsigned int probed:1;
  655. struct snd_soc_card *card;
  656. struct list_head list;
  657. struct list_head card_list;
  658. struct snd_soc_dapm_context dapm;
  659. #ifdef CONFIG_DEBUG_FS
  660. struct dentry *debugfs_platform_root;
  661. struct dentry *debugfs_dapm;
  662. #endif
  663. };
  664. struct snd_soc_dai_link {
  665. /* config - must be set by machine driver */
  666. const char *name; /* Codec name */
  667. const char *stream_name; /* Stream name */
  668. const char *codec_name; /* for multi-codec */
  669. const struct device_node *codec_of_node;
  670. const char *platform_name; /* for multi-platform */
  671. const struct device_node *platform_of_node;
  672. const char *cpu_dai_name;
  673. const struct device_node *cpu_dai_of_node;
  674. const char *codec_dai_name;
  675. unsigned int dai_fmt; /* format to set on init */
  676. /* Keep DAI active over suspend */
  677. unsigned int ignore_suspend:1;
  678. /* Symmetry requirements */
  679. unsigned int symmetric_rates:1;
  680. /* pmdown_time is ignored at stop */
  681. unsigned int ignore_pmdown_time:1;
  682. /* codec/machine specific init - e.g. add machine controls */
  683. int (*init)(struct snd_soc_pcm_runtime *rtd);
  684. /* machine stream operations */
  685. struct snd_soc_ops *ops;
  686. };
  687. struct snd_soc_codec_conf {
  688. const char *dev_name;
  689. /*
  690. * optional map of kcontrol, widget and path name prefixes that are
  691. * associated per device
  692. */
  693. const char *name_prefix;
  694. /*
  695. * set this to the desired compression type if you want to
  696. * override the one supplied in codec->driver->compress_type
  697. */
  698. enum snd_soc_compress_type compress_type;
  699. };
  700. struct snd_soc_aux_dev {
  701. const char *name; /* Codec name */
  702. const char *codec_name; /* for multi-codec */
  703. /* codec/machine specific init - e.g. add machine controls */
  704. int (*init)(struct snd_soc_dapm_context *dapm);
  705. };
  706. /* SoC card */
  707. struct snd_soc_card {
  708. const char *name;
  709. const char *long_name;
  710. const char *driver_name;
  711. struct device *dev;
  712. struct snd_card *snd_card;
  713. struct module *owner;
  714. struct list_head list;
  715. struct mutex mutex;
  716. bool instantiated;
  717. int (*probe)(struct snd_soc_card *card);
  718. int (*late_probe)(struct snd_soc_card *card);
  719. int (*remove)(struct snd_soc_card *card);
  720. /* the pre and post PM functions are used to do any PM work before and
  721. * after the codec and DAI's do any PM work. */
  722. int (*suspend_pre)(struct snd_soc_card *card);
  723. int (*suspend_post)(struct snd_soc_card *card);
  724. int (*resume_pre)(struct snd_soc_card *card);
  725. int (*resume_post)(struct snd_soc_card *card);
  726. /* callbacks */
  727. int (*set_bias_level)(struct snd_soc_card *,
  728. struct snd_soc_dapm_context *dapm,
  729. enum snd_soc_bias_level level);
  730. int (*set_bias_level_post)(struct snd_soc_card *,
  731. struct snd_soc_dapm_context *dapm,
  732. enum snd_soc_bias_level level);
  733. long pmdown_time;
  734. /* CPU <--> Codec DAI links */
  735. struct snd_soc_dai_link *dai_link;
  736. int num_links;
  737. struct snd_soc_pcm_runtime *rtd;
  738. int num_rtd;
  739. /* optional codec specific configuration */
  740. struct snd_soc_codec_conf *codec_conf;
  741. int num_configs;
  742. /*
  743. * optional auxiliary devices such as amplifiers or codecs with DAI
  744. * link unused
  745. */
  746. struct snd_soc_aux_dev *aux_dev;
  747. int num_aux_devs;
  748. struct snd_soc_pcm_runtime *rtd_aux;
  749. int num_aux_rtd;
  750. const struct snd_kcontrol_new *controls;
  751. int num_controls;
  752. /*
  753. * Card-specific routes and widgets.
  754. */
  755. const struct snd_soc_dapm_widget *dapm_widgets;
  756. int num_dapm_widgets;
  757. const struct snd_soc_dapm_route *dapm_routes;
  758. int num_dapm_routes;
  759. bool fully_routed;
  760. struct work_struct deferred_resume_work;
  761. /* lists of probed devices belonging to this card */
  762. struct list_head codec_dev_list;
  763. struct list_head platform_dev_list;
  764. struct list_head dai_dev_list;
  765. struct list_head widgets;
  766. struct list_head paths;
  767. struct list_head dapm_list;
  768. struct list_head dapm_dirty;
  769. /* Generic DAPM context for the card */
  770. struct snd_soc_dapm_context dapm;
  771. struct snd_soc_dapm_stats dapm_stats;
  772. #ifdef CONFIG_DEBUG_FS
  773. struct dentry *debugfs_card_root;
  774. struct dentry *debugfs_pop_time;
  775. #endif
  776. u32 pop_time;
  777. void *drvdata;
  778. };
  779. /* SoC machine DAI configuration, glues a codec and cpu DAI together */
  780. struct snd_soc_pcm_runtime {
  781. struct device *dev;
  782. struct snd_soc_card *card;
  783. struct snd_soc_dai_link *dai_link;
  784. struct mutex pcm_mutex;
  785. enum snd_soc_pcm_subclass pcm_subclass;
  786. struct snd_pcm_ops ops;
  787. unsigned int complete:1;
  788. unsigned int dev_registered:1;
  789. long pmdown_time;
  790. /* runtime devices */
  791. struct snd_pcm *pcm;
  792. struct snd_soc_codec *codec;
  793. struct snd_soc_platform *platform;
  794. struct snd_soc_dai *codec_dai;
  795. struct snd_soc_dai *cpu_dai;
  796. struct delayed_work delayed_work;
  797. };
  798. /* mixer control */
  799. struct soc_mixer_control {
  800. int min, max, platform_max;
  801. unsigned int reg, rreg, shift, rshift, invert;
  802. };
  803. struct soc_bytes {
  804. int base;
  805. int num_regs;
  806. };
  807. /* enumerated kcontrol */
  808. struct soc_enum {
  809. unsigned short reg;
  810. unsigned short reg2;
  811. unsigned char shift_l;
  812. unsigned char shift_r;
  813. unsigned int max;
  814. unsigned int mask;
  815. const char * const *texts;
  816. const unsigned int *values;
  817. void *dapm;
  818. };
  819. /* codec IO */
  820. unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
  821. unsigned int snd_soc_write(struct snd_soc_codec *codec,
  822. unsigned int reg, unsigned int val);
  823. unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
  824. unsigned int reg, const void *data, size_t len);
  825. /* device driver data */
  826. static inline void snd_soc_card_set_drvdata(struct snd_soc_card *card,
  827. void *data)
  828. {
  829. card->drvdata = data;
  830. }
  831. static inline void *snd_soc_card_get_drvdata(struct snd_soc_card *card)
  832. {
  833. return card->drvdata;
  834. }
  835. static inline void snd_soc_codec_set_drvdata(struct snd_soc_codec *codec,
  836. void *data)
  837. {
  838. dev_set_drvdata(codec->dev, data);
  839. }
  840. static inline void *snd_soc_codec_get_drvdata(struct snd_soc_codec *codec)
  841. {
  842. return dev_get_drvdata(codec->dev);
  843. }
  844. static inline void snd_soc_platform_set_drvdata(struct snd_soc_platform *platform,
  845. void *data)
  846. {
  847. dev_set_drvdata(platform->dev, data);
  848. }
  849. static inline void *snd_soc_platform_get_drvdata(struct snd_soc_platform *platform)
  850. {
  851. return dev_get_drvdata(platform->dev);
  852. }
  853. static inline void snd_soc_pcm_set_drvdata(struct snd_soc_pcm_runtime *rtd,
  854. void *data)
  855. {
  856. dev_set_drvdata(rtd->dev, data);
  857. }
  858. static inline void *snd_soc_pcm_get_drvdata(struct snd_soc_pcm_runtime *rtd)
  859. {
  860. return dev_get_drvdata(rtd->dev);
  861. }
  862. static inline void snd_soc_initialize_card_lists(struct snd_soc_card *card)
  863. {
  864. INIT_LIST_HEAD(&card->dai_dev_list);
  865. INIT_LIST_HEAD(&card->codec_dev_list);
  866. INIT_LIST_HEAD(&card->platform_dev_list);
  867. INIT_LIST_HEAD(&card->widgets);
  868. INIT_LIST_HEAD(&card->paths);
  869. INIT_LIST_HEAD(&card->dapm_list);
  870. }
  871. static inline bool snd_soc_volsw_is_stereo(struct soc_mixer_control *mc)
  872. {
  873. if (mc->reg == mc->rreg && mc->shift == mc->rshift)
  874. return 0;
  875. /*
  876. * mc->reg == mc->rreg && mc->shift != mc->rshift, or
  877. * mc->reg != mc->rreg means that the control is
  878. * stereo (bits in one register or in two registers)
  879. */
  880. return 1;
  881. }
  882. int snd_soc_util_init(void);
  883. void snd_soc_util_exit(void);
  884. int snd_soc_of_parse_card_name(struct snd_soc_card *card,
  885. const char *propname);
  886. int snd_soc_of_parse_audio_routing(struct snd_soc_card *card,
  887. const char *propname);
  888. #include <sound/soc-dai.h>
  889. #ifdef CONFIG_DEBUG_FS
  890. extern struct dentry *snd_soc_debugfs_root;
  891. #endif
  892. extern const struct dev_pm_ops snd_soc_pm_ops;
  893. #endif