Re: [PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-08-03 Thread Santiago Hormazabal
On Mon, 3 Aug 2020 at 10:05, Hans Verkuil  wrote:
>
> On 03/08/2020 04:09, Santiago Hormazabal wrote:
> > This chip requires almost no support components and can used over I2C.
> > The driver uses the I2C bus and exposes the controls as a V4L2 radio.
> > Tested with a module that contains this chip (from SZZSJDZ.com,
> > part number ZJ-801B, even tho the company seems defunct now), and an H2+
> > AllWinner SoC running a kernel built off 8f2a4a9 of the media_tree.
> >
> > Signed-off-by: Santiago Hormazabal 
> > ---
>
> It's good practice to list the changes you made for a v2 either in the
> cover letter or here (below ---).
>
> I have a preference myself for the cover letter, but either is fine.
>
Will do!

> >  drivers/media/radio/Kconfig|   10 +
> >  drivers/media/radio/Makefile   |1 +
> >  drivers/media/radio/radio-kt0913.c | 1196 
> >  3 files changed, 1207 insertions(+)
> >  create mode 100644 drivers/media/radio/radio-kt0913.c
> >
> > diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
> > index d29e29645e04..ac9053a95f3a 100644
> > --- a/drivers/media/radio/Kconfig
> > +++ b/drivers/media/radio/Kconfig
> > @@ -226,6 +226,16 @@ config RADIO_WL1273
> >  # TI's ST based wl128x FM radio
> >  source "drivers/media/radio/wl128x/Kconfig"
> >
> > +config RADIO_KT0913
> > + tristate "KT0913 I2C FM/AM radio support"
> > + depends on I2C && VIDEO_V4L2
> > + help
> > +   Say Y here if you want to use the KT0913 FM/AM chip.
> > +   This is a low cost chip that uses the I2C bus.
> > +
> > +   To compile this driver as a module, choose M here: the
> > +   module will be called radio-kt0913.
> > +
> >  #
> >  # ISA drivers configuration
> >  #
> > diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
> > index 53c7ae135460..a314121f7771 100644
> > --- a/drivers/media/radio/Makefile
> > +++ b/drivers/media/radio/Makefile
> > @@ -34,5 +34,6 @@ obj-$(CONFIG_RADIO_WL1273) += radio-wl1273.o
> >  obj-$(CONFIG_RADIO_WL128X) += wl128x/
> >  obj-$(CONFIG_RADIO_TEA575X) += tea575x.o
> >  obj-$(CONFIG_USB_RAREMONO) += radio-raremono.o
> > +obj-$(CONFIG_RADIO_KT0913) += radio-kt0913.o
> >
> >  shark2-objs := radio-shark2.o radio-tea5777.o
> > diff --git a/drivers/media/radio/radio-kt0913.c 
> > b/drivers/media/radio/radio-kt0913.c
> > new file mode 100644
> > index ..e8c1ff882779
> > --- /dev/null
> > +++ b/drivers/media/radio/radio-kt0913.c
> > @@ -0,0 +1,1196 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * drivers/media/radio/radio-kt0913.c
> > + *
> > + * Driver for the KT0913 radio chip from KTMicro.
> > + * This driver provides a v4l2 interface to the tuner, using the I2C
> > + * protocol to communicate with the chip.
> > + * It exposes two bands, one for AM and another for FM. If the "campus
> > + * band" feature needs to be enabled, set the corresponding module 
> > parameter
> > + * to 1.
> > + * Reference Clock and Audio DAC anti-pop configurations should be
> > + * set via a device tree node. Defaults will be used otherwise.
> > + *
> > + * Audio output should be routed to a speaker or an audio capture
> > + * device.
> > + *
> > + * Based on radio-tea5764 by Fabio Belavenuto 
> > + *
> > + *  Copyright (c) 2020 Santiago Hormazabal 
> > + *
> > + * TODO:
> > + *  use rd and wr support for the regmap instead of volatile regs.
> > + *  add support for the hardware-assisted frequency seek.
> > + *  export FM SNR and AM/FM AFC deviation values as RO controls.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > + /* 
> > * */
> > +
> > + /* registers of the kt0913 */
> > +#define KT0913_REG_CHIP_ID  0x01
> > +#define KT0913_REG_SEEK 0x02
> > +#define KT0913_REG_TUNE 0x03
> > +#define KT0913_REG_VOLUME   0x04
> > +#define KT0913_REG_DSPCFGA  0x05
> > +#define KT0913_REG_LOCFGA   0x0A
> > +#define KT0913_REG_LOCFGC   0x0C
> > +#define KT0913_REG_RXCFG0x0F
> > +#define KT0913_REG_STATUSA  0x12
> > +#define KT0913_REG_STATUSB  0x13
> > +#define KT0913_REG_STATUSC  0x14
> > +#define KT0913_REG_AMSYSCFG 0x16
> > +#define KT0913_REG_AMCHAN   0x17
> > +#define KT0913_REG_AMCALI   0x18
> > +#define KT0913_REG_GPIOCFG  0x1D
> > +#define KT0913_REG_AMDSP0x22
> > +#define KT0913_REG_AMSTATUSA0x24
> > +#define KT0913_REG_AMSTATUSB0x25
> > +#define KT0913_REG_SOFTMUTE 0x2E
> > +#define KT0913_REG_AMCFG0x33
> > +#define KT0913_REG_AMCFG2   0x34
> > +#define KT0913_REG_AFC  0x3C
>
> Hmm, this is still uppercase.
>
Uh! you know what? I had all the changes staged and then when I
upgraded the master of the repo I forgot to pop them. Then I continued
fixing the other errors you've 

Re: [PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-08-03 Thread Hans Verkuil
On 03/08/2020 04:09, Santiago Hormazabal wrote:
> This chip requires almost no support components and can used over I2C.
> The driver uses the I2C bus and exposes the controls as a V4L2 radio.
> Tested with a module that contains this chip (from SZZSJDZ.com,
> part number ZJ-801B, even tho the company seems defunct now), and an H2+
> AllWinner SoC running a kernel built off 8f2a4a9 of the media_tree.
> 
> Signed-off-by: Santiago Hormazabal 
> ---

It's good practice to list the changes you made for a v2 either in the
cover letter or here (below ---).

I have a preference myself for the cover letter, but either is fine.

>  drivers/media/radio/Kconfig|   10 +
>  drivers/media/radio/Makefile   |1 +
>  drivers/media/radio/radio-kt0913.c | 1196 
>  3 files changed, 1207 insertions(+)
>  create mode 100644 drivers/media/radio/radio-kt0913.c
> 
> diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
> index d29e29645e04..ac9053a95f3a 100644
> --- a/drivers/media/radio/Kconfig
> +++ b/drivers/media/radio/Kconfig
> @@ -226,6 +226,16 @@ config RADIO_WL1273
>  # TI's ST based wl128x FM radio
>  source "drivers/media/radio/wl128x/Kconfig"
>  
> +config RADIO_KT0913
> + tristate "KT0913 I2C FM/AM radio support"
> + depends on I2C && VIDEO_V4L2
> + help
> +   Say Y here if you want to use the KT0913 FM/AM chip.
> +   This is a low cost chip that uses the I2C bus.
> +
> +   To compile this driver as a module, choose M here: the
> +   module will be called radio-kt0913.
> +
>  #
>  # ISA drivers configuration
>  #
> diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
> index 53c7ae135460..a314121f7771 100644
> --- a/drivers/media/radio/Makefile
> +++ b/drivers/media/radio/Makefile
> @@ -34,5 +34,6 @@ obj-$(CONFIG_RADIO_WL1273) += radio-wl1273.o
>  obj-$(CONFIG_RADIO_WL128X) += wl128x/
>  obj-$(CONFIG_RADIO_TEA575X) += tea575x.o
>  obj-$(CONFIG_USB_RAREMONO) += radio-raremono.o
> +obj-$(CONFIG_RADIO_KT0913) += radio-kt0913.o
>  
>  shark2-objs := radio-shark2.o radio-tea5777.o
> diff --git a/drivers/media/radio/radio-kt0913.c 
> b/drivers/media/radio/radio-kt0913.c
> new file mode 100644
> index ..e8c1ff882779
> --- /dev/null
> +++ b/drivers/media/radio/radio-kt0913.c
> @@ -0,0 +1,1196 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * drivers/media/radio/radio-kt0913.c
> + *
> + * Driver for the KT0913 radio chip from KTMicro.
> + * This driver provides a v4l2 interface to the tuner, using the I2C
> + * protocol to communicate with the chip.
> + * It exposes two bands, one for AM and another for FM. If the "campus
> + * band" feature needs to be enabled, set the corresponding module parameter
> + * to 1.
> + * Reference Clock and Audio DAC anti-pop configurations should be
> + * set via a device tree node. Defaults will be used otherwise.
> + *
> + * Audio output should be routed to a speaker or an audio capture
> + * device.
> + *
> + * Based on radio-tea5764 by Fabio Belavenuto 
> + *
> + *  Copyright (c) 2020 Santiago Hormazabal 
> + *
> + * TODO:
> + *  use rd and wr support for the regmap instead of volatile regs.
> + *  add support for the hardware-assisted frequency seek.
> + *  export FM SNR and AM/FM AFC deviation values as RO controls.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> + /* 
> * */
> +
> + /* registers of the kt0913 */
> +#define KT0913_REG_CHIP_ID  0x01
> +#define KT0913_REG_SEEK 0x02
> +#define KT0913_REG_TUNE 0x03
> +#define KT0913_REG_VOLUME   0x04
> +#define KT0913_REG_DSPCFGA  0x05
> +#define KT0913_REG_LOCFGA   0x0A
> +#define KT0913_REG_LOCFGC   0x0C
> +#define KT0913_REG_RXCFG0x0F
> +#define KT0913_REG_STATUSA  0x12
> +#define KT0913_REG_STATUSB  0x13
> +#define KT0913_REG_STATUSC  0x14
> +#define KT0913_REG_AMSYSCFG 0x16
> +#define KT0913_REG_AMCHAN   0x17
> +#define KT0913_REG_AMCALI   0x18
> +#define KT0913_REG_GPIOCFG  0x1D
> +#define KT0913_REG_AMDSP0x22
> +#define KT0913_REG_AMSTATUSA0x24
> +#define KT0913_REG_AMSTATUSB0x25
> +#define KT0913_REG_SOFTMUTE 0x2E
> +#define KT0913_REG_AMCFG0x33
> +#define KT0913_REG_AMCFG2   0x34
> +#define KT0913_REG_AFC  0x3C

Hmm, this is still uppercase.

> +
> +/* register symbols masks, values and shift count */
> +#define KT0913_TUNE_FMTUNE_MASK 0x8000 /* FM Tune enable */
> +#define KT0913_TUNE_FMTUNE_ON 0x8000 /* FM Tune enabled */
> +#define KT0913_TUNE_FMTUNE_OFF 0x /* FM Tune disabled */
> +#define KT0913_TUNE_FMCHAN_MASK 0x0FFF /* frequency in kHz / 50kHz */
> +
> +#define KT0913_VOLUME_DMUTE_MASK 0x2000
> +#define KT0913_VOLUME_DMUTE_ON 0x
> +#define KT0913_VOLUME_DMUTE_OFF 0x2000
> +#define KT0913_VOLUME_DE_MASK 

[PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-08-02 Thread Santiago Hormazabal
This chip requires almost no support components and can used over I2C.
The driver uses the I2C bus and exposes the controls as a V4L2 radio.
Tested with a module that contains this chip (from SZZSJDZ.com,
part number ZJ-801B, even tho the company seems defunct now), and an H2+
AllWinner SoC running a kernel built off 8f2a4a9 of the media_tree.

Signed-off-by: Santiago Hormazabal 
---
 drivers/media/radio/Kconfig|   10 +
 drivers/media/radio/Makefile   |1 +
 drivers/media/radio/radio-kt0913.c | 1196 
 3 files changed, 1207 insertions(+)
 create mode 100644 drivers/media/radio/radio-kt0913.c

diff --git a/drivers/media/radio/Kconfig b/drivers/media/radio/Kconfig
index d29e29645e04..ac9053a95f3a 100644
--- a/drivers/media/radio/Kconfig
+++ b/drivers/media/radio/Kconfig
@@ -226,6 +226,16 @@ config RADIO_WL1273
 # TI's ST based wl128x FM radio
 source "drivers/media/radio/wl128x/Kconfig"
 
+config RADIO_KT0913
+   tristate "KT0913 I2C FM/AM radio support"
+   depends on I2C && VIDEO_V4L2
+   help
+ Say Y here if you want to use the KT0913 FM/AM chip.
+ This is a low cost chip that uses the I2C bus.
+
+ To compile this driver as a module, choose M here: the
+ module will be called radio-kt0913.
+
 #
 # ISA drivers configuration
 #
diff --git a/drivers/media/radio/Makefile b/drivers/media/radio/Makefile
index 53c7ae135460..a314121f7771 100644
--- a/drivers/media/radio/Makefile
+++ b/drivers/media/radio/Makefile
@@ -34,5 +34,6 @@ obj-$(CONFIG_RADIO_WL1273) += radio-wl1273.o
 obj-$(CONFIG_RADIO_WL128X) += wl128x/
 obj-$(CONFIG_RADIO_TEA575X) += tea575x.o
 obj-$(CONFIG_USB_RAREMONO) += radio-raremono.o
+obj-$(CONFIG_RADIO_KT0913) += radio-kt0913.o
 
 shark2-objs := radio-shark2.o radio-tea5777.o
diff --git a/drivers/media/radio/radio-kt0913.c 
b/drivers/media/radio/radio-kt0913.c
new file mode 100644
index ..e8c1ff882779
--- /dev/null
+++ b/drivers/media/radio/radio-kt0913.c
@@ -0,0 +1,1196 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * drivers/media/radio/radio-kt0913.c
+ *
+ * Driver for the KT0913 radio chip from KTMicro.
+ * This driver provides a v4l2 interface to the tuner, using the I2C
+ * protocol to communicate with the chip.
+ * It exposes two bands, one for AM and another for FM. If the "campus
+ * band" feature needs to be enabled, set the corresponding module parameter
+ * to 1.
+ * Reference Clock and Audio DAC anti-pop configurations should be
+ * set via a device tree node. Defaults will be used otherwise.
+ *
+ * Audio output should be routed to a speaker or an audio capture
+ * device.
+ *
+ * Based on radio-tea5764 by Fabio Belavenuto 
+ *
+ *  Copyright (c) 2020 Santiago Hormazabal 
+ *
+ * TODO:
+ *  use rd and wr support for the regmap instead of volatile regs.
+ *  add support for the hardware-assisted frequency seek.
+ *  export FM SNR and AM/FM AFC deviation values as RO controls.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+ /* * 
*/
+
+ /* registers of the kt0913 */
+#define KT0913_REG_CHIP_ID  0x01
+#define KT0913_REG_SEEK 0x02
+#define KT0913_REG_TUNE 0x03
+#define KT0913_REG_VOLUME   0x04
+#define KT0913_REG_DSPCFGA  0x05
+#define KT0913_REG_LOCFGA   0x0A
+#define KT0913_REG_LOCFGC   0x0C
+#define KT0913_REG_RXCFG0x0F
+#define KT0913_REG_STATUSA  0x12
+#define KT0913_REG_STATUSB  0x13
+#define KT0913_REG_STATUSC  0x14
+#define KT0913_REG_AMSYSCFG 0x16
+#define KT0913_REG_AMCHAN   0x17
+#define KT0913_REG_AMCALI   0x18
+#define KT0913_REG_GPIOCFG  0x1D
+#define KT0913_REG_AMDSP0x22
+#define KT0913_REG_AMSTATUSA0x24
+#define KT0913_REG_AMSTATUSB0x25
+#define KT0913_REG_SOFTMUTE 0x2E
+#define KT0913_REG_AMCFG0x33
+#define KT0913_REG_AMCFG2   0x34
+#define KT0913_REG_AFC  0x3C
+
+/* register symbols masks, values and shift count */
+#define KT0913_TUNE_FMTUNE_MASK 0x8000 /* FM Tune enable */
+#define KT0913_TUNE_FMTUNE_ON 0x8000 /* FM Tune enabled */
+#define KT0913_TUNE_FMTUNE_OFF 0x /* FM Tune disabled */
+#define KT0913_TUNE_FMCHAN_MASK 0x0FFF /* frequency in kHz / 50kHz */
+
+#define KT0913_VOLUME_DMUTE_MASK 0x2000
+#define KT0913_VOLUME_DMUTE_ON 0x
+#define KT0913_VOLUME_DMUTE_OFF 0x2000
+#define KT0913_VOLUME_DE_MASK 0x0800 /* de-emphasis time constant */
+#define KT0913_VOLUME_DE_75US 0x /* 75us */
+#define KT0913_VOLUME_DE_50US 0x0800 /* 50us */
+#define KT0913_VOLUME_POP_MASK 0x30 /* audio dac anti-pop config */
+#define KT0913_VOLUME_POP_SHIFT 4
+
+#define KT0913_DSPCFGA_MONO_MASK 0x8000 /* mono select (0=stereo, 1=mono) */
+#define KT0913_DSPCFGA_MONO_ON 0x8000 /* mono */
+#define KT0913_DSPCFGA_MONO_OFF 0x /* stereo */
+
+#define KT0913_LOCFG_CAMPUSBAND_EN_MASK 0x0008 /* campus band fm enable 

Re: [PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-07-17 Thread Joe Perches
On Fri, 2020-07-17 at 12:04 +0200, Hans Verkuil wrote:
> On 17/07/2020 11:51, Joe Perches wrote:
> > On Fri, 2020-07-17 at 11:29 +0200, Hans Verkuil wrote:
> > > It's standard linux codingstyle to use lowercase for hex numbers.
> > > Can you change that throughout the source for the next version?
> > 
> > Is there a standard?  It's not in coding-style.rst.
> > 
> > While I prefer lowercase too, it seems the kernel has
> > only ~2:1 preference for lowercase to uppercase hex.
> > 
> > $ git grep -ohP '\b0[xX][0-9a-f]+\b' | grep [a-f] | wc -l
> > 1149833
> > $ git grep -ohP '\b0[xX][0-9A-F]+\b' | grep [A-F] | wc -l
> > 575781
> > 
> Well, it's indeed not a standard for the kernel as a whole, but certainly
> for drivers/media:
> 
> $ git grep -ohP '\b0[xX][0-9a-f]+\b' drivers/media/ | grep [a-f] | wc -l
> 109272
> $ git grep -ohP '\b0[xX][0-9A-F]+\b' drivers/media/ | grep [A-F] | wc -l
> 22392
> 
> The media subsystem has a 5:1 preference for lowercase. And uppercase is
> mostly found in older drivers.
> Still, I really prefer lowercase over uppercase, especially in new drivers.

That's certainly any maintainer's preference right.

Slightly unrelated:

The last 100k commits have only a ~2.5:1 use of
lowercase to uppercase hex constants.

While my cut-off for declaring something a generic
kernel style standard is also ~5:1, this isn't a
style check I would put into checkpatch as the
per-subsystem variability is quite high.

cheers, Joe



Re: [PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-07-17 Thread Santiago Hormazabal
On Fri, 17 Jul 2020 at 06:29, Hans Verkuil  wrote:
>
> Hi Santiago,
>
> Nice, it's been a long time since I last received a new radio driver :-)
>
> I have a bunch of comments below, nothing major.
>
> Main thing you need to do is to run 'checkpatch --strict' over the patch
> to fix codingstyle issues. And I realized that one corner of the API wasn't
> checked by v4l2-compliance, so you need to get the latest version of
> v4l2-compliance where I added new checks.
>
Sure, I'll get the newest v4l2-compliance and run it again, and
(probably) fix the issues on the code.

> On 17/07/2020 02:44, Santiago Hormazabal wrote:
> > This chip requires almost no support components and can used over I2C.
> > The driver uses the I2C bus and exposes the controls as a V4L2 radio.
> > Tested with a module that contains this chip (from SZZSJDZ.com,
>
> I can't find that site, is the URL correct?

Right, it seems like the manufacturer is gone, and the specs of this
module didn't get
saved by the web.archive.org; but I found these chips readily available over
AliExpress/Alibaba and so on. I scavenged this module from an
not-so-old home theater.
I found a Japanese provider of these chips over
https://www.aitendo.com/product/7448;
and they also provide a breakout board for the SSOP16 package, but I
assume it'll be
easier to just buy the chip over AliExpress and use a standard SSOP16L breakout.
I also saw a cool project that used this chip with an arduino, where
the minimal components
needed for the chip to run are described over
https://github.com/xiaolaba/KT0913_RADIO.

> If you know of a cheap shield that has this chip then let me know, I might
> just get one myself.
>
> > part number ZJ-801B) and a H2+ AllWinner SoC running the master
> > (at this time) of the media_tree.
> >
> > Signed-off-by: Santiago Hormazabal 
> > ---
> >  drivers/media/radio/radio-kt0913.c | 1181 
> >  1 file changed, 1181 insertions(+)
> >  create mode 100644 drivers/media/radio/radio-kt0913.c
> >
> > diff --git a/drivers/media/radio/radio-kt0913.c 
> > b/drivers/media/radio/radio-kt0913.c
> > new file mode 100644
> > index ..9350d1764d44
> > --- /dev/null
> > +++ b/drivers/media/radio/radio-kt0913.c
> > @@ -0,0 +1,1181 @@
> > +// SPDX-License-Identifier: GPL-2.0-only
> > +/*
> > + * drivers/media/radio/radio-kt0913.c
> > + *
> > + * Driver for the KT0913 radio chip from KTMicro.
> > + * This driver provides a v4l2 interface to the tuner, using the I2C
> > + * protocol to communicate with the chip.
> > + * It exposes two bands, one for AM and another for FM. If the "campus
> > + * band" feature needs to be enabled, set the corresponding module 
> > parameter
> > + * to 1.
> > + * Reference Clock and Audio DAC anti-pop configurations should be
> > + * set via a device tree node. Defaults will be used otherwise.
> > + *
> > + * Audio output should be routed to a speaker or an audio capture
> > + * device.
> > + *
> > + * Based on radio-tea5764 by Fabio Belavenuto 
> > + *
> > + *  Copyright (c) 2020 Santiago Hormazabal 
> > + *
> > + * TODO:
> > + *  use rd and wr support for the regmap instead of volatile regs.
> > + *  add support for the hardware-assisted frequency seek.
> > + *  export FM SNR and AM/FM AFC deviation values as RO controls.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > + /* 
> > * */
> > +
> > + /* registers of the kt0913 */
> > +#define KT0913_REG_CHIP_ID  0x01
> > +#define KT0913_REG_SEEK 0x02
> > +#define KT0913_REG_TUNE 0x03
> > +#define KT0913_REG_VOLUME   0x04
> > +#define KT0913_REG_DSPCFGA  0x05
> > +#define KT0913_REG_LOCFGA   0x0A
> > +#define KT0913_REG_LOCFGC   0x0C
> > +#define KT0913_REG_RXCFG0x0F
> > +#define KT0913_REG_STATUSA  0x12
> > +#define KT0913_REG_STATUSB  0x13
> > +#define KT0913_REG_STATUSC  0x14
> > +#define KT0913_REG_AMSYSCFG 0x16
> > +#define KT0913_REG_AMCHAN   0x17
> > +#define KT0913_REG_AMCALI   0x18
> > +#define KT0913_REG_GPIOCFG  0x1D
> > +#define KT0913_REG_AMDSP0x22
> > +#define KT0913_REG_AMSTATUSA0x24
> > +#define KT0913_REG_AMSTATUSB0x25
> > +#define KT0913_REG_SOFTMUTE 0x2E
> > +#define KT0913_REG_AMCFG0x33
> > +#define KT0913_REG_AMCFG2   0x34
> > +#define KT0913_REG_AFC  0x3C
>
> It's standard linux codingstyle to use lowercase for hex numbers.
> Can you change that throughout the source for the next version?
>
Yes, of course.

> > +
> > +/* register symbols masks, values and shift count */
> > +#define KT0913_TUNE_FMTUNE_MASK 0x8000 /* FM Tune enable */
> > +#define KT0913_TUNE_FMTUNE_ON 0x8000 /* FM Tune enabled */
> > +#define KT0913_TUNE_FMTUNE_OFF 0x /* FM Tune disabled */
> > +#define KT0913_TUNE_FMCHAN_MASK 0x0FFF /* 

Re: [PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-07-17 Thread Hans Verkuil
On 17/07/2020 11:51, Joe Perches wrote:
> On Fri, 2020-07-17 at 11:29 +0200, Hans Verkuil wrote:
>> It's standard linux codingstyle to use lowercase for hex numbers.
>> Can you change that throughout the source for the next version?
> 
> Is there a standard?  It's not in coding-style.rst.
> 
> While I prefer lowercase too, it seems the kernel has
> only ~2:1 preference for lowercase to uppercase hex.
> 
> $ git grep -ohP '\b0[xX][0-9a-f]+\b' | grep [a-f] | wc -l
> 1149833
> $ git grep -ohP '\b0[xX][0-9A-F]+\b' | grep [A-F] | wc -l
> 575781
> 
> 

Well, it's indeed not a standard for the kernel as a whole, but certainly
for drivers/media:

$ git grep -ohP '\b0[xX][0-9a-f]+\b' drivers/media/ | grep [a-f] | wc -l
109272
$ git grep -ohP '\b0[xX][0-9A-F]+\b' drivers/media/ | grep [A-F] | wc -l
22392

The media subsystem has a 5:1 preference for lowercase. And uppercase is
mostly found in older drivers.

Still, I really prefer lowercase over uppercase, especially in new drivers.

Regards,

Hans


Re: [PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-07-17 Thread Joe Perches
On Fri, 2020-07-17 at 11:29 +0200, Hans Verkuil wrote:
> It's standard linux codingstyle to use lowercase for hex numbers.
> Can you change that throughout the source for the next version?

Is there a standard?  It's not in coding-style.rst.

While I prefer lowercase too, it seems the kernel has
only ~2:1 preference for lowercase to uppercase hex.

$ git grep -ohP '\b0[xX][0-9a-f]+\b' | grep [a-f] | wc -l
1149833
$ git grep -ohP '\b0[xX][0-9A-F]+\b' | grep [A-F] | wc -l
575781




Re: [PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-07-17 Thread Hans Verkuil
Hi Santiago,

Nice, it's been a long time since I last received a new radio driver :-)

I have a bunch of comments below, nothing major.

Main thing you need to do is to run 'checkpatch --strict' over the patch
to fix codingstyle issues. And I realized that one corner of the API wasn't
checked by v4l2-compliance, so you need to get the latest version of
v4l2-compliance where I added new checks.

On 17/07/2020 02:44, Santiago Hormazabal wrote:
> This chip requires almost no support components and can used over I2C.
> The driver uses the I2C bus and exposes the controls as a V4L2 radio.
> Tested with a module that contains this chip (from SZZSJDZ.com,

I can't find that site, is the URL correct?

If you know of a cheap shield that has this chip then let me know, I might
just get one myself.

> part number ZJ-801B) and a H2+ AllWinner SoC running the master
> (at this time) of the media_tree.
> 
> Signed-off-by: Santiago Hormazabal 
> ---
>  drivers/media/radio/radio-kt0913.c | 1181 
>  1 file changed, 1181 insertions(+)
>  create mode 100644 drivers/media/radio/radio-kt0913.c
> 
> diff --git a/drivers/media/radio/radio-kt0913.c 
> b/drivers/media/radio/radio-kt0913.c
> new file mode 100644
> index ..9350d1764d44
> --- /dev/null
> +++ b/drivers/media/radio/radio-kt0913.c
> @@ -0,0 +1,1181 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * drivers/media/radio/radio-kt0913.c
> + *
> + * Driver for the KT0913 radio chip from KTMicro.
> + * This driver provides a v4l2 interface to the tuner, using the I2C
> + * protocol to communicate with the chip.
> + * It exposes two bands, one for AM and another for FM. If the "campus
> + * band" feature needs to be enabled, set the corresponding module parameter
> + * to 1.
> + * Reference Clock and Audio DAC anti-pop configurations should be
> + * set via a device tree node. Defaults will be used otherwise.
> + *
> + * Audio output should be routed to a speaker or an audio capture
> + * device.
> + *
> + * Based on radio-tea5764 by Fabio Belavenuto 
> + *
> + *  Copyright (c) 2020 Santiago Hormazabal 
> + *
> + * TODO:
> + *  use rd and wr support for the regmap instead of volatile regs.
> + *  add support for the hardware-assisted frequency seek.
> + *  export FM SNR and AM/FM AFC deviation values as RO controls.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> + /* 
> * */
> +
> + /* registers of the kt0913 */
> +#define KT0913_REG_CHIP_ID  0x01
> +#define KT0913_REG_SEEK 0x02
> +#define KT0913_REG_TUNE 0x03
> +#define KT0913_REG_VOLUME   0x04
> +#define KT0913_REG_DSPCFGA  0x05
> +#define KT0913_REG_LOCFGA   0x0A
> +#define KT0913_REG_LOCFGC   0x0C
> +#define KT0913_REG_RXCFG0x0F
> +#define KT0913_REG_STATUSA  0x12
> +#define KT0913_REG_STATUSB  0x13
> +#define KT0913_REG_STATUSC  0x14
> +#define KT0913_REG_AMSYSCFG 0x16
> +#define KT0913_REG_AMCHAN   0x17
> +#define KT0913_REG_AMCALI   0x18
> +#define KT0913_REG_GPIOCFG  0x1D
> +#define KT0913_REG_AMDSP0x22
> +#define KT0913_REG_AMSTATUSA0x24
> +#define KT0913_REG_AMSTATUSB0x25
> +#define KT0913_REG_SOFTMUTE 0x2E
> +#define KT0913_REG_AMCFG0x33
> +#define KT0913_REG_AMCFG2   0x34
> +#define KT0913_REG_AFC  0x3C

It's standard linux codingstyle to use lowercase for hex numbers.
Can you change that throughout the source for the next version?

> +
> +/* register symbols masks, values and shift count */
> +#define KT0913_TUNE_FMTUNE_MASK 0x8000 /* FM Tune enable */
> +#define KT0913_TUNE_FMTUNE_ON 0x8000 /* FM Tune enabled */
> +#define KT0913_TUNE_FMTUNE_OFF 0x /* FM Tune disabled */
> +#define KT0913_TUNE_FMCHAN_MASK 0x0FFF /* frequency in kHz / 50kHz */
> +
> +#define KT0913_VOLUME_DMUTE_MASK 0x2000
> +#define KT0913_VOLUME_DMUTE_ON 0x
> +#define KT0913_VOLUME_DMUTE_OFF 0x2000
> +#define KT0913_VOLUME_DE_MASK 0x0800 /* de-emphasis time constant */
> +#define KT0913_VOLUME_DE_75US 0x /* 75us */
> +#define KT0913_VOLUME_DE_50US 0x0800 /* 50us */
> +#define KT0913_VOLUME_POP_MASK 0x30 /* audio dac anti-pop config */
> +#define KT0913_VOLUME_POP_SHIFT 4
> +
> +#define KT0913_DSPCFGA_MONO_MASK 0x8000 /* mono select (0=stereo, 1=mono) */
> +#define KT0913_DSPCFGA_MONO_ON 0x8000 /* mono */
> +#define KT0913_DSPCFGA_MONO_OFF 0x /* stereo */
> +
> +#define KT0913_LOCFG_CAMPUSBAND_EN_MASK 0x0008 /* campus band fm enable */
> +#define KT0913_LOCFG_CAMPUSBAND_EN_ON 0x0008 /* FM range 64-110MHz */
> +#define KT0913_LOCFG_CAMPUSBAND_EN_OFF 0x /* FM range 32-110MHz */
> +
> +#define KT0913_RXCFGA_STDBY_MASK 0x1000 /* standby mode enable */
> +#define KT0913_RXCFGA_STDBY_ON 0x1000 /* standby mode enabled */
> +#define KT0913_RXCFGA_STDBY_OFF 0x /* standby mode disabled */
> 

[PATCH 3/3] media: Add support for the AM/FM radio chip KT0913 from KT Micro.

2020-07-16 Thread Santiago Hormazabal
This chip requires almost no support components and can used over I2C.
The driver uses the I2C bus and exposes the controls as a V4L2 radio.
Tested with a module that contains this chip (from SZZSJDZ.com,
part number ZJ-801B) and a H2+ AllWinner SoC running the master
(at this time) of the media_tree.

Signed-off-by: Santiago Hormazabal 
---
 drivers/media/radio/radio-kt0913.c | 1181 
 1 file changed, 1181 insertions(+)
 create mode 100644 drivers/media/radio/radio-kt0913.c

diff --git a/drivers/media/radio/radio-kt0913.c 
b/drivers/media/radio/radio-kt0913.c
new file mode 100644
index ..9350d1764d44
--- /dev/null
+++ b/drivers/media/radio/radio-kt0913.c
@@ -0,0 +1,1181 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * drivers/media/radio/radio-kt0913.c
+ *
+ * Driver for the KT0913 radio chip from KTMicro.
+ * This driver provides a v4l2 interface to the tuner, using the I2C
+ * protocol to communicate with the chip.
+ * It exposes two bands, one for AM and another for FM. If the "campus
+ * band" feature needs to be enabled, set the corresponding module parameter
+ * to 1.
+ * Reference Clock and Audio DAC anti-pop configurations should be
+ * set via a device tree node. Defaults will be used otherwise.
+ *
+ * Audio output should be routed to a speaker or an audio capture
+ * device.
+ *
+ * Based on radio-tea5764 by Fabio Belavenuto 
+ *
+ *  Copyright (c) 2020 Santiago Hormazabal 
+ *
+ * TODO:
+ *  use rd and wr support for the regmap instead of volatile regs.
+ *  add support for the hardware-assisted frequency seek.
+ *  export FM SNR and AM/FM AFC deviation values as RO controls.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+ /* * 
*/
+
+ /* registers of the kt0913 */
+#define KT0913_REG_CHIP_ID  0x01
+#define KT0913_REG_SEEK 0x02
+#define KT0913_REG_TUNE 0x03
+#define KT0913_REG_VOLUME   0x04
+#define KT0913_REG_DSPCFGA  0x05
+#define KT0913_REG_LOCFGA   0x0A
+#define KT0913_REG_LOCFGC   0x0C
+#define KT0913_REG_RXCFG0x0F
+#define KT0913_REG_STATUSA  0x12
+#define KT0913_REG_STATUSB  0x13
+#define KT0913_REG_STATUSC  0x14
+#define KT0913_REG_AMSYSCFG 0x16
+#define KT0913_REG_AMCHAN   0x17
+#define KT0913_REG_AMCALI   0x18
+#define KT0913_REG_GPIOCFG  0x1D
+#define KT0913_REG_AMDSP0x22
+#define KT0913_REG_AMSTATUSA0x24
+#define KT0913_REG_AMSTATUSB0x25
+#define KT0913_REG_SOFTMUTE 0x2E
+#define KT0913_REG_AMCFG0x33
+#define KT0913_REG_AMCFG2   0x34
+#define KT0913_REG_AFC  0x3C
+
+/* register symbols masks, values and shift count */
+#define KT0913_TUNE_FMTUNE_MASK 0x8000 /* FM Tune enable */
+#define KT0913_TUNE_FMTUNE_ON 0x8000 /* FM Tune enabled */
+#define KT0913_TUNE_FMTUNE_OFF 0x /* FM Tune disabled */
+#define KT0913_TUNE_FMCHAN_MASK 0x0FFF /* frequency in kHz / 50kHz */
+
+#define KT0913_VOLUME_DMUTE_MASK 0x2000
+#define KT0913_VOLUME_DMUTE_ON 0x
+#define KT0913_VOLUME_DMUTE_OFF 0x2000
+#define KT0913_VOLUME_DE_MASK 0x0800 /* de-emphasis time constant */
+#define KT0913_VOLUME_DE_75US 0x /* 75us */
+#define KT0913_VOLUME_DE_50US 0x0800 /* 50us */
+#define KT0913_VOLUME_POP_MASK 0x30 /* audio dac anti-pop config */
+#define KT0913_VOLUME_POP_SHIFT 4
+
+#define KT0913_DSPCFGA_MONO_MASK 0x8000 /* mono select (0=stereo, 1=mono) */
+#define KT0913_DSPCFGA_MONO_ON 0x8000 /* mono */
+#define KT0913_DSPCFGA_MONO_OFF 0x /* stereo */
+
+#define KT0913_LOCFG_CAMPUSBAND_EN_MASK 0x0008 /* campus band fm enable */
+#define KT0913_LOCFG_CAMPUSBAND_EN_ON 0x0008 /* FM range 64-110MHz */
+#define KT0913_LOCFG_CAMPUSBAND_EN_OFF 0x /* FM range 32-110MHz */
+
+#define KT0913_RXCFGA_STDBY_MASK 0x1000 /* standby mode enable */
+#define KT0913_RXCFGA_STDBY_ON 0x1000 /* standby mode enabled */
+#define KT0913_RXCFGA_STDBY_OFF 0x /* standby mode disabled */
+#define KT0913_RXCFGA_VOLUME_MASK 0x001F /* volume control */
+
+#define KT0913_STATUSA_XTAL_OK 0x8000 /* crystal ready indicator */
+#define KT0913_STATUSA_STC 0x4000 /* seek/tune complete */
+
+#define KT0913_STATUSA_PLL_LOCK_MASK 0x800 /* system pll ready indicator */
+#define KT0913_STATUSA_PLL_LOCK_LOCKED 0x800 /* system pll ready */
+#define KT0913_STATUSA_PLL_LOCK_UNLOCKED 0x000 /* not ready */
+#define KT0913_STATUSA_LO_LOCK 0x400 /* LO synthesizer ready indicator */
+#define KT0913_STATUSA_ST_MASK 0x300 /* stereo indicator (0x300=stereo, 
otherwise mono) */
+#define KT0913_STATUSA_ST_STEREO 0x300 /* stereo */
+#define KT0913_STATUSA_FMRSSI_MASK 0xF8 /* FM RSSI (-100dBm + FMRSSI*3dBm) */
+#define KT0913_STATUSA_FMRSSI_SHIFT 3
+
+#define KT0913_STATUSC_PWSTATUS 0x8000 /* power status indicator */
+#define KT0913_STATUSC_CHIPRDY 0x2000 /* chip ready indicator */
+#define KT0913_STATUSC_FMSNR 0x1FC0 /* FM SNR (unknown units)