Commit 2d21e974 authored by Lee Jones's avatar Lee Jones

Merge branch 'ib-mfd-firmware-input-sound-soc-6.11' into ibs-for-mfd-merged

parents ecad8fb8 c486def5
# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
%YAML 1.2
---
$id: http://devicetree.org/schemas/input/cirrus,cs40l50.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Cirrus Logic CS40L50 Advanced Haptic Driver
maintainers:
- James Ogletree <jogletre@opensource.cirrus.com>
description:
CS40L50 is a haptic driver with waveform memory,
integrated DSP, and closed-loop algorithms.
properties:
compatible:
enum:
- cirrus,cs40l50
reg:
maxItems: 1
interrupts:
maxItems: 1
reset-gpios:
maxItems: 1
vdd-a-supply:
description: Power supply for internal analog circuits.
vdd-p-supply:
description: Power supply for always-on circuits.
vdd-io-supply:
description: Power supply for digital input/output.
vdd-b-supply:
description: Power supply for the boost converter.
required:
- compatible
- reg
- interrupts
- reset-gpios
- vdd-io-supply
additionalProperties: false
examples:
- |
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/interrupt-controller/irq.h>
i2c {
#address-cells = <1>;
#size-cells = <0>;
haptic-driver@34 {
compatible = "cirrus,cs40l50";
reg = <0x34>;
interrupt-parent = <&gpio>;
interrupts = <113 IRQ_TYPE_LEVEL_LOW>;
reset-gpios = <&gpio 112 GPIO_ACTIVE_LOW>;
vdd-io-supply = <&vreg>;
};
};
......@@ -5211,6 +5211,18 @@ F: sound/pci/hda/hda_component*
F: sound/pci/hda/hda_cs_dsp_ctl.*
F: sound/soc/codecs/cs*
CIRRUS LOGIC HAPTIC DRIVERS
M: James Ogletree <jogletre@opensource.cirrus.com>
M: Fred Treven <fred.treven@cirrus.com>
M: Ben Bright <ben.bright@cirrus.com>
L: patches@opensource.cirrus.com
S: Supported
F: Documentation/devicetree/bindings/input/cirrus,cs40l50.yaml
F: drivers/input/misc/cs40l*
F: drivers/mfd/cs40l*
F: include/linux/mfd/cs40l*
F: sound/soc/codecs/cs40l*
CIRRUS LOGIC DSP FIRMWARE DRIVER
M: Simon Trimmer <simont@opensource.cirrus.com>
M: Charles Keepax <ckeepax@opensource.cirrus.com>
......
......@@ -275,6 +275,12 @@
#define HALO_MPU_VIO_ERR_SRC_MASK 0x00007fff
#define HALO_MPU_VIO_ERR_SRC_SHIFT 0
/*
* Write Sequence
*/
#define WSEQ_OP_MAX_WORDS 3
#define WSEQ_END_OF_SCRIPT 0xFFFFFF
struct cs_dsp_ops {
bool (*validate_version)(struct cs_dsp *dsp, unsigned int version);
unsigned int (*parse_sizes)(struct cs_dsp *dsp,
......@@ -3398,6 +3404,278 @@ int cs_dsp_chunk_read(struct cs_dsp_chunk *ch, int nbits)
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_chunk_read, FW_CS_DSP);
struct cs_dsp_wseq_op {
struct list_head list;
u32 address;
u32 data;
u16 offset;
u8 operation;
};
static void cs_dsp_wseq_clear(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq)
{
struct cs_dsp_wseq_op *op, *op_tmp;
list_for_each_entry_safe(op, op_tmp, &wseq->ops, list) {
list_del(&op->list);
devm_kfree(dsp->dev, op);
}
}
static int cs_dsp_populate_wseq(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq)
{
struct cs_dsp_wseq_op *op = NULL;
struct cs_dsp_chunk chunk;
u8 *words;
int ret;
if (!wseq->ctl) {
cs_dsp_err(dsp, "No control for write sequence\n");
return -EINVAL;
}
words = kzalloc(wseq->ctl->len, GFP_KERNEL);
if (!words)
return -ENOMEM;
ret = cs_dsp_coeff_read_ctrl(wseq->ctl, 0, words, wseq->ctl->len);
if (ret) {
cs_dsp_err(dsp, "Failed to read %s: %d\n", wseq->ctl->subname, ret);
goto err_free;
}
INIT_LIST_HEAD(&wseq->ops);
chunk = cs_dsp_chunk(words, wseq->ctl->len);
while (!cs_dsp_chunk_end(&chunk)) {
op = devm_kzalloc(dsp->dev, sizeof(*op), GFP_KERNEL);
if (!op) {
ret = -ENOMEM;
goto err_free;
}
op->offset = cs_dsp_chunk_bytes(&chunk);
op->operation = cs_dsp_chunk_read(&chunk, 8);
switch (op->operation) {
case CS_DSP_WSEQ_END:
op->data = WSEQ_END_OF_SCRIPT;
break;
case CS_DSP_WSEQ_UNLOCK:
op->data = cs_dsp_chunk_read(&chunk, 16);
break;
case CS_DSP_WSEQ_ADDR8:
op->address = cs_dsp_chunk_read(&chunk, 8);
op->data = cs_dsp_chunk_read(&chunk, 32);
break;
case CS_DSP_WSEQ_H16:
case CS_DSP_WSEQ_L16:
op->address = cs_dsp_chunk_read(&chunk, 24);
op->data = cs_dsp_chunk_read(&chunk, 16);
break;
case CS_DSP_WSEQ_FULL:
op->address = cs_dsp_chunk_read(&chunk, 32);
op->data = cs_dsp_chunk_read(&chunk, 32);
break;
default:
ret = -EINVAL;
cs_dsp_err(dsp, "Unsupported op: %X\n", op->operation);
devm_kfree(dsp->dev, op);
goto err_free;
}
list_add_tail(&op->list, &wseq->ops);
if (op->operation == CS_DSP_WSEQ_END)
break;
}
if (op && op->operation != CS_DSP_WSEQ_END) {
cs_dsp_err(dsp, "%s missing end terminator\n", wseq->ctl->subname);
ret = -ENOENT;
}
err_free:
kfree(words);
return ret;
}
/**
* cs_dsp_wseq_init() - Initialize write sequences contained within the loaded DSP firmware
* @dsp: Pointer to DSP structure
* @wseqs: List of write sequences to initialize
* @num_wseqs: Number of write sequences to initialize
*
* Return: Zero for success, a negative number on error.
*/
int cs_dsp_wseq_init(struct cs_dsp *dsp, struct cs_dsp_wseq *wseqs, unsigned int num_wseqs)
{
int i, ret;
lockdep_assert_held(&dsp->pwr_lock);
for (i = 0; i < num_wseqs; i++) {
ret = cs_dsp_populate_wseq(dsp, &wseqs[i]);
if (ret) {
cs_dsp_wseq_clear(dsp, &wseqs[i]);
return ret;
}
}
return 0;
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_wseq_init, FW_CS_DSP);
static struct cs_dsp_wseq_op *cs_dsp_wseq_find_op(u32 addr, u8 op_code,
struct list_head *wseq_ops)
{
struct cs_dsp_wseq_op *op;
list_for_each_entry(op, wseq_ops, list) {
if (op->operation == op_code && op->address == addr)
return op;
}
return NULL;
}
/**
* cs_dsp_wseq_write() - Add or update an entry in a write sequence
* @dsp: Pointer to a DSP structure
* @wseq: Write sequence to write to
* @addr: Address of the register to be written to
* @data: Data to be written
* @op_code: The type of operation of the new entry
* @update: If true, searches for the first entry in the write sequence with
* the same address and op_code, and replaces it. If false, creates a new entry
* at the tail
*
* This function formats register address and value pairs into the format
* required for write sequence entries, and either updates or adds the
* new entry into the write sequence.
*
* If update is set to true and no matching entry is found, it will add a new entry.
*
* Return: Zero for success, a negative number on error.
*/
int cs_dsp_wseq_write(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq,
u32 addr, u32 data, u8 op_code, bool update)
{
struct cs_dsp_wseq_op *op_end, *op_new = NULL;
u32 words[WSEQ_OP_MAX_WORDS];
struct cs_dsp_chunk chunk;
int new_op_size, ret;
if (update)
op_new = cs_dsp_wseq_find_op(addr, op_code, &wseq->ops);
/* If entry to update is not found, treat it as a new operation */
if (!op_new) {
op_end = cs_dsp_wseq_find_op(0, CS_DSP_WSEQ_END, &wseq->ops);
if (!op_end) {
cs_dsp_err(dsp, "Missing terminator for %s\n", wseq->ctl->subname);
return -EINVAL;
}
op_new = devm_kzalloc(dsp->dev, sizeof(*op_new), GFP_KERNEL);
if (!op_new)
return -ENOMEM;
op_new->operation = op_code;
op_new->address = addr;
op_new->offset = op_end->offset;
update = false;
}
op_new->data = data;
chunk = cs_dsp_chunk(words, sizeof(words));
cs_dsp_chunk_write(&chunk, 8, op_new->operation);
switch (op_code) {
case CS_DSP_WSEQ_FULL:
cs_dsp_chunk_write(&chunk, 32, op_new->address);
cs_dsp_chunk_write(&chunk, 32, op_new->data);
break;
case CS_DSP_WSEQ_L16:
case CS_DSP_WSEQ_H16:
cs_dsp_chunk_write(&chunk, 24, op_new->address);
cs_dsp_chunk_write(&chunk, 16, op_new->data);
break;
default:
ret = -EINVAL;
cs_dsp_err(dsp, "Operation %X not supported\n", op_code);
goto op_new_free;
}
new_op_size = cs_dsp_chunk_bytes(&chunk);
if (!update) {
if (wseq->ctl->len - op_end->offset < new_op_size) {
cs_dsp_err(dsp, "Not enough memory in %s for entry\n", wseq->ctl->subname);
ret = -E2BIG;
goto op_new_free;
}
op_end->offset += new_op_size;
ret = cs_dsp_coeff_write_ctrl(wseq->ctl, op_end->offset / sizeof(u32),
&op_end->data, sizeof(u32));
if (ret)
goto op_new_free;
list_add_tail(&op_new->list, &op_end->list);
}
ret = cs_dsp_coeff_write_ctrl(wseq->ctl, op_new->offset / sizeof(u32),
words, new_op_size);
if (ret)
goto op_new_free;
return 0;
op_new_free:
devm_kfree(dsp->dev, op_new);
return ret;
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_wseq_write, FW_CS_DSP);
/**
* cs_dsp_wseq_multi_write() - Add or update multiple entries in a write sequence
* @dsp: Pointer to a DSP structure
* @wseq: Write sequence to write to
* @reg_seq: List of address-data pairs
* @num_regs: Number of address-data pairs
* @op_code: The types of operations of the new entries
* @update: If true, searches for the first entry in the write sequence with
* the same address and op_code, and replaces it. If false, creates a new entry
* at the tail
*
* This function calls cs_dsp_wseq_write() for multiple address-data pairs.
*
* Return: Zero for success, a negative number on error.
*/
int cs_dsp_wseq_multi_write(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq,
const struct reg_sequence *reg_seq, int num_regs,
u8 op_code, bool update)
{
int i, ret;
for (i = 0; i < num_regs; i++) {
ret = cs_dsp_wseq_write(dsp, wseq, reg_seq[i].reg,
reg_seq[i].def, op_code, update);
if (ret)
return ret;
}
return 0;
}
EXPORT_SYMBOL_NS_GPL(cs_dsp_wseq_multi_write, FW_CS_DSP);
MODULE_DESCRIPTION("Cirrus Logic DSP Support");
MODULE_AUTHOR("Simon Trimmer <simont@opensource.cirrus.com>");
MODULE_LICENSE("GPL v2");
......@@ -140,6 +140,16 @@ config INPUT_BMA150
To compile this driver as a module, choose M here: the
module will be called bma150.
config INPUT_CS40L50_VIBRA
tristate "CS40L50 Haptic Driver support"
depends on MFD_CS40L50_CORE
help
Say Y here to enable support for Cirrus Logic's CS40L50
haptic driver.
To compile this driver as a module, choose M here: the
module will be called cs40l50-vibra.
config INPUT_E3X0_BUTTON
tristate "NI Ettus Research USRP E3xx Button support."
default n
......
......@@ -28,6 +28,7 @@ obj-$(CONFIG_INPUT_CMA3000) += cma3000_d0x.o
obj-$(CONFIG_INPUT_CMA3000_I2C) += cma3000_d0x_i2c.o
obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o
obj-$(CONFIG_INPUT_CPCAP_PWRBUTTON) += cpcap-pwrbutton.o
obj-$(CONFIG_INPUT_CS40L50_VIBRA) += cs40l50-vibra.o
obj-$(CONFIG_INPUT_DA7280_HAPTICS) += da7280.o
obj-$(CONFIG_INPUT_DA9052_ONKEY) += da9052_onkey.o
obj-$(CONFIG_INPUT_DA9055_ONKEY) += da9055_onkey.o
......
This diff is collapsed.
......@@ -2243,6 +2243,36 @@ config MCP_UCB1200_TS
endmenu
config MFD_CS40L50_CORE
tristate
select MFD_CORE
select FW_CS_DSP
select REGMAP_IRQ
config MFD_CS40L50_I2C
tristate "Cirrus Logic CS40L50 (I2C)"
select REGMAP_I2C
select MFD_CS40L50_CORE
depends on I2C
help
Select this to support the Cirrus Logic CS40L50 Haptic
Driver over I2C.
This driver can be built as a module. If built as a module it will be
called "cs40l50-i2c".
config MFD_CS40L50_SPI
tristate "Cirrus Logic CS40L50 (SPI)"
select REGMAP_SPI
select MFD_CS40L50_CORE
depends on SPI
help
Select this to support the Cirrus Logic CS40L50 Haptic
Driver over SPI.
This driver can be built as a module. If built as a module it will be
called "cs40l50-spi".
config MFD_VEXPRESS_SYSREG
tristate "Versatile Express System Registers"
depends on VEXPRESS_CONFIG && GPIOLIB
......
......@@ -88,6 +88,10 @@ obj-$(CONFIG_MFD_MADERA) += madera.o
obj-$(CONFIG_MFD_MADERA_I2C) += madera-i2c.o
obj-$(CONFIG_MFD_MADERA_SPI) += madera-spi.o
obj-$(CONFIG_MFD_CS40L50_CORE) += cs40l50-core.o
obj-$(CONFIG_MFD_CS40L50_I2C) += cs40l50-i2c.o
obj-$(CONFIG_MFD_CS40L50_SPI) += cs40l50-spi.o
obj-$(CONFIG_TPS6105X) += tps6105x.o
obj-$(CONFIG_TPS65010) += tps65010.o
obj-$(CONFIG_TPS6507X) += tps6507x.o
......
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0
/*
* CS40L50 Advanced Haptic Driver with waveform memory,
* integrated DSP, and closed-loop algorithms
*
* Copyright 2024 Cirrus Logic, Inc.
*
* Author: James Ogletree <james.ogletree@cirrus.com>
*/
#include <linux/i2c.h>
#include <linux/mfd/cs40l50.h>
static int cs40l50_i2c_probe(struct i2c_client *i2c)
{
struct cs40l50 *cs40l50;
cs40l50 = devm_kzalloc(&i2c->dev, sizeof(*cs40l50), GFP_KERNEL);
if (!cs40l50)
return -ENOMEM;
i2c_set_clientdata(i2c, cs40l50);
cs40l50->dev = &i2c->dev;
cs40l50->irq = i2c->irq;
cs40l50->regmap = devm_regmap_init_i2c(i2c, &cs40l50_regmap);
if (IS_ERR(cs40l50->regmap))
return dev_err_probe(cs40l50->dev, PTR_ERR(cs40l50->regmap),
"Failed to initialize register map\n");
return cs40l50_probe(cs40l50);
}
static void cs40l50_i2c_remove(struct i2c_client *i2c)
{
struct cs40l50 *cs40l50 = i2c_get_clientdata(i2c);
cs40l50_remove(cs40l50);
}
static const struct i2c_device_id cs40l50_id_i2c[] = {
{ "cs40l50" },
{}
};
MODULE_DEVICE_TABLE(i2c, cs40l50_id_i2c);
static const struct of_device_id cs40l50_of_match[] = {
{ .compatible = "cirrus,cs40l50" },
{}
};
MODULE_DEVICE_TABLE(of, cs40l50_of_match);
static struct i2c_driver cs40l50_i2c_driver = {
.driver = {
.name = "cs40l50",
.of_match_table = cs40l50_of_match,
.pm = pm_ptr(&cs40l50_pm_ops),
},
.id_table = cs40l50_id_i2c,
.probe = cs40l50_i2c_probe,
.remove = cs40l50_i2c_remove,
};
module_i2c_driver(cs40l50_i2c_driver);
MODULE_DESCRIPTION("CS40L50 I2C Driver");
MODULE_AUTHOR("James Ogletree, Cirrus Logic Inc. <james.ogletree@cirrus.com>");
MODULE_LICENSE("GPL");
// SPDX-License-Identifier: GPL-2.0
/*
* CS40L50 Advanced Haptic Driver with waveform memory,
* integrated DSP, and closed-loop algorithms
*
* Copyright 2024 Cirrus Logic, Inc.
*
* Author: James Ogletree <james.ogletree@cirrus.com>
*/
#include <linux/mfd/cs40l50.h>
#include <linux/spi/spi.h>
static int cs40l50_spi_probe(struct spi_device *spi)
{
struct cs40l50 *cs40l50;
cs40l50 = devm_kzalloc(&spi->dev, sizeof(*cs40l50), GFP_KERNEL);
if (!cs40l50)
return -ENOMEM;
spi_set_drvdata(spi, cs40l50);
cs40l50->dev = &spi->dev;
cs40l50->irq = spi->irq;
cs40l50->regmap = devm_regmap_init_spi(spi, &cs40l50_regmap);
if (IS_ERR(cs40l50->regmap))
return dev_err_probe(cs40l50->dev, PTR_ERR(cs40l50->regmap),
"Failed to initialize register map\n");
return cs40l50_probe(cs40l50);
}
static void cs40l50_spi_remove(struct spi_device *spi)
{
struct cs40l50 *cs40l50 = spi_get_drvdata(spi);
cs40l50_remove(cs40l50);
}
static const struct spi_device_id cs40l50_id_spi[] = {
{ "cs40l50" },
{}
};
MODULE_DEVICE_TABLE(spi, cs40l50_id_spi);
static const struct of_device_id cs40l50_of_match[] = {
{ .compatible = "cirrus,cs40l50" },
{}
};
MODULE_DEVICE_TABLE(of, cs40l50_of_match);
static struct spi_driver cs40l50_spi_driver = {
.driver = {
.name = "cs40l50",
.of_match_table = cs40l50_of_match,
.pm = pm_ptr(&cs40l50_pm_ops),
},
.id_table = cs40l50_id_spi,
.probe = cs40l50_spi_probe,
.remove = cs40l50_spi_remove,
};
module_spi_driver(cs40l50_spi_driver);
MODULE_DESCRIPTION("CS40L50 SPI Driver");
MODULE_AUTHOR("James Ogletree, Cirrus Logic Inc. <james.ogletree@cirrus.com>");
MODULE_LICENSE("GPL");
......@@ -42,6 +42,16 @@
#define CS_DSP_ACKED_CTL_MIN_VALUE 0
#define CS_DSP_ACKED_CTL_MAX_VALUE 0xFFFFFF
/*
* Write sequence operation codes
*/
#define CS_DSP_WSEQ_FULL 0x00
#define CS_DSP_WSEQ_ADDR8 0x02
#define CS_DSP_WSEQ_L16 0x04
#define CS_DSP_WSEQ_H16 0x05
#define CS_DSP_WSEQ_UNLOCK 0xFD
#define CS_DSP_WSEQ_END 0xFF
/**
* struct cs_dsp_region - Describes a logical memory region in DSP address space
* @type: Memory region type
......@@ -258,6 +268,23 @@ struct cs_dsp_alg_region *cs_dsp_find_alg_region(struct cs_dsp *dsp,
const char *cs_dsp_mem_region_name(unsigned int type);
/**
* struct cs_dsp_wseq - Describes a write sequence
* @ctl: Write sequence cs_dsp control
* @ops: Operations contained within
*/
struct cs_dsp_wseq {
struct cs_dsp_coeff_ctl *ctl;
struct list_head ops;
};
int cs_dsp_wseq_init(struct cs_dsp *dsp, struct cs_dsp_wseq *wseqs, unsigned int num_wseqs);
int cs_dsp_wseq_write(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq, u32 addr, u32 data,
u8 op_code, bool update);
int cs_dsp_wseq_multi_write(struct cs_dsp *dsp, struct cs_dsp_wseq *wseq,
const struct reg_sequence *reg_seq, int num_regs,
u8 op_code, bool update);
/**
* struct cs_dsp_chunk - Describes a buffer holding data formatted for the DSP
* @data: Pointer to underlying buffer memory
......
/* SPDX-License-Identifier: GPL-2.0
*
* CS40L50 Advanced Haptic Driver with waveform memory,
* integrated DSP, and closed-loop algorithms
*
* Copyright 2024 Cirrus Logic, Inc.
*
* Author: James Ogletree <james.ogletree@cirrus.com>
*/
#ifndef __MFD_CS40L50_H__
#define __MFD_CS40L50_H__
#include <linux/firmware/cirrus/cs_dsp.h>
#include <linux/gpio/consumer.h>
#include <linux/pm.h>
#include <linux/regmap.h>
/* Power Supply Configuration */
#define CS40L50_BLOCK_ENABLES2 0x201C
#define CS40L50_ERR_RLS 0x2034
#define CS40L50_BST_LPMODE_SEL 0x3810
#define CS40L50_DCM_LOW_POWER 0x1
#define CS40L50_OVERTEMP_WARN 0x4000010
/* Interrupts */
#define CS40L50_IRQ1_INT_1 0xE010
#define CS40L50_IRQ1_BASE CS40L50_IRQ1_INT_1
#define CS40L50_IRQ1_INT_2 0xE014
#define CS40L50_IRQ1_INT_8 0xE02C
#define CS40L50_IRQ1_INT_9 0xE030
#define CS40L50_IRQ1_INT_10 0xE034
#define CS40L50_IRQ1_INT_18 0xE054
#define CS40L50_IRQ1_MASK_1 0xE090
#define CS40L50_IRQ1_MASK_2 0xE094
#define CS40L50_IRQ1_MASK_20 0xE0DC
#define CS40L50_IRQ1_INT_1_OFFSET (CS40L50_IRQ1_INT_1 - CS40L50_IRQ1_BASE)
#define CS40L50_IRQ1_INT_2_OFFSET (CS40L50_IRQ1_INT_2 - CS40L50_IRQ1_BASE)
#define CS40L50_IRQ1_INT_8_OFFSET (CS40L50_IRQ1_INT_8 - CS40L50_IRQ1_BASE)
#define CS40L50_IRQ1_INT_9_OFFSET (CS40L50_IRQ1_INT_9 - CS40L50_IRQ1_BASE)
#define CS40L50_IRQ1_INT_10_OFFSET (CS40L50_IRQ1_INT_10 - CS40L50_IRQ1_BASE)
#define CS40L50_IRQ1_INT_18_OFFSET (CS40L50_IRQ1_INT_18 - CS40L50_IRQ1_BASE)
#define CS40L50_IRQ_MASK_2_OVERRIDE 0xFFDF7FFF
#define CS40L50_IRQ_MASK_20_OVERRIDE 0x15C01000
#define CS40L50_AMP_SHORT_MASK BIT(31)
#define CS40L50_DSP_QUEUE_MASK BIT(21)
#define CS40L50_TEMP_ERR_MASK BIT(31)
#define CS40L50_BST_UVP_MASK BIT(6)
#define CS40L50_BST_SHORT_MASK BIT(7)
#define CS40L50_BST_ILIMIT_MASK BIT(18)
#define CS40L50_UVLO_VDDBATT_MASK BIT(16)
#define CS40L50_GLOBAL_ERROR_MASK BIT(15)
enum cs40l50_irq_list {
CS40L50_DSP_QUEUE_IRQ,
CS40L50_GLOBAL_ERROR_IRQ,
CS40L50_UVLO_VDDBATT_IRQ,
CS40L50_BST_ILIMIT_IRQ,
CS40L50_BST_SHORT_IRQ,
CS40L50_BST_UVP_IRQ,
CS40L50_TEMP_ERR_IRQ,
CS40L50_AMP_SHORT_IRQ,
};
/* DSP */
#define CS40L50_XMEM_PACKED_0 0x2000000
#define CS40L50_XMEM_UNPACKED24_0 0x2800000
#define CS40L50_SYS_INFO_ID 0x25E0000
#define CS40L50_DSP_QUEUE_WT 0x28042C8
#define CS40L50_DSP_QUEUE_RD 0x28042CC
#define CS40L50_NUM_WAVES 0x2805C18
#define CS40L50_CORE_BASE 0x2B80000
#define CS40L50_YMEM_PACKED_0 0x2C00000
#define CS40L50_YMEM_UNPACKED24_0 0x3400000
#define CS40L50_PMEM_0 0x3800000
#define CS40L50_DSP_POLL_US 1000
#define CS40L50_DSP_TIMEOUT_COUNT 100
#define CS40L50_RESET_PULSE_US 2200
#define CS40L50_CP_READY_US 3100
#define CS40L50_AUTOSUSPEND_MS 2000
#define CS40L50_PM_ALGO 0x9F206
#define CS40L50_GLOBAL_ERR_RLS_SET BIT(11)
#define CS40L50_GLOBAL_ERR_RLS_CLEAR 0
enum cs40l50_wseqs {
CS40L50_PWR_ON,
CS40L50_STANDBY,
CS40L50_ACTIVE,
CS40L50_NUM_WSEQS,
};
/* DSP Queue */
#define CS40L50_DSP_QUEUE_BASE 0x11004
#define CS40L50_DSP_QUEUE_END 0x1101C
#define CS40L50_DSP_QUEUE 0x11020
#define CS40L50_PREVENT_HIBER 0x2000003
#define CS40L50_ALLOW_HIBER 0x2000004
#define CS40L50_SHUTDOWN 0x2000005
#define CS40L50_SYSTEM_RESET 0x2000007
#define CS40L50_START_I2S 0x3000002
#define CS40L50_OWT_PUSH 0x3000008
#define CS40L50_STOP_PLAYBACK 0x5000000
#define CS40L50_OWT_DELETE 0xD000000
/* Firmware files */
#define CS40L50_FW "cs40l50.wmfw"
#define CS40L50_WT "cs40l50.bin"
/* Device */
#define CS40L50_DEVID 0x0
#define CS40L50_REVID 0x4
#define CS40L50_DEVID_A 0x40A50
#define CS40L50_REVID_B0 0xB0
struct cs40l50 {
struct device *dev;
struct regmap *regmap;
struct mutex lock;
struct cs_dsp dsp;
struct gpio_desc *reset_gpio;
struct regmap_irq_chip_data *irq_data;
const struct firmware *fw;
const struct firmware *bin;
struct cs_dsp_wseq wseqs[CS40L50_NUM_WSEQS];
int irq;
u32 devid;
u32 revid;
};
int cs40l50_dsp_write(struct device *dev, struct regmap *regmap, u32 val);
int cs40l50_probe(struct cs40l50 *cs40l50);
int cs40l50_remove(struct cs40l50 *cs40l50);
extern const struct regmap_config cs40l50_regmap;
extern const struct dev_pm_ops cs40l50_pm_ops;
#endif /* __MFD_CS40L50_H__ */
......@@ -75,6 +75,7 @@ config SND_SOC_ALL_CODECS
imply SND_SOC_CS35L56_I2C
imply SND_SOC_CS35L56_SPI
imply SND_SOC_CS35L56_SDW
imply SND_SOC_CS40L50
imply SND_SOC_CS42L42
imply SND_SOC_CS42L42_SDW
imply SND_SOC_CS42L43
......@@ -847,6 +848,16 @@ config SND_SOC_CS35L56_SDW
help
Enable support for Cirrus Logic CS35L56 boosted amplifier with SoundWire control
config SND_SOC_CS40L50
tristate "Cirrus Logic CS40L50 CODEC"
depends on MFD_CS40L50_CORE
help
This option enables support for I2S streaming to Cirrus Logic CS40L50.
CS40L50 is a haptic driver with waveform memory, an integrated
DSP, and closed-loop algorithms. If built as a module, it will be
called snd-soc-cs40l50.
config SND_SOC_CS42L42_CORE
tristate
......
......@@ -78,6 +78,7 @@ snd-soc-cs35l56-shared-y := cs35l56-shared.o
snd-soc-cs35l56-i2c-y := cs35l56-i2c.o
snd-soc-cs35l56-spi-y := cs35l56-spi.o
snd-soc-cs35l56-sdw-y := cs35l56-sdw.o
snd-soc-cs40l50-objs := cs40l50-codec.o
snd-soc-cs42l42-y := cs42l42.o
snd-soc-cs42l42-i2c-y := cs42l42-i2c.o
snd-soc-cs42l42-sdw-y := cs42l42-sdw.o
......@@ -475,6 +476,7 @@ obj-$(CONFIG_SND_SOC_CS35L56_SHARED) += snd-soc-cs35l56-shared.o
obj-$(CONFIG_SND_SOC_CS35L56_I2C) += snd-soc-cs35l56-i2c.o
obj-$(CONFIG_SND_SOC_CS35L56_SPI) += snd-soc-cs35l56-spi.o
obj-$(CONFIG_SND_SOC_CS35L56_SDW) += snd-soc-cs35l56-sdw.o
obj-$(CONFIG_SND_SOC_CS40L50) += snd-soc-cs40l50.o
obj-$(CONFIG_SND_SOC_CS42L42_CORE) += snd-soc-cs42l42.o
obj-$(CONFIG_SND_SOC_CS42L42) += snd-soc-cs42l42-i2c.o
obj-$(CONFIG_SND_SOC_CS42L42_SDW) += snd-soc-cs42l42-sdw.o
......
// SPDX-License-Identifier: GPL-2.0
//
// CS40L50 Advanced Haptic Driver with waveform memory,
// integrated DSP, and closed-loop algorithms
//
// Copyright 2024 Cirrus Logic, Inc.
//
// Author: James Ogletree <james.ogletree@cirrus.com>
#include <linux/bitfield.h>
#include <linux/mfd/cs40l50.h>
#include <sound/pcm_params.h>
#include <sound/soc.h>
#define CS40L50_REFCLK_INPUT 0x2C04
#define CS40L50_ASP_CONTROL2 0x4808
#define CS40L50_ASP_DATA_CONTROL5 0x4840
/* PLL Config */
#define CS40L50_PLL_REFCLK_BCLK 0x0
#define CS40L50_PLL_REFCLK_MCLK 0x5
#define CS40L50_PLL_REEFCLK_MCLK_CFG 0x00
#define CS40L50_PLL_REFCLK_LOOP_MASK BIT(11)
#define CS40L50_PLL_REFCLK_OPEN_LOOP 1
#define CS40L50_PLL_REFCLK_CLOSED_LOOP 0
#define CS40L50_PLL_REFCLK_LOOP_SHIFT 11
#define CS40L50_PLL_REFCLK_FREQ_MASK GENMASK(10, 5)
#define CS40L50_PLL_REFCLK_FREQ_SHIFT 5
#define CS40L50_PLL_REFCLK_SEL_MASK GENMASK(2, 0)
#define CS40L50_BCLK_RATIO_DEFAULT 32
/* ASP Config */
#define CS40L50_ASP_RX_WIDTH_SHIFT 24
#define CS40L50_ASP_RX_WIDTH_MASK GENMASK(31, 24)
#define CS40L50_ASP_RX_WL_MASK GENMASK(5, 0)
#define CS40L50_ASP_FSYNC_INV_MASK BIT(2)
#define CS40L50_ASP_BCLK_INV_MASK BIT(6)
#define CS40L50_ASP_FMT_MASK GENMASK(10, 8)
#define CS40L50_ASP_FMT_I2S 0x2
struct cs40l50_pll_config {
unsigned int freq;
unsigned int cfg;
};
struct cs40l50_codec {
struct device *dev;
struct regmap *regmap;
unsigned int daifmt;
unsigned int bclk_ratio;
unsigned int rate;
};
static const struct cs40l50_pll_config cs40l50_pll_cfg[] = {
{ 32768, 0x00 },
{ 1536000, 0x1B },
{ 3072000, 0x21 },
{ 6144000, 0x28 },
{ 9600000, 0x30 },
{ 12288000, 0x33 },
};
static int cs40l50_get_clk_config(const unsigned int freq, unsigned int *cfg)
{
int i;
for (i = 0; i < ARRAY_SIZE(cs40l50_pll_cfg); i++) {
if (cs40l50_pll_cfg[i].freq == freq) {
*cfg = cs40l50_pll_cfg[i].cfg;
return 0;
}
}
return -EINVAL;
}
static int cs40l50_swap_ext_clk(struct cs40l50_codec *codec, const unsigned int clk_src)
{
unsigned int cfg;
int ret;
switch (clk_src) {
case CS40L50_PLL_REFCLK_BCLK:
ret = cs40l50_get_clk_config(codec->bclk_ratio * codec->rate, &cfg);
if (ret)
return ret;
break;
case CS40L50_PLL_REFCLK_MCLK:
cfg = CS40L50_PLL_REEFCLK_MCLK_CFG;
break;
default:
return -EINVAL;
}
ret = regmap_update_bits(codec->regmap, CS40L50_REFCLK_INPUT,
CS40L50_PLL_REFCLK_LOOP_MASK,
CS40L50_PLL_REFCLK_OPEN_LOOP <<
CS40L50_PLL_REFCLK_LOOP_SHIFT);
if (ret)
return ret;
ret = regmap_update_bits(codec->regmap, CS40L50_REFCLK_INPUT,
CS40L50_PLL_REFCLK_FREQ_MASK |
CS40L50_PLL_REFCLK_SEL_MASK,
(cfg << CS40L50_PLL_REFCLK_FREQ_SHIFT) | clk_src);
if (ret)
return ret;
return regmap_update_bits(codec->regmap, CS40L50_REFCLK_INPUT,
CS40L50_PLL_REFCLK_LOOP_MASK,
CS40L50_PLL_REFCLK_CLOSED_LOOP <<
CS40L50_PLL_REFCLK_LOOP_SHIFT);
}
static int cs40l50_clk_en(struct snd_soc_dapm_widget *w,
struct snd_kcontrol *kcontrol,
int event)
{
struct snd_soc_component *comp = snd_soc_dapm_to_component(w->dapm);
struct cs40l50_codec *codec = snd_soc_component_get_drvdata(comp);
int ret;
switch (event) {
case SND_SOC_DAPM_POST_PMU:
ret = cs40l50_dsp_write(codec->dev, codec->regmap, CS40L50_STOP_PLAYBACK);
if (ret)
return ret;
ret = cs40l50_dsp_write(codec->dev, codec->regmap, CS40L50_START_I2S);
if (ret)
return ret;
ret = cs40l50_swap_ext_clk(codec, CS40L50_PLL_REFCLK_BCLK);
if (ret)
return ret;
break;
case SND_SOC_DAPM_PRE_PMD:
ret = cs40l50_swap_ext_clk(codec, CS40L50_PLL_REFCLK_MCLK);
if (ret)
return ret;
break;
default:
return -EINVAL;
}
return 0;
}
static const struct snd_soc_dapm_widget cs40l50_dapm_widgets[] = {
SND_SOC_DAPM_SUPPLY_S("ASP PLL", 0, SND_SOC_NOPM, 0, 0, cs40l50_clk_en,
SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
SND_SOC_DAPM_AIF_IN("ASPRX1", NULL, 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_AIF_IN("ASPRX2", NULL, 0, SND_SOC_NOPM, 0, 0),
SND_SOC_DAPM_OUTPUT("OUT"),
};
static const struct snd_soc_dapm_route cs40l50_dapm_routes[] = {
{ "ASP Playback", NULL, "ASP PLL" },
{ "ASPRX1", NULL, "ASP Playback" },
{ "ASPRX2", NULL, "ASP Playback" },
{ "OUT", NULL, "ASPRX1" },
{ "OUT", NULL, "ASPRX2" },
};
static int cs40l50_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
{
struct cs40l50_codec *codec = snd_soc_component_get_drvdata(codec_dai->component);
if ((fmt & SND_SOC_DAIFMT_MASTER_MASK) != SND_SOC_DAIFMT_CBC_CFC)
return -EINVAL;
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
case SND_SOC_DAIFMT_NB_NF:
codec->daifmt = 0;
break;
case SND_SOC_DAIFMT_NB_IF:
codec->daifmt = CS40L50_ASP_FSYNC_INV_MASK;
break;
case SND_SOC_DAIFMT_IB_NF:
codec->daifmt = CS40L50_ASP_BCLK_INV_MASK;
break;
case SND_SOC_DAIFMT_IB_IF:
codec->daifmt = CS40L50_ASP_FSYNC_INV_MASK | CS40L50_ASP_BCLK_INV_MASK;
break;
default:
dev_err(codec->dev, "Invalid clock invert\n");
return -EINVAL;
}
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
case SND_SOC_DAIFMT_I2S:
codec->daifmt |= FIELD_PREP(CS40L50_ASP_FMT_MASK, CS40L50_ASP_FMT_I2S);
break;
default:
dev_err(codec->dev, "Unsupported DAI format\n");
return -EINVAL;
}
return 0;
}
static int cs40l50_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
struct cs40l50_codec *codec = snd_soc_component_get_drvdata(dai->component);
unsigned int asp_rx_wl = params_width(params);
int ret;
codec->rate = params_rate(params);
ret = regmap_update_bits(codec->regmap, CS40L50_ASP_DATA_CONTROL5,
CS40L50_ASP_RX_WL_MASK, asp_rx_wl);
if (ret)
return ret;
codec->daifmt |= (asp_rx_wl << CS40L50_ASP_RX_WIDTH_SHIFT);
return regmap_update_bits(codec->regmap, CS40L50_ASP_CONTROL2,
CS40L50_ASP_FSYNC_INV_MASK |
CS40L50_ASP_BCLK_INV_MASK |
CS40L50_ASP_FMT_MASK |
CS40L50_ASP_RX_WIDTH_MASK, codec->daifmt);
}
static int cs40l50_set_dai_bclk_ratio(struct snd_soc_dai *dai, unsigned int ratio)
{
struct cs40l50_codec *codec = snd_soc_component_get_drvdata(dai->component);
codec->bclk_ratio = ratio;
return 0;
}
static const struct snd_soc_dai_ops cs40l50_dai_ops = {
.set_fmt = cs40l50_set_dai_fmt,
.set_bclk_ratio = cs40l50_set_dai_bclk_ratio,
.hw_params = cs40l50_hw_params,
};
static struct snd_soc_dai_driver cs40l50_dai[] = {
{
.name = "cs40l50-pcm",
.id = 0,
.playback = {
.stream_name = "ASP Playback",
.channels_min = 1,
.channels_max = 2,
.rates = SNDRV_PCM_RATE_48000,
.formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE,
},
.ops = &cs40l50_dai_ops,
},
};
static int cs40l50_codec_probe(struct snd_soc_component *component)
{
struct cs40l50_codec *codec = snd_soc_component_get_drvdata(component);
codec->bclk_ratio = CS40L50_BCLK_RATIO_DEFAULT;
return 0;
}
static const struct snd_soc_component_driver soc_codec_dev_cs40l50 = {
.probe = cs40l50_codec_probe,
.dapm_widgets = cs40l50_dapm_widgets,
.num_dapm_widgets = ARRAY_SIZE(cs40l50_dapm_widgets),
.dapm_routes = cs40l50_dapm_routes,
.num_dapm_routes = ARRAY_SIZE(cs40l50_dapm_routes),
};
static int cs40l50_codec_driver_probe(struct platform_device *pdev)
{
struct cs40l50 *cs40l50 = dev_get_drvdata(pdev->dev.parent);
struct cs40l50_codec *codec;
codec = devm_kzalloc(&pdev->dev, sizeof(*codec), GFP_KERNEL);
if (!codec)
return -ENOMEM;
codec->regmap = cs40l50->regmap;
codec->dev = &pdev->dev;
return devm_snd_soc_register_component(&pdev->dev, &soc_codec_dev_cs40l50,
cs40l50_dai, ARRAY_SIZE(cs40l50_dai));
}
static const struct platform_device_id cs40l50_id[] = {
{ "cs40l50-codec", },
{}
};
MODULE_DEVICE_TABLE(platform, cs40l50_id);
static struct platform_driver cs40l50_codec_driver = {
.probe = cs40l50_codec_driver_probe,
.id_table = cs40l50_id,
.driver = {
.name = "cs40l50-codec",
},
};
module_platform_driver(cs40l50_codec_driver);
MODULE_DESCRIPTION("ASoC CS40L50 driver");
MODULE_AUTHOR("James Ogletree <james.ogletree@cirrus.com>");
MODULE_LICENSE("GPL");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment