xref: /OK3568_Linux_fs/kernel/drivers/misc/eeprom/digsy_mtc_eeprom.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-only
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * EEPROMs access control driver for display configuration EEPROMs
4*4882a593Smuzhiyun  * on DigsyMTC board.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * (C) 2011 DENX Software Engineering, Anatolij Gustschin <agust@denx.de>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * FIXME: this driver is used on a device-tree probed platform: it
9*4882a593Smuzhiyun  * should be defined as a bit-banged SPI device and probed from the device
10*4882a593Smuzhiyun  * tree and not like this with static grabbing of a few numbered GPIO
11*4882a593Smuzhiyun  * lines at random.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * Add proper SPI and EEPROM in arch/powerpc/boot/dts/digsy_mtc.dts
14*4882a593Smuzhiyun  * and delete this driver.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #include <linux/gpio.h>
18*4882a593Smuzhiyun #include <linux/gpio/machine.h>
19*4882a593Smuzhiyun #include <linux/init.h>
20*4882a593Smuzhiyun #include <linux/platform_device.h>
21*4882a593Smuzhiyun #include <linux/spi/spi.h>
22*4882a593Smuzhiyun #include <linux/spi/spi_gpio.h>
23*4882a593Smuzhiyun #include <linux/eeprom_93xx46.h>
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #define GPIO_EEPROM_CLK		216
26*4882a593Smuzhiyun #define GPIO_EEPROM_CS		210
27*4882a593Smuzhiyun #define GPIO_EEPROM_DI		217
28*4882a593Smuzhiyun #define GPIO_EEPROM_DO		249
29*4882a593Smuzhiyun #define GPIO_EEPROM_OE		255
30*4882a593Smuzhiyun #define EE_SPI_BUS_NUM	1
31*4882a593Smuzhiyun 
digsy_mtc_op_prepare(void * p)32*4882a593Smuzhiyun static void digsy_mtc_op_prepare(void *p)
33*4882a593Smuzhiyun {
34*4882a593Smuzhiyun 	/* enable */
35*4882a593Smuzhiyun 	gpio_set_value(GPIO_EEPROM_OE, 0);
36*4882a593Smuzhiyun }
37*4882a593Smuzhiyun 
digsy_mtc_op_finish(void * p)38*4882a593Smuzhiyun static void digsy_mtc_op_finish(void *p)
39*4882a593Smuzhiyun {
40*4882a593Smuzhiyun 	/* disable */
41*4882a593Smuzhiyun 	gpio_set_value(GPIO_EEPROM_OE, 1);
42*4882a593Smuzhiyun }
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun struct eeprom_93xx46_platform_data digsy_mtc_eeprom_data = {
45*4882a593Smuzhiyun 	.flags		= EE_ADDR8,
46*4882a593Smuzhiyun 	.prepare	= digsy_mtc_op_prepare,
47*4882a593Smuzhiyun 	.finish		= digsy_mtc_op_finish,
48*4882a593Smuzhiyun };
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun static struct spi_gpio_platform_data eeprom_spi_gpio_data = {
51*4882a593Smuzhiyun 	.num_chipselect	= 1,
52*4882a593Smuzhiyun };
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun static struct platform_device digsy_mtc_eeprom = {
55*4882a593Smuzhiyun 	.name	= "spi_gpio",
56*4882a593Smuzhiyun 	.id	= EE_SPI_BUS_NUM,
57*4882a593Smuzhiyun 	.dev	= {
58*4882a593Smuzhiyun 		.platform_data	= &eeprom_spi_gpio_data,
59*4882a593Smuzhiyun 	},
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun static struct gpiod_lookup_table eeprom_spi_gpiod_table = {
63*4882a593Smuzhiyun 	.dev_id         = "spi_gpio",
64*4882a593Smuzhiyun 	.table          = {
65*4882a593Smuzhiyun 		GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CLK,
66*4882a593Smuzhiyun 			    "sck", GPIO_ACTIVE_HIGH),
67*4882a593Smuzhiyun 		GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DI,
68*4882a593Smuzhiyun 			    "mosi", GPIO_ACTIVE_HIGH),
69*4882a593Smuzhiyun 		GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_DO,
70*4882a593Smuzhiyun 			    "miso", GPIO_ACTIVE_HIGH),
71*4882a593Smuzhiyun 		GPIO_LOOKUP("gpio@b00", GPIO_EEPROM_CS,
72*4882a593Smuzhiyun 			    "cs", GPIO_ACTIVE_HIGH),
73*4882a593Smuzhiyun 		{ },
74*4882a593Smuzhiyun 	},
75*4882a593Smuzhiyun };
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun static struct spi_board_info digsy_mtc_eeprom_info[] __initdata = {
78*4882a593Smuzhiyun 	{
79*4882a593Smuzhiyun 		.modalias		= "93xx46",
80*4882a593Smuzhiyun 		.max_speed_hz		= 1000000,
81*4882a593Smuzhiyun 		.bus_num		= EE_SPI_BUS_NUM,
82*4882a593Smuzhiyun 		.chip_select		= 0,
83*4882a593Smuzhiyun 		.mode			= SPI_MODE_0,
84*4882a593Smuzhiyun 		.platform_data		= &digsy_mtc_eeprom_data,
85*4882a593Smuzhiyun 	},
86*4882a593Smuzhiyun };
87*4882a593Smuzhiyun 
digsy_mtc_eeprom_devices_init(void)88*4882a593Smuzhiyun static int __init digsy_mtc_eeprom_devices_init(void)
89*4882a593Smuzhiyun {
90*4882a593Smuzhiyun 	int ret;
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 	ret = gpio_request_one(GPIO_EEPROM_OE, GPIOF_OUT_INIT_HIGH,
93*4882a593Smuzhiyun 				"93xx46 EEPROMs OE");
94*4882a593Smuzhiyun 	if (ret) {
95*4882a593Smuzhiyun 		pr_err("can't request gpio %d\n", GPIO_EEPROM_OE);
96*4882a593Smuzhiyun 		return ret;
97*4882a593Smuzhiyun 	}
98*4882a593Smuzhiyun 	gpiod_add_lookup_table(&eeprom_spi_gpiod_table);
99*4882a593Smuzhiyun 	spi_register_board_info(digsy_mtc_eeprom_info,
100*4882a593Smuzhiyun 				ARRAY_SIZE(digsy_mtc_eeprom_info));
101*4882a593Smuzhiyun 	return platform_device_register(&digsy_mtc_eeprom);
102*4882a593Smuzhiyun }
103*4882a593Smuzhiyun device_initcall(digsy_mtc_eeprom_devices_init);
104