Orange Pi5 kernel

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

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Driver for the Analog Devices digital potentiometers (SPI bus)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010-2011 Michael Hennerich, Analog Devices Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/spi/spi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include "ad525x_dpot.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) /* SPI bus functions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) static int write8(void *client, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 	u8 data = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 	return spi_write(client, &data, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) static int write16(void *client, u8 reg, u8 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	u8 data[2] = {reg, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	return spi_write(client, data, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) static int write24(void *client, u8 reg, u16 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 	u8 data[3] = {reg, val >> 8, val};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	return spi_write(client, data, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) static int read8(void *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	u8 data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	ret = spi_read(client, &data, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	return data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static int read16(void *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	u8 buf_rx[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	write16(client, reg, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	ret = spi_read(client, buf_rx, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	return (buf_rx[0] << 8) |  buf_rx[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int read24(void *client, u8 reg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	u8 buf_rx[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	write24(client, reg, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	ret = spi_read(client, buf_rx, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	return (buf_rx[1] << 8) |  buf_rx[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static const struct ad_dpot_bus_ops bops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.read_d8	= read8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.read_r8d8	= read16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.read_r8d16	= read24,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	.write_d8	= write8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	.write_r8d8	= write16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	.write_r8d16	= write24,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) static int ad_dpot_spi_probe(struct spi_device *spi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct ad_dpot_bus_data bdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		.client = spi,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		.bops = &bops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	return ad_dpot_probe(&spi->dev, &bdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			     spi_get_device_id(spi)->driver_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			     spi_get_device_id(spi)->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) static int ad_dpot_spi_remove(struct spi_device *spi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	return ad_dpot_remove(&spi->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static const struct spi_device_id ad_dpot_spi_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	{"ad5160", AD5160_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	{"ad5161", AD5161_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	{"ad5162", AD5162_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	{"ad5165", AD5165_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	{"ad5200", AD5200_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	{"ad5201", AD5201_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	{"ad5203", AD5203_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	{"ad5204", AD5204_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	{"ad5206", AD5206_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	{"ad5207", AD5207_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	{"ad5231", AD5231_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	{"ad5232", AD5232_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	{"ad5233", AD5233_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	{"ad5235", AD5235_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	{"ad5260", AD5260_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	{"ad5262", AD5262_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	{"ad5263", AD5263_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	{"ad5290", AD5290_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	{"ad5291", AD5291_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	{"ad5292", AD5292_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	{"ad5293", AD5293_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	{"ad7376", AD7376_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	{"ad8400", AD8400_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	{"ad8402", AD8402_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	{"ad8403", AD8403_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	{"adn2850", ADN2850_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	{"ad5270", AD5270_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	{"ad5271", AD5271_ID},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	{}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) MODULE_DEVICE_TABLE(spi, ad_dpot_spi_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static struct spi_driver ad_dpot_spi_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		.name	= "ad_dpot",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	.probe		= ad_dpot_spi_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	.remove		= ad_dpot_spi_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	.id_table	= ad_dpot_spi_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) module_spi_driver(ad_dpot_spi_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) MODULE_AUTHOR("Michael Hennerich <michael.hennerich@analog.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) MODULE_DESCRIPTION("digital potentiometer SPI bus driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) MODULE_ALIAS("spi:ad_dpot");